return [...bytes].map(b => b.toString(16).padStart(2, '0')).join('')
}
+ const outPub = new Uint8Array(32)
+ const outSig = new Uint8Array(64)
+
/**
* @param {Uint8Array} prv
* @param {string} api
const derive = (prv, api) => {
switch (api) {
case 'nano25519': {
- return nano25519.derive(prv)
+ nano25519.derive(prv, outPub)
+ return outPub
}
case 'NanocurrencyWeb': {
const { publicKey } = NanocurrencyWeb.wallet.legacyAccounts(b2a(prv))[0]
const sign = (msg, prv, pub, api) => {
const sk = new Uint8Array([...prv, ...pub])
switch (api) {
- case 'nano25519':
- case 'nano25519 with bulk block verification': {
- return nano25519.sign(msg, prv, pub)
+ case 'nano25519': {
+ nano25519.sign(msg, prv, pub, outSig)
+ return outSig
}
case 'NanocurrencyWeb': {
const { privateKey } = NanocurrencyWeb.wallet.legacyAccounts(b2a(prv))[0]
failures += +!test
result = nano25519.derive(NANO_ORG_VECTOR.privateKeyBytes)
- test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase()
+ test = result.toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase()
check(`derive from bytes ${NANO_ORG_VECTOR.privateKey}`, test)
passes += +test
failures += +!test
result = nano25519.sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.privateKeyBytes, NANO_ORG_VECTOR.publicKeyBytes)
- test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase()
+ test = result.toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase()
check(`sign message bytes ${NANO_ORG_VECTOR.blockHash}`, test)
passes += +test
failures += +!test
const signatureBytes = new Uint8Array(signature.match(/.{2}/g)?.slice(0, 64).map(b => parseInt(b, 16)) ?? [])
result = nano25519.derive(privateKeyBytes)
- test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === publicKey
+ test = result.toLowerCase() === publicKey
check(`derive from ${privateKey}`, test)
passes += +test
failures += +!test
result = nano25519.sign(messageBytes, privateKeyBytes, publicKeyBytes)
- test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === signature.slice(0, 128)
+ test = result.toLowerCase() === signature.slice(0, 128)
check(`sign message ${message}`, test)
passes += +test
failures += +!test