Comparing version 1.2.0 to 1.3.0
13
index.js
@@ -8,2 +8,5 @@ var nacl = require("tweetnacl"); | ||
var x = nacl.sign.keyPair.fromSeed(seed); | ||
var secretKey = x.secretKey.subarray(0, 32); | ||
var signKey = bs58.encode(secretKey); | ||
var keyPair = nacl.box.keyPair.fromSecretKey(secretKey); | ||
@@ -14,6 +17,8 @@ return { | ||
verifyKey: bs58.encode(x.publicKey), | ||
encryptionPublicKey: bs58.encode(keyPair.publicKey), | ||
secret: { | ||
seed: Buffer.from(seed).toString("hex"), | ||
signKey: bs58.encode(x.secretKey.subarray(0, 32)), | ||
signKey: signKey, | ||
encryptionPrivateKey: bs58.encode(keyPair.secretKey), | ||
}, | ||
@@ -45,3 +50,3 @@ }; | ||
var getBoxKeyPairFromSignKey = function (signKey) { | ||
var getKeyPairFromSignKey = function (signKey) { | ||
return nacl.box.keyPair.fromSecretKey(getArrayFromKey(signKey)); | ||
@@ -51,2 +56,4 @@ }; | ||
var getSharedSecret = function (theirVerifyKey, mySigningKey) { | ||
theirVerifyKey = typeof theirVerifyKey === "string" ? bs58.decode(theirVerifyKey) : theirVerifyKey; | ||
mySigningKey = typeof mySigningKey === "string" ? bs58.decode(mySigningKey) : mySigningKey; | ||
return nacl.box.before(theirVerifyKey, mySigningKey) | ||
@@ -72,3 +79,3 @@ }; | ||
verifySignedMessage: verifySignedMessage, | ||
getKeyPairFromSignKey: getBoxKeyPairFromSignKey, | ||
getKeyPairFromSignKey: getKeyPairFromSignKey, | ||
getSharedSecret: getSharedSecret, | ||
@@ -75,0 +82,0 @@ decryptMessage: decryptMessage, |
{ | ||
"name": "sovrin-did", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "node.js module to generate DID and Ed25519 keys to use with Sovrin", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -28,5 +28,7 @@ # node-sovrin-did | ||
verifyKey: 'EgvhZsLKSsqsbNBfJ2wfR9FFWo9YqkpxpfXeT4ifR1Cq', | ||
encryptionPublicKey: '5UAXeov4Gi7ioSTLDoMPtdvqX6RRmJcQAWagVgdaxUej', | ||
secret: | ||
{ seed: '36a572a7e43956784b517c57b26720a8ef838d114c0619f1d8c7801c37fa4f6a', | ||
signKey: '4gKLe7Qq2WX249NBfymQySZbAzXboq2emMig6wBR82Bj' } } | ||
signKey: '4gKLe7Qq2WX249NBfymQySZbAzXboq2emMig6wBR82Bj', | ||
encryptionPrivateKey: '7H25Jfb2ND51hhaomL5FPhhqQvBGujd1jJeSjZZ8HQzR'} } | ||
``` | ||
@@ -40,3 +42,3 @@ | ||
Generates a new did, verification key, signing key, and also gives you the seed used to generate them. | ||
Generates a new did, verification key, signing key, and also gives you the seed used to generate them. It also includes the public and private key used for encryption. | ||
@@ -47,6 +49,8 @@ ```js | ||
verifyKey: "<base58 publicKey>", | ||
publicKey: "<base58 publicKey>", | ||
secret: { | ||
seed: "<hex encoded 32-byte seed>", | ||
signKey: "<base58 secretKey>" | ||
signKey: "<base58 secretKey>", | ||
privateKey: "<base58 privateKey>" | ||
} | ||
@@ -164,4 +168,4 @@ } | ||
* theirVerifyKey should be the publicKey given from the `getKeyPairFromSignKey(signKey)` method | ||
* mySigningKey should be the secretKey given from the `getKeyPairFromSignKey(signKey)` method | ||
* theirVerifyKey should be the publicKey given from the `getKeyPairFromSignKey(signKey)` method or the publicKey string given from the `gen()` method. | ||
* mySigningKey should be the secretKey given from the `getKeyPairFromSignKey(signKey)` method or the privateKey given from the `gen()` method. | ||
@@ -172,2 +176,7 @@ Example: | ||
var sovrin2 = sovrinDID.gen(); | ||
// Using the strings given via the gen() method | ||
var sharedSecret1 = sovrinDID.getSharedSecret(sovrin2.encryptionPublicKey, sovrin1.secret.encryptionPrivateKey); | ||
var sharedSecret2 = sovrinDID.getSharedSecret(sovrin1.encryptionPublicKey, sovrin2.secret.encryptionPrivateKey); | ||
var signKey1 = sovrin1.secret.signKey; | ||
@@ -179,5 +188,7 @@ var signKey2 = sovrin2.secret.signKey; | ||
// These two secrets are the same | ||
var sharedSecret1To2 = sovrinDID.getSharedSecret(keyPair2.publicKey, keyPair1.secretKey); | ||
var sharedSecret2To1 = sovrinDID.getSharedSecret(keyPair1.publicKey, keyPair2.secretKey); | ||
// Using the buffer given from the getKeyPairFromSignKey(signKey2) method | ||
var sharedSecret3 = sovrinDID.getSharedSecret(keyPair2.publicKey, keyPair1.secretKey); | ||
var sharedSecret4 = sovrinDID.getSharedSecret(keyPair1.publicKey, keyPair2.secretKey); | ||
// All the secrets generated are equivalent | ||
``` | ||
@@ -184,0 +195,0 @@ |
19
tests.js
@@ -17,2 +17,3 @@ var test = require("tape"); | ||
verifyKey: "QDQ7Y69yg6eeJNstq62rXw8mK8HmnnsocPwvo9DU2tS", | ||
encryptionPublicKey: "C2CLejK2c3SC9Rz4JLFuNtWJM8WDRq2CEMJuRqaJvr35", | ||
@@ -22,2 +23,3 @@ secret: { | ||
signKey: "516mChDX1BRjwHJc2w838W8cXxy8a6Eb35HKXjPR2fD8", | ||
encryptionPrivateKey: "516mChDX1BRjwHJc2w838W8cXxy8a6Eb35HKXjPR2fD8", | ||
}, | ||
@@ -30,2 +32,3 @@ }); | ||
verifyKey: "89ZgeKmTktxWg9UrGFzL2PbcHrToKNMPpLQtjbh17pfT", | ||
encryptionPublicKey: "5UAXeov4Gi7ioSTLDoMPtdvqX6RRmJcQAWagVgdaxUej", | ||
@@ -35,2 +38,3 @@ secret: { | ||
signKey: "7H25Jfb2ND51hhaomL5FPhhqQvBGujd1jJeSjZZ8HQzR", | ||
encryptionPrivateKey: "7H25Jfb2ND51hhaomL5FPhhqQvBGujd1jJeSjZZ8HQzR", | ||
}, | ||
@@ -43,2 +47,3 @@ }); | ||
verifyKey: "FgFdznhQTymQEBKNoboDLKDGWB7eezrhvKKQK2uKUSU5", | ||
encryptionPublicKey: "3mosoLnk91yNrGga3vJtLaFNXf9yi85gSNisMT643HyH", | ||
@@ -48,2 +53,3 @@ secret: { | ||
signKey: "9Po5sqUto67MYFyfXXgV3PwvXoRxCfEXpSoMKn1eFtcv", | ||
encryptionPrivateKey: "9Po5sqUto67MYFyfXXgV3PwvXoRxCfEXpSoMKn1eFtcv", | ||
}, | ||
@@ -56,2 +62,3 @@ }); | ||
verifyKey: "BzH5a2wLEyKxySUALpfBiBjHZtZudCG68J17QwWkRsdN", | ||
encryptionPublicKey: "7QhcMiFkfZLf6TScAucX2kw3A9561MHMukWUhnsSzba8", | ||
@@ -61,2 +68,3 @@ secret: { | ||
signKey: "4bMnc36WuLYJqsWTZtiazJJrtkvPwgyWnirn7gKk7ium", | ||
encryptionPrivateKey: "4bMnc36WuLYJqsWTZtiazJJrtkvPwgyWnirn7gKk7ium", | ||
}, | ||
@@ -124,3 +132,3 @@ }); | ||
test("sovrinDID.getSharedSecret(theirVerifyKey, mySigningKey", function(t) { | ||
test("sovrinDID.getSharedSecret(theirVerifyKey, mySigningKey)", function(t) { | ||
var signKey1 = "4bMnc36WuLYJqsWTZtiazJJrtkvPwgyWnirn7gKk7ium"; | ||
@@ -134,2 +142,11 @@ var signKey2 = "516mChDX1BRjwHJc2w838W8cXxy8a6Eb35HKXjPR2fD8"; | ||
var sovrin1 = sovrinDID.gen(); | ||
var sovrin2 = sovrinDID.gen(); | ||
// Create shared secrets from the string version of the keys | ||
var sharedSecret1 = sovrinDID.getSharedSecret(sovrin2.encryptionPublicKey, sovrin1.secret.encryptionPrivateKey); | ||
var sharedSecret2 = sovrinDID.getSharedSecret(sovrin1.encryptionPublicKey, sovrin2.secret.encryptionPrivateKey); | ||
t.equal(nacl.verify(sharedSecret1, sharedSecret2), true); | ||
var sharedSecret1To2 = sovrinDID.getSharedSecret(keyPair2.publicKey, keyPair1.secretKey); | ||
@@ -136,0 +153,0 @@ var sharedSecret2To1 = sovrinDID.getSharedSecret(keyPair1.publicKey, keyPair2.secretKey); |
19778
207
261
6