mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-04-25 16:32:26 +00:00
tests and browser tests setup
This commit is contained in:
parent
d7ab4bd8fb
commit
3c0c9a3b19
12
README.md
12
README.md
@ -43,22 +43,22 @@ You will need to use Node.js `Buffer` API compatible, if you are running inside
|
||||
var PeerId = require('ipfs-peer')
|
||||
|
||||
// Create a new Id
|
||||
var id = new PeerId.create()
|
||||
var id = PeerId.create()
|
||||
|
||||
// Recreate an Id from Hex string
|
||||
var id = new PeerId.createFromHexString(str)
|
||||
var id = PeerId.createFromHexString(str)
|
||||
|
||||
// Recreate an Id from a Buffer
|
||||
var id = new PeerId.createFromBytes(buf)
|
||||
var id = PeerId.createFromBytes(buf)
|
||||
|
||||
// Recreate an B58 String
|
||||
var id = new PeerId.createFromB58String(str)
|
||||
var id = PeerId.createFromB58String(str)
|
||||
|
||||
// Recreate from a Public Key
|
||||
var id = new PeerId.createFromPubKey(pubKey)
|
||||
var id = PeerId.createFromPubKey(pubKey)
|
||||
|
||||
// Recreate from a Private Key
|
||||
var id = new PeerId.createFromPrivKey(privKey)
|
||||
var id = PeerId.createFromPrivKey(privKey)
|
||||
```
|
||||
|
||||
### Exporting an Id
|
||||
|
24225
dist/peer-id.js
vendored
Normal file
24225
dist/peer-id.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
dist/peer-id.min.js
vendored
Normal file
11
dist/peer-id.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
14
package.json
14
package.json
@ -4,8 +4,13 @@
|
||||
"description": "IPFS Peer Id implementation in Node.js",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"test": "node tests/*-test.js",
|
||||
"lint": "standard"
|
||||
"test:node": "node tests/*-test.js",
|
||||
"lint": "standard",
|
||||
"test": "npm run test:node",
|
||||
"lint": "./node_modules/.bin/standard",
|
||||
"test:browser": "./node_modules/.bin/zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- tests/id-test.js",
|
||||
"test:browser:q": "BROWSER_VERSION=46 BROWSER_NAME=chrome npm run test:browser",
|
||||
"build": "./node_modules/.bin/browserify -s PeerId -e ./src/index.js | tee dist/peer-id.js | ./node_modules/.bin/uglifyjs -m > dist/peer-id.min.js"
|
||||
},
|
||||
"keywords": [
|
||||
"IPFS"
|
||||
@ -16,6 +21,11 @@
|
||||
"lint",
|
||||
"test"
|
||||
],
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"dist"
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"node": "^4.2.0"
|
||||
},
|
||||
|
@ -25,7 +25,7 @@ function Id (id, privKey, pubKey) {
|
||||
|
||||
self.toPrint = function () {
|
||||
return {
|
||||
id: id.toHexString(),
|
||||
id: self.toHexString(),
|
||||
privKey: privKey.toString('hex'),
|
||||
pubKey: pubKey.toString('hex')
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
var test = require('tape')
|
||||
var PeerId = require('../src')
|
||||
|
||||
var testId = {
|
||||
id: '1220151ab1658d8294ab34b71d5582cfe20d06414212f440a69366f1bc31deb5c72d',
|
||||
privKey: '-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAgPEiGHOwFEUdo95/DaALH69umbFI4xD3Jmla0hiHbkcW535arBfFd8nJ\ns5VPt49sgdSgn1ZmiqmHLgMwMz6mKplu4GsmWj5mjdyxiNl5z6R2rF+ZziuiwRTeHVX/8zR8\nM7Cbh0QXmzpoq6LcNOFHbg495zsbmT9QAtjVsS1KyF5324mxbTZtjaD6hxJkAL8aVi0ikvhA\nL4HuZ1m3brjSSZ0+epFCFL7UIoJlFfOvap2sAyxdOrSvY2PXKTE00s51YTin5+CrvofRLCJP\nROls1oFkhXIDGfuTGTxMxe3hSUlNj0LjQi6RXPGat/5XH0nCuFTODmyhrnnnx51OdgT9vwID\nAQABAoIBAQAIAnKSwET0zWJM9po/12w5eKVPKMMVT816dlrs6Bcpk4LpuGCbhhJ/IWrFHAZK\nqb8cxX+AxlYyUNuT0SDiXgbmaIe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jwAxK1wVGw9UcQl0w/utuDxcGCArlszFcRNPX1g/5e0F07OXM8bF9gQcom1HZBKgLaoLStI\nz94OOA==\n-----END RSA PRIVATE KEY-----\n',
|
||||
pubKey: '-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAgPEiGHOwFEUdo95/DaALH69umbFI4xD3Jmla0hiHbkcW535arBfFd8nJs5VP\nt49sgdSgn1ZmiqmHLgMwMz6mKplu4GsmWj5mjdyxiNl5z6R2rF+ZziuiwRTeHVX/8zR8M7Cb\nh0QXmzpoq6LcNOFHbg495zsbmT9QAtjVsS1KyF5324mxbTZtjaD6hxJkAL8aVi0ikvhAL4Hu\nZ1m3brjSSZ0+epFCFL7UIoJlFfOvap2sAyxdOrSvY2PXKTE00s51YTin5+CrvofRLCJPROls\n1oFkhXIDGfuTGTxMxe3hSUlNj0LjQi6RXPGat/5XH0nCuFTODmyhrnnnx51OdgT9vwIDAQAB\n-----END RSA PUBLIC KEY-----\n'
|
||||
}
|
||||
|
||||
var testIdHex = '1220151ab1658d8294ab34b71d5582cfe20d06414212f440a69366f1bc31deb5c72d'
|
||||
|
||||
var testIdBytes = new Buffer('1220151ab1658d8294ab34b71d5582cfe20d06414212f440a69366f1bc31deb5c72d', 'hex')
|
||||
|
||||
var testIdB58String = 'QmPm2sunRFpswBAByqunK5Yk8PLj7mxL5HpCS4Qg6p7LdS'
|
||||
|
||||
test('create a new Id', function (t) {
|
||||
var id = PeerId.create()
|
||||
t.ok(id)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('recreate an Id from Hex string', function (t) {
|
||||
var id = PeerId.createFromHexString(testIdHex)
|
||||
t.ok(id)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Recreate an Id from a Buffer', function (t) {
|
||||
var id = PeerId.createFromBytes(testIdBytes)
|
||||
t.ok(id)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Recreate an B58 String', function (t) {
|
||||
var id = PeerId.createFromB58String(testIdB58String)
|
||||
t.ok(id)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Recreate from a Public Key', function (t) {
|
||||
var id = PeerId.createFromPubKey(testId.pubKey)
|
||||
t.ok(id)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Recreate from a Private Key', function (t) {
|
||||
// TODO
|
||||
t.end()
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user