cardano-crypto.js
Advanced tools
Comparing version 4.1.0 to 4.2.0
20
index.js
@@ -622,2 +622,21 @@ const bip39 = require('bip39-light') | ||
function isValidAddress(address) { | ||
try { | ||
// we decode the address from the base58 string | ||
const addressAsArray = cbor.decode(base58.decode(address)) | ||
// we strip the 24 CBOR data taga by taking the "value" attribute from the "Tagged" object | ||
const addressDataEncoded = addressAsArray[0].value | ||
const crc32Checksum = addressAsArray[1] | ||
if (crc32Checksum !== crc32(addressDataEncoded)) { | ||
return false | ||
} | ||
} catch (e) { | ||
return false | ||
} | ||
return true | ||
} | ||
function getAddressHash(input) { | ||
@@ -665,2 +684,3 @@ // eslint-disable-next-line camelcase | ||
unpackAddress, | ||
isValidAddress, | ||
cardanoMemoryCombine, | ||
@@ -667,0 +687,0 @@ blake2b, |
{ | ||
"name": "cardano-crypto.js", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "input-output-hk/cardano-crypto compiled to pure javascript using Emscripten", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -20,3 +20,3 @@ # cardano-crypto.js | ||
## deriving child keys (hardened derivation, you can choose either derivation mode 1 or 2) | ||
## deriving child keys (hardened derivation, you can choose either derivation scheme 1 or 2) | ||
@@ -31,3 +31,3 @@ ``` javascript | ||
## deriving child public keys (nonhardened derivation, you can choose either derivation mode 1 or 2) | ||
## deriving child public keys (nonhardened derivation, you can choose either derivation scheme 1 or 2) | ||
@@ -63,3 +63,3 @@ ``` javascript | ||
* Install [emscripten](https://askubuntu.com/questions/891630/how-to-install-the-latest-emscripten-on-ubuntu-using-command-line) | ||
* Install [emscripten](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#installation-instructions), recommended version is 1.38.8 | ||
* run `npm install` | ||
@@ -66,0 +66,0 @@ * run `npm run build` |
@@ -23,3 +23,8 @@ var test = require('tape') | ||
var sampleDecodedPaperWalletMnemonic = 'swim average antenna there trap nice good stereo lion safe next brief' | ||
var sampleV1Address = 'DdzFFzCqrhssmYoG5Eca1bKZFdGS8d6iag1mU4wbLeYcSPVvBNF2wRG8yhjzQqErbg63N6KJA4DHqha113tjKDpGEwS5x1dT2KfLSbSJ' | ||
var sampleV2Address = 'Ae2tdPwUPEZ18ZjTLnLVr9CEvUEUX4eW1LBHbxxxJgxdAYHrDeSCSbCxrvx' | ||
var sampleAddressInvalidChecksum = 'Ae2tdPwUPEZ18ZjTLnLVr9CEvUEUX4eW1LBHbxxxJgxdAYHrDeSCSbCxrvm' | ||
var sampleRandomString = 'hasoiusaodiuhsaijnnsajnsaiussai' | ||
test('wallet secret from mnemonic V1', async function(t) { | ||
@@ -211,2 +216,27 @@ t.plan(1) | ||
) | ||
}) | ||
test('address validation', async function (t) { | ||
t.plan(4) | ||
t.equals( | ||
lib.isValidAddress(sampleV1Address), | ||
true, | ||
'should accept V1 address' | ||
) | ||
t.equals( | ||
lib.isValidAddress(sampleV2Address), | ||
true, | ||
'should accept V2 address' | ||
) | ||
t.equals( | ||
lib.isValidAddress(sampleAddressInvalidChecksum), | ||
false, | ||
'should reject address with invalid checksum' | ||
) | ||
t.equals( | ||
lib.isValidAddress(sampleRandomString), | ||
false, | ||
'should reject random string' | ||
) | ||
}) |
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
277965
2252