cardano-crypto.js
Advanced tools
Comparing version 3.1.10 to 4.0.1
327
index.js
@@ -1,12 +0,14 @@ | ||
var bip39 = require('bip39-light') | ||
const bip39 = require('bip39-light') | ||
var Module = require('./lib.js') | ||
var crc32 = require('./utils/crc32') | ||
var base58 = require('./utils/base58') | ||
var scrypt = require('./utils/scrypt-async') | ||
const Module = require('./lib.js') | ||
const crc32 = require('./utils/crc32') | ||
const base58 = require('./utils/base58') | ||
const scrypt = require('./utils/scrypt-async') | ||
const pbkdf2Sync = require('pbkdf2').pbkdf2Sync | ||
const HARDENED_THRESHOLD = 0x80000000 | ||
function validateDerivationMode(input) { | ||
function validateDerivationScheme(input) { | ||
if (input !== 1 && input !== 2) { | ||
throw new Error('invalid derivation mode!') | ||
throw new Error('invalid derivation scheme!') | ||
} | ||
@@ -16,3 +18,3 @@ } | ||
function validateBuffer(input, expectedLength) { | ||
if(!Buffer.isBuffer(input)){ | ||
if (!Buffer.isBuffer(input)) { | ||
throw new Error('not buffer!') | ||
@@ -27,3 +29,3 @@ } | ||
function validateArray(input) { | ||
if (typeof(input) !== typeof([])) { | ||
if (typeof input !== typeof []) { | ||
throw new Error('not an array!') | ||
@@ -39,11 +41,13 @@ } | ||
function validateBool(input) { | ||
if (typeof(input) !== typeof(true)) { | ||
throw new Error('not a boolean!') | ||
function validateString(input) { | ||
if (typeof input !== typeof 'aa') { | ||
throw new Error('not a string!') | ||
} | ||
} | ||
function validateString(input) { | ||
if (typeof(input) !== typeof('aa')) { | ||
throw new Error('not a string!') | ||
function validateMnemonic(input) { | ||
if (!bip39.validateMnemonic(input)) { | ||
const e = new Error('Invalid or unsupported mnemonic format:') | ||
e.name = 'InvalidArgumentException' | ||
throw e | ||
} | ||
@@ -55,4 +59,4 @@ } | ||
var len = input.length | ||
var cborPrefix = [] | ||
const len = input.length | ||
let cborPrefix = [] | ||
@@ -74,9 +78,9 @@ if (len < 24) { | ||
var msgLen = msg.length | ||
var msgArrPtr = Module._malloc(msgLen) | ||
var msgArr = new Uint8Array(Module.HEAPU8.buffer, msgArrPtr, msgLen) | ||
var walletSecretArrPtr = Module._malloc(128) | ||
var walletSecretArr = new Uint8Array(Module.HEAPU8.buffer, walletSecretArrPtr, 128) | ||
var sigPtr = Module._malloc(64) | ||
var sigArr = new Uint8Array(Module.HEAPU8.buffer, sigPtr, 64) | ||
const msgLen = msg.length | ||
const msgArrPtr = Module._malloc(msgLen) | ||
const msgArr = new Uint8Array(Module.HEAPU8.buffer, msgArrPtr, msgLen) | ||
const walletSecretArrPtr = Module._malloc(128) | ||
const walletSecretArr = new Uint8Array(Module.HEAPU8.buffer, walletSecretArrPtr, 128) | ||
const sigPtr = Module._malloc(64) | ||
const sigArr = new Uint8Array(Module.HEAPU8.buffer, sigPtr, 64) | ||
@@ -99,9 +103,9 @@ msgArr.set(msg) | ||
var msgLen = msg.length | ||
var msgArrPtr = Module._malloc(msgLen) | ||
var msgArr = new Uint8Array(Module.HEAPU8.buffer, msgArrPtr, msgLen) | ||
var publicKeyArrPtr = Module._malloc(32) | ||
var publicKeyArr = new Uint8Array(Module.HEAPU8.buffer, publicKeyArrPtr, 32) | ||
var sigPtr = Module._malloc(64) | ||
var sigArr = new Uint8Array(Module.HEAPU8.buffer, sigPtr, 64) | ||
const msgLen = msg.length | ||
const msgArrPtr = Module._malloc(msgLen) | ||
const msgArr = new Uint8Array(Module.HEAPU8.buffer, msgArrPtr, msgLen) | ||
const publicKeyArrPtr = Module._malloc(32) | ||
const publicKeyArr = new Uint8Array(Module.HEAPU8.buffer, publicKeyArrPtr, 32) | ||
const sigPtr = Module._malloc(64) | ||
const sigArr = new Uint8Array(Module.HEAPU8.buffer, sigPtr, 64) | ||
@@ -112,3 +116,3 @@ msgArr.set(msg) | ||
var result = Module._emscripten_verify(msgArrPtr, msgLen, publicKeyArrPtr, sigPtr) === 0 | ||
const result = Module._emscripten_verify(msgArrPtr, msgLen, publicKeyArrPtr, sigPtr) === 0 | ||
@@ -126,8 +130,8 @@ Module._free(msgArrPtr) | ||
var seedArrPtr = Module._malloc(32) | ||
var seedArr = new Uint8Array(Module.HEAPU8.buffer, seedArrPtr, 32) | ||
var chainCodeArrPtr = Module._malloc(32) | ||
var chainCodeArr = new Uint8Array(Module.HEAPU8.buffer, chainCodeArrPtr, 32) | ||
var walletSecretArrPtr = Module._malloc(128) | ||
var walletSecretArr = new Uint8Array(Module.HEAPU8.buffer, walletSecretArrPtr, 128) | ||
const seedArrPtr = Module._malloc(32) | ||
const seedArr = new Uint8Array(Module.HEAPU8.buffer, seedArrPtr, 32) | ||
const chainCodeArrPtr = Module._malloc(32) | ||
const chainCodeArr = new Uint8Array(Module.HEAPU8.buffer, chainCodeArrPtr, 32) | ||
const walletSecretArrPtr = Module._malloc(128) | ||
const walletSecretArr = new Uint8Array(Module.HEAPU8.buffer, walletSecretArrPtr, 128) | ||
@@ -153,23 +157,26 @@ seedArr.set(seed) | ||
function mnemonicToHashSeed(mnemonic) { | ||
if (!bip39.validateMnemonic(mnemonic)) { | ||
const e = new Error('Invalid or unsupported mnemonic format') | ||
e.name = 'InvalidArgumentException' | ||
throw e | ||
function walletSecretFromMnemonic(mnemonic, derivationScheme) { | ||
validateDerivationScheme(derivationScheme) | ||
if (derivationScheme === 1) { | ||
return walletSecretFromMnemonicV1(mnemonic) | ||
} else if (derivationScheme === 2) { | ||
return walletSecretFromMnemonicV2(mnemonic, '') | ||
} else { | ||
throw Error(`Derivation scheme ${derivationScheme} not implemented`) | ||
} | ||
} | ||
const ent = Buffer.from(bip39.mnemonicToEntropy(mnemonic), 'hex') | ||
function walletSecretFromMnemonicV1(mnemonic) { | ||
validateMnemonic(mnemonic) | ||
return cborEncodeBuffer(blake2b(cborEncodeBuffer(ent), 32)) | ||
} | ||
const entropy = Buffer.from(bip39.mnemonicToEntropy(mnemonic), 'hex') | ||
const hashSeed = cborEncodeBuffer(blake2b(cborEncodeBuffer(entropy), 32)) | ||
function walletSecretFromMnemonic(mnemonic) { | ||
var hashSeed = mnemonicToHashSeed(mnemonic) | ||
var result | ||
for (var i = 1; result === undefined && i <= 1000; i++) { | ||
let result | ||
for (let i = 1; result === undefined && i <= 1000; i++) { | ||
try { | ||
var digest = hmac_sha512(hashSeed, [Buffer.from(`Root Seed Chain ${i}`, 'ascii')]) | ||
var seed = digest.slice(0, 32) | ||
var chainCode = digest.slice(32, 64) | ||
const digest = hmac_sha512(hashSeed, [Buffer.from(`Root Seed Chain ${i}`, 'ascii')]) | ||
const seed = digest.slice(0, 32) | ||
const chainCode = digest.slice(32, 64) | ||
@@ -188,3 +195,3 @@ result = walletSecretFromSeed(seed, chainCode) | ||
if (result === undefined) { | ||
var e = new Error('Secret key generation from mnemonic is looping forever') | ||
const e = new Error('Secret key generation from mnemonic is looping forever') | ||
e.name = 'RuntimeException' | ||
@@ -197,17 +204,57 @@ throw e | ||
function walletSecretFromMnemonicV2(mnemonic, password) { | ||
validateMnemonic(mnemonic) | ||
const entropy = Buffer.from(bip39.mnemonicToEntropy(mnemonic), 'hex') | ||
const xprv = pbkdf2Sync(password, entropy, 4096, 96, 'sha512') | ||
xprv[0] &= 248 | ||
xprv[31] &= 31 | ||
xprv[31] |= 64 | ||
function derivePrivate(parentKey, index, derivationMode) { | ||
const publicKey = toPublic(xprv.slice(0, 64)) | ||
const rootSecret = Buffer.concat([xprv.slice(0, 64), publicKey, xprv.slice(64,)]) | ||
return derivePrivate( | ||
derivePrivate( | ||
rootSecret, | ||
HARDENED_THRESHOLD + 44, | ||
2 | ||
), | ||
HARDENED_THRESHOLD + 1815, | ||
2 | ||
) | ||
} | ||
function toPublic(privateKey) { | ||
validateBuffer(privateKey, 64) | ||
const privateKeyArrPtr = Module._malloc(64) | ||
const privateKeyArr = new Uint8Array(Module.HEAPU8.buffer, privateKeyArrPtr, 64) | ||
const publicKeyArrPtr = Module._malloc(32) | ||
const publicKeyArr = new Uint8Array(Module.HEAPU8.buffer, publicKeyArrPtr, 32) | ||
privateKeyArr.set(privateKey) | ||
Module._emscripten_to_public(privateKeyArrPtr, publicKeyArrPtr) | ||
Module._free(privateKeyArrPtr) | ||
Module._free(publicKeyArrPtr) | ||
return new Buffer(publicKeyArr) | ||
} | ||
function derivePrivate(parentKey, index, derivationScheme) { | ||
validateBuffer(parentKey, 128) | ||
validateDerivationIndex(index) | ||
validateDerivationMode(derivationMode) | ||
validateDerivationScheme(derivationScheme) | ||
var parentKeyArrPtr = Module._malloc(128) | ||
var parentKeyArr = new Uint8Array(Module.HEAPU8.buffer, parentKeyArrPtr, 128) | ||
var childKeyArrPtr = Module._malloc(128) | ||
var childKeyArr = new Uint8Array(Module.HEAPU8.buffer, childKeyArrPtr, 128) | ||
const parentKeyArrPtr = Module._malloc(128) | ||
const parentKeyArr = new Uint8Array(Module.HEAPU8.buffer, parentKeyArrPtr, 128) | ||
const childKeyArrPtr = Module._malloc(128) | ||
const childKeyArr = new Uint8Array(Module.HEAPU8.buffer, childKeyArrPtr, 128) | ||
parentKeyArr.set(parentKey) | ||
Module._emscripten_derive_private(parentKeyArrPtr, index, childKeyArrPtr, derivationMode) | ||
Module._emscripten_derive_private(parentKeyArrPtr, index, childKeyArrPtr, derivationScheme) | ||
Module._free(parentKeyArrPtr) | ||
@@ -219,19 +266,19 @@ Module._free(childKeyArrPtr) | ||
function derivePublic(parentExtPubKey, index, derivationMode) { | ||
function derivePublic(parentExtPubKey, index, derivationScheme) { | ||
validateBuffer(parentExtPubKey, 64) | ||
validateDerivationIndex(index) | ||
validateDerivationMode(derivationMode) | ||
validateDerivationScheme(derivationScheme) | ||
var parentPubKey = parentExtPubKey.slice(0, 32) | ||
var parentChainCode = parentExtPubKey.slice(32, 64) | ||
const parentPubKey = parentExtPubKey.slice(0, 32) | ||
const parentChainCode = parentExtPubKey.slice(32, 64) | ||
var parentPubKeyArrPtr = Module._malloc(32) | ||
var parentPubKeyArr = new Uint8Array(Module.HEAPU8.buffer, parentPubKeyArrPtr, 32) | ||
var parentChainCodeArrPtr = Module._malloc(32) | ||
var parentChainCodeArr = new Uint8Array(Module.HEAPU8.buffer, parentChainCodeArrPtr, 32) | ||
const parentPubKeyArrPtr = Module._malloc(32) | ||
const parentPubKeyArr = new Uint8Array(Module.HEAPU8.buffer, parentPubKeyArrPtr, 32) | ||
const parentChainCodeArrPtr = Module._malloc(32) | ||
const parentChainCodeArr = new Uint8Array(Module.HEAPU8.buffer, parentChainCodeArrPtr, 32) | ||
var childPubKeyArrPtr = Module._malloc(32) | ||
var childPubKeyArr = new Uint8Array(Module.HEAPU8.buffer, childPubKeyArrPtr, 32) | ||
var childChainCodeArrPtr = Module._malloc(32) | ||
var childChainCodeArr = new Uint8Array(Module.HEAPU8.buffer, childChainCodeArrPtr, 32) | ||
const childPubKeyArrPtr = Module._malloc(32) | ||
const childPubKeyArr = new Uint8Array(Module.HEAPU8.buffer, childPubKeyArrPtr, 32) | ||
const childChainCodeArrPtr = Module._malloc(32) | ||
const childChainCodeArr = new Uint8Array(Module.HEAPU8.buffer, childChainCodeArrPtr, 32) | ||
@@ -241,3 +288,3 @@ parentPubKeyArr.set(parentPubKey) | ||
var resultCode = Module._emscripten_derive_public(parentPubKeyArrPtr, parentChainCodeArrPtr, index, childPubKeyArrPtr, childChainCodeArrPtr, derivationMode) | ||
const resultCode = Module._emscripten_derive_public(parentPubKeyArrPtr, parentChainCodeArrPtr, index, childPubKeyArrPtr, childChainCodeArrPtr, derivationScheme) | ||
@@ -259,7 +306,7 @@ Module._free(parentPubKeyArrPtr) | ||
var inputLen = input.length | ||
var inputArrPtr = Module._malloc(inputLen) | ||
var inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
var outputArrPtr = Module._malloc(outputLen) | ||
var outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, outputLen) | ||
const inputLen = input.length | ||
const inputArrPtr = Module._malloc(inputLen) | ||
const inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
const outputArrPtr = Module._malloc(outputLen) | ||
const outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, outputLen) | ||
@@ -278,9 +325,9 @@ inputArr.set(input) | ||
validateBuffer(input) | ||
var inputLen = input.length | ||
var inputArrPtr = Module._malloc(inputLen) | ||
var inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
const inputLen = input.length | ||
const inputArrPtr = Module._malloc(inputLen) | ||
const inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
var outputLen = 32 | ||
var outputArrPtr = Module._malloc(outputLen) | ||
var outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, outputLen) | ||
const outputLen = 32 | ||
const outputArrPtr = Module._malloc(outputLen) | ||
const outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, outputLen) | ||
@@ -302,13 +349,13 @@ inputArr.set(input) | ||
var ctxLen = Module._emscripten_size_of_hmac_sha512_ctx() | ||
var ctxArrPtr = Module._malloc(ctxLen) | ||
var ctxArr = new Uint8Array(Module.HEAPU8.buffer, ctxArrPtr, ctxLen) | ||
const ctxLen = Module._emscripten_size_of_hmac_sha512_ctx() | ||
const ctxArrPtr = Module._malloc(ctxLen) | ||
const ctxArr = new Uint8Array(Module.HEAPU8.buffer, ctxArrPtr, ctxLen) | ||
var initKeyLen = initKey.length | ||
var initKeyArrPtr = Module._malloc(initKeyLen) | ||
var initKeyArr = new Uint8Array(Module.HEAPU8.buffer, initKeyArrPtr, initKeyLen) | ||
const initKeyLen = initKey.length | ||
const initKeyArrPtr = Module._malloc(initKeyLen) | ||
const initKeyArr = new Uint8Array(Module.HEAPU8.buffer, initKeyArrPtr, initKeyLen) | ||
var outputLen = 64 | ||
var outputArrPtr = Module._malloc(outputLen) | ||
var outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, outputLen) | ||
const outputLen = 64 | ||
const outputArrPtr = Module._malloc(outputLen) | ||
const outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, outputLen) | ||
@@ -319,6 +366,6 @@ initKeyArr.set(initKey) | ||
for (var i = 0; i < inputs.length; i++) { | ||
var inputLen = inputs[i].length | ||
var inputArrPtr = Module._malloc(inputLen) | ||
var inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
for (let i = 0; i < inputs.length; i++) { | ||
const inputLen = inputs[i].length | ||
const inputArrPtr = Module._malloc(inputLen) | ||
const inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
@@ -349,13 +396,13 @@ inputArr.set(inputs[i]) | ||
var transformedPassword = blake2b(Buffer.from(password, 'utf-8'), 32) | ||
var transformedPasswordLen = transformedPassword.length | ||
var transformedPasswordArrPtr = Module._malloc(transformedPasswordLen) | ||
var transformedPasswordArr = new Uint8Array(Module.HEAPU8.buffer, transformedPasswordArrPtr, transformedPasswordLen) | ||
const transformedPassword = blake2b(Buffer.from(password, 'utf-8'), 32) | ||
const transformedPasswordLen = transformedPassword.length | ||
const transformedPasswordArrPtr = Module._malloc(transformedPasswordLen) | ||
const transformedPasswordArr = new Uint8Array(Module.HEAPU8.buffer, transformedPasswordArrPtr, transformedPasswordLen) | ||
var inputLen = input.length | ||
var inputArrPtr = Module._malloc(inputLen) | ||
var inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
const inputLen = input.length | ||
const inputArrPtr = Module._malloc(inputLen) | ||
const inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
var outputArrPtr = Module._malloc(inputLen) | ||
var outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, inputLen) | ||
const outputArrPtr = Module._malloc(inputLen) | ||
const outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, inputLen) | ||
@@ -379,18 +426,18 @@ inputArr.set(input) | ||
var inputLen = input.length | ||
var inputArrPtr = Module._malloc(inputLen) | ||
var inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
const inputLen = input.length | ||
const inputArrPtr = Module._malloc(inputLen) | ||
const inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
var keyLen = key.length | ||
var keyArrPtr = Module._malloc(keyLen) | ||
var keyArr = new Uint8Array(Module.HEAPU8.buffer, keyArrPtr, keyLen) | ||
const keyLen = key.length | ||
const keyArrPtr = Module._malloc(keyLen) | ||
const keyArr = new Uint8Array(Module.HEAPU8.buffer, keyArrPtr, keyLen) | ||
var nonceLen = nonce.length | ||
var nonceArrPtr = Module._malloc(nonceLen) | ||
var nonceArr = new Uint8Array(Module.HEAPU8.buffer, nonceArrPtr, nonceLen) | ||
const nonceLen = nonce.length | ||
const nonceArrPtr = Module._malloc(nonceLen) | ||
const nonceArr = new Uint8Array(Module.HEAPU8.buffer, nonceArrPtr, nonceLen) | ||
var tagLen = 16 | ||
var outputLen = inputLen + tagLen | ||
var outputArrPtr = Module._malloc(outputLen) | ||
var outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, outputLen) | ||
const tagLen = 16 | ||
const outputLen = inputLen + tagLen | ||
const outputArrPtr = Module._malloc(outputLen) | ||
const outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, outputLen) | ||
@@ -401,3 +448,3 @@ inputArr.set(input) | ||
var resultCode = Module._emscripten_chacha20poly1305_enc(keyArrPtr, nonceArrPtr, inputArrPtr, inputLen, outputArrPtr, outputArrPtr + inputLen, tagLen, 1) | ||
const resultCode = Module._emscripten_chacha20poly1305_enc(keyArrPtr, nonceArrPtr, inputArrPtr, inputLen, outputArrPtr, outputArrPtr + inputLen, tagLen, 1) | ||
@@ -422,24 +469,24 @@ Module._free(inputArrPtr) | ||
// extract tag from input | ||
var tagLen = 16 | ||
var tag = input.slice(input.length - tagLen, input.length) | ||
var input = input.slice(0, input.length - tagLen) | ||
const tagLen = 16 | ||
const tag = input.slice(input.length - tagLen, input.length) | ||
input = input.slice(0, input.length - tagLen) | ||
var inputLen = input.length | ||
var inputArrPtr = Module._malloc(inputLen) | ||
var inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
const inputLen = input.length | ||
const inputArrPtr = Module._malloc(inputLen) | ||
const inputArr = new Uint8Array(Module.HEAPU8.buffer, inputArrPtr, inputLen) | ||
var tagArrPtr = Module._malloc(tagLen) | ||
var tagArr = new Uint8Array(Module.HEAPU8.buffer, tagArrPtr, tagLen) | ||
const tagArrPtr = Module._malloc(tagLen) | ||
const tagArr = new Uint8Array(Module.HEAPU8.buffer, tagArrPtr, tagLen) | ||
var keyLen = key.length | ||
var keyArrPtr = Module._malloc(keyLen) | ||
var keyArr = new Uint8Array(Module.HEAPU8.buffer, keyArrPtr, keyLen) | ||
const keyLen = key.length | ||
const keyArrPtr = Module._malloc(keyLen) | ||
const keyArr = new Uint8Array(Module.HEAPU8.buffer, keyArrPtr, keyLen) | ||
var nonceLen = nonce.length | ||
var nonceArrPtr = Module._malloc(nonceLen) | ||
var nonceArr = new Uint8Array(Module.HEAPU8.buffer, nonceArrPtr, nonceLen) | ||
const nonceLen = nonce.length | ||
const nonceArrPtr = Module._malloc(nonceLen) | ||
const nonceArr = new Uint8Array(Module.HEAPU8.buffer, nonceArrPtr, nonceLen) | ||
var outputLen = inputLen | ||
var outputArrPtr = Module._malloc(outputLen) | ||
var outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, outputLen) | ||
const outputLen = inputLen | ||
const outputArrPtr = Module._malloc(outputLen) | ||
const outputArr = new Uint8Array(Module.HEAPU8.buffer, outputArrPtr, outputLen) | ||
@@ -451,3 +498,3 @@ inputArr.set(input) | ||
var resultCode = Module._emscripten_chacha20poly1305_enc(keyArrPtr, nonceArrPtr, inputArrPtr, inputLen, outputArrPtr, tagArrPtr, tagLen, 0) | ||
const resultCode = Module._emscripten_chacha20poly1305_enc(keyArrPtr, nonceArrPtr, inputArrPtr, inputLen, outputArrPtr, tagArrPtr, tagLen, 0) | ||
@@ -454,0 +501,0 @@ Module._free(inputArrPtr) |
{ | ||
"name": "cardano-crypto.js", | ||
"version": "3.1.10", | ||
"version": "4.0.1", | ||
"description": "input-output-hk/cardano-crypto compiled to pure javascript using Emscripten", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var test = require('tape') | ||
var lib = require('..') | ||
var sampleWalletMnemonic = 'logic easily waste eager injury oval sentence wine bomb embrace gossip supreme' | ||
var sampleWalletSecret = Buffer.from('d809b1b4b4c74734037f76aace501730a3fe2fca30b5102df99ad3f7c0103e48d54cde47e9041b31f3e6873d700d83f7a937bea746dadfa2c5b0a6a92502356ce6f04522f875c1563682ca876ddb04c2e2e3ae718e3ff9f11c03dd9f9dccf69869272d81c376382b8a87c21370a7ae9618df8da708d1a9490939ec54ebe43000', 'hex') | ||
var samplePublicKey = sampleWalletSecret.slice(64, 96) | ||
var sampleExtendedPublicKey = sampleWalletSecret.slice(64, 128) | ||
var sampleWalletMnemonicV1 = 'logic easily waste eager injury oval sentence wine bomb embrace gossip supreme' | ||
var sampleWalletMnemonicV2 = 'cost dash dress stove morning robust group affair stomach vacant route volume yellow salute laugh' | ||
var sampleWalletSecretV1 = Buffer.from('d809b1b4b4c74734037f76aace501730a3fe2fca30b5102df99ad3f7c0103e48d54cde47e9041b31f3e6873d700d83f7a937bea746dadfa2c5b0a6a92502356ce6f04522f875c1563682ca876ddb04c2e2e3ae718e3ff9f11c03dd9f9dccf69869272d81c376382b8a87c21370a7ae9618df8da708d1a9490939ec54ebe43000', 'hex') | ||
var sampleWalletSecretV2 = Buffer.from('70b441728448ebbafe087474d2ddc59be673700c70c3843660f681c34a0b57442a982a7c6edb0024d5b7a520d3369c236f6e0e649b78aebbe40a7b16618b9b2b783f05bc024661edbd9aa29651ea19d48ca974e70704f3d44ff7f48c37c5aa65f25b034e06cacc37ce661cdc718a4a35a221649d55d5e5691c16f6bec6ee7b85', 'hex') | ||
var samplePublicKey = sampleWalletSecretV1.slice(64, 96) | ||
var sampleExtendedPublicKey = sampleWalletSecretV1.slice(64, 128) | ||
var sampleMessage = Buffer.from('Hello world', 'utf-8') | ||
@@ -19,9 +21,9 @@ var sampleRightSignature = Buffer.from('1096ddcfb2ad21a4c0d861ef3fabe18841e8de88105b0d8e36430d7992c588634ead4100c32b2800b31b65e014d54a8238bdda63118d829bf0bcf1b631e86f0e', 'hex') | ||
test('wallet secret from mnemonic', function(t) { | ||
test('wallet secret from mnemonic V1', function(t) { | ||
t.plan(1) | ||
var walletSecret = lib.walletSecretFromMnemonic(sampleWalletMnemonic) | ||
var walletSecret = lib.walletSecretFromMnemonic(sampleWalletMnemonicV1, 1) | ||
t.equals( | ||
walletSecret.toString('hex'), | ||
sampleWalletSecret.toString('hex'), | ||
sampleWalletSecretV1.toString('hex'), | ||
'wallet secret derivates from mnemonic properly' | ||
@@ -31,6 +33,17 @@ ) | ||
test('wallet secret from mnemonic V2', function(t) { | ||
t.plan(1) | ||
var walletSecret = lib.walletSecretFromMnemonic(sampleWalletMnemonicV2, 2) | ||
t.equals( | ||
walletSecret.toString('hex'), | ||
sampleWalletSecretV2.toString('hex'), | ||
'wallet secret derivates from mnemonic properly' | ||
) | ||
}) | ||
test('signing', function(t) { | ||
t.plan(1) | ||
var signature = lib.sign(sampleMessage, sampleWalletSecret) | ||
var signature = lib.sign(sampleMessage, sampleWalletSecretV1) | ||
@@ -64,3 +77,3 @@ t.equals( | ||
t.equals( | ||
lib.derivePrivate(sampleWalletSecret, sampleHardenedIndex, 1).toString('hex'), | ||
lib.derivePrivate(sampleWalletSecretV1, sampleHardenedIndex, 1).toString('hex'), | ||
sampleHardenedChildKeyMode1.toString('hex'), | ||
@@ -71,3 +84,3 @@ 'should properly derive hardened child key in derivation mode 1' | ||
t.equals( | ||
lib.derivePrivate(sampleWalletSecret, sampleHardenedIndex, 2).toString('hex'), | ||
lib.derivePrivate(sampleWalletSecretV1, sampleHardenedIndex, 2).toString('hex'), | ||
sampleHardenedChildKeyMode2.toString('hex'), | ||
@@ -74,0 +87,0 @@ 'should properly derive hardened child key in derivation mode 2' |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
269442
2034