Comparing version 0.1.0 to 0.1.1
@@ -52,3 +52,3 @@ 'use strict'; | ||
expect(function () { | ||
(0, _index.decode)('3FeXiAwmuLCe5ivArnhvmt3AMupZeFCT8LFum6g'); | ||
(0, _index.decode)('2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqU'); | ||
}).toThrow('Invalid address checksum'); | ||
@@ -77,2 +77,29 @@ }); | ||
}); | ||
}); | ||
describe('isMNID', function () { | ||
it('is valid', function () { | ||
expect((0, _index.isMNID)('2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX')).toBeTruthy(); | ||
expect((0, _index.isMNID)('5A8bRWU3F7j3REx3vkJWxdjQPp4tqmxFPmab1Tr')).toBeTruthy(); | ||
expect((0, _index.isMNID)('2oDZvNUgn77w2BKTkd9qKpMeUo8EL94QL5V')).toBeTruthy(); | ||
expect((0, _index.isMNID)('34ukSmiK1oA1C5Du8aWpkjFGALoH7nsHeDX')).toBeTruthy(); | ||
// bad checksum but still MNID | ||
expect((0, _index.isMNID)('2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqU')).toBeTruthy(); | ||
}); | ||
it('is invalid', function () { | ||
// Ethereum Hex | ||
expect((0, _index.isMNID)('0x00521965e7bd230323c423d96c657db5b79d099f')).toBeFalsy(); | ||
// Bitcoin | ||
expect((0, _index.isMNID)('1GbVUSW5WJmRCpaCJ4hanUny77oDaWW4to')).toBeFalsy(); | ||
// IPFS | ||
expect((0, _index.isMNID)('QmXuNqXmrkxs4WhTDC2GCnXEep4LUD87bu97LQMn1rkxmQ')).toBeFalsy(); | ||
// Cut off | ||
expect((0, _index.isMNID)('2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkq')).toBeFalsy(); | ||
expect((0, _index.isMNID)('')).toBeFalsy(); | ||
expect((0, _index.isMNID)(null)).toBeFalsy(); | ||
}); | ||
}); |
@@ -8,2 +8,3 @@ 'use strict'; | ||
exports.decode = decode; | ||
exports.isMNID = isMNID; | ||
@@ -46,2 +47,11 @@ var _jsSha = require('js-sha3'); | ||
} | ||
} | ||
function isMNID(encoded) { | ||
try { | ||
var data = _buffer.Buffer.from(base58.decode(encoded)); | ||
return data.length > 24 && data[0] === 1; | ||
} catch (e) { | ||
return false; | ||
} | ||
} |
{ | ||
"name": "mnid", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Multi Network Identifier - Blockchain Address Encoding", | ||
@@ -13,2 +13,6 @@ "main": "lib/index.js", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/uport-project/mnid.git" | ||
}, | ||
"files": [ | ||
@@ -24,2 +28,6 @@ "dist", | ||
}, | ||
"jest": { | ||
"coverageDirectory": "./coverage/", | ||
"collectCoverage": true | ||
}, | ||
"devDependencies": { | ||
@@ -26,0 +34,0 @@ "babel-cli": "^6.24.0", |
@@ -44,4 +44,33 @@ # Multi Network Identifier (MNID) | ||
## Previous Work | ||
## Javascript reference implementation | ||
```js | ||
> var mnid = require('mnid') | ||
> mnid.encode({ | ||
network: '0x1', // the hex encoded network id or for private chains the hex encoded first 4 bytes of the genesis hash | ||
address: '0x00521965e7bd230323c423d96c657db5b79d099f' | ||
}) | ||
'2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX' | ||
> mnid.decode('2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX') | ||
{ network: '0x1', | ||
address: '0x00521965e7bd230323c423d96c657db5b79d099f' } | ||
// Check if string is a valid MNID | ||
> mnid.isMNID('2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX') | ||
true | ||
> mnid.isMNID('0x00521965e7bd230323c423d96c657db5b79d099f') | ||
false | ||
> mnid.isMNID('1GbVUSW5WJmRCpaCJ4hanUny77oDaWW4to') | ||
false | ||
> mnid.isMNID('QmXuNqXmrkxs4WhTDC2GCnXEep4LUD87bu97LQMn1rkxmQ') | ||
false | ||
``` | ||
## Inspirations | ||
### Base58Check Encoding | ||
@@ -48,0 +77,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { encode, decode } from '../index' | ||
import { encode, decode, isMNID } from '../index' | ||
@@ -52,3 +52,3 @@ describe('encode', () => { | ||
expect(() => { | ||
decode('3FeXiAwmuLCe5ivArnhvmt3AMupZeFCT8LFum6g') | ||
decode('2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqU') | ||
}).toThrow('Invalid address checksum') | ||
@@ -83,2 +83,30 @@ }) | ||
}) | ||
}) | ||
describe('isMNID', () => { | ||
it('is valid', () => { | ||
expect(isMNID('2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX')).toBeTruthy() | ||
expect(isMNID('5A8bRWU3F7j3REx3vkJWxdjQPp4tqmxFPmab1Tr')).toBeTruthy() | ||
expect(isMNID('2oDZvNUgn77w2BKTkd9qKpMeUo8EL94QL5V')).toBeTruthy() | ||
expect(isMNID('34ukSmiK1oA1C5Du8aWpkjFGALoH7nsHeDX')).toBeTruthy() | ||
// bad checksum but still MNID | ||
expect(isMNID('2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqU')).toBeTruthy() | ||
}) | ||
it('is invalid', () => { | ||
// Ethereum Hex | ||
expect(isMNID('0x00521965e7bd230323c423d96c657db5b79d099f')).toBeFalsy() | ||
// Bitcoin | ||
expect(isMNID('1GbVUSW5WJmRCpaCJ4hanUny77oDaWW4to')).toBeFalsy() | ||
// IPFS | ||
expect(isMNID('QmXuNqXmrkxs4WhTDC2GCnXEep4LUD87bu97LQMn1rkxmQ')).toBeFalsy() | ||
// Cut off | ||
expect(isMNID('2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkq')).toBeFalsy() | ||
expect(isMNID('')).toBeFalsy() | ||
expect(isMNID(null)).toBeFalsy() | ||
}) | ||
}) |
@@ -34,1 +34,10 @@ var BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' | ||
} | ||
export function isMNID (encoded) { | ||
try { | ||
const data = Buffer.from(base58.decode(encoded)) | ||
return data.length > 24 && data[0] === 1 | ||
} catch (e) { | ||
return false | ||
} | ||
} |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
14317
260
98
0