@ledgerhq/hw-ledger-key-ring-protocol 0.3.1-next.0 → 0.3.2-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +28 -0
- package/lib/ApduDevice.d.ts +1 -0
- package/lib/ApduDevice.d.ts.map +1 -1
- package/lib/ApduDevice.js +195 -240
- package/lib/ApduDevice.js.map +1 -1
- package/lib/CommandBlock.js +26 -2
- package/lib/CommandBlock.js.map +1 -1
- package/lib/CommandStream.js +69 -85
- package/lib/CommandStream.js.map +1 -1
- package/lib/CommandStreamResolver.js +42 -56
- package/lib/CommandStreamResolver.js.map +1 -1
- package/lib/Device.js +115 -131
- package/lib/Device.js.map +1 -1
- package/lib/IndexedTree.js +2 -0
- package/lib/IndexedTree.js.map +1 -1
- package/lib/PublicKey.js +1 -0
- package/lib/PublicKey.js.map +1 -1
- package/lib/SeedId.js +12 -0
- package/lib/SeedId.js.map +1 -1
- package/lib/StreamTree.js +56 -72
- package/lib/StreamTree.js.map +1 -1
- package/lib/StreamTreeCipher.js +62 -75
- package/lib/StreamTreeCipher.js.map +1 -1
- package/lib/__tests__/codec.js +3 -12
- package/lib/__tests__/codec.js.map +1 -1
- package/lib/__tests__/crypto.js +22 -31
- package/lib/__tests__/crypto.js.map +1 -1
- package/lib/__tests__/indexed_tree.js +2 -3
- package/lib/__tests__/indexed_tree.js.map +1 -1
- package/lib/__tests__/key_exchange.js +40 -49
- package/lib/__tests__/key_exchange.js.map +1 -1
- package/lib/__tests__/shared_object.js +34 -47
- package/lib/__tests__/shared_object.js.map +1 -1
- package/lib-es/ApduDevice.d.ts +1 -0
- package/lib-es/ApduDevice.d.ts.map +1 -1
- package/lib-es/ApduDevice.js +195 -240
- package/lib-es/ApduDevice.js.map +1 -1
- package/lib-es/CommandBlock.js +26 -2
- package/lib-es/CommandBlock.js.map +1 -1
- package/lib-es/CommandStream.js +69 -85
- package/lib-es/CommandStream.js.map +1 -1
- package/lib-es/CommandStreamResolver.js +42 -56
- package/lib-es/CommandStreamResolver.js.map +1 -1
- package/lib-es/Device.js +115 -131
- package/lib-es/Device.js.map +1 -1
- package/lib-es/IndexedTree.js +2 -0
- package/lib-es/IndexedTree.js.map +1 -1
- package/lib-es/PublicKey.js +1 -0
- package/lib-es/PublicKey.js.map +1 -1
- package/lib-es/SeedId.js +12 -0
- package/lib-es/SeedId.js.map +1 -1
- package/lib-es/StreamTree.js +56 -72
- package/lib-es/StreamTree.js.map +1 -1
- package/lib-es/StreamTreeCipher.js +62 -75
- package/lib-es/StreamTreeCipher.js.map +1 -1
- package/lib-es/__tests__/codec.js +3 -12
- package/lib-es/__tests__/codec.js.map +1 -1
- package/lib-es/__tests__/crypto.js +22 -31
- package/lib-es/__tests__/crypto.js.map +1 -1
- package/lib-es/__tests__/indexed_tree.js +2 -3
- package/lib-es/__tests__/indexed_tree.js.map +1 -1
- package/lib-es/__tests__/key_exchange.js +40 -49
- package/lib-es/__tests__/key_exchange.js.map +1 -1
- package/lib-es/__tests__/shared_object.js +34 -47
- package/lib-es/__tests__/shared_object.js.map +1 -1
- package/package.json +4 -4
- package/tsconfig.json +0 -1
|
@@ -2,60 +2,47 @@
|
|
|
2
2
|
This test suite simulates an application generating data (using a fixed shchema) and sharing part of the
|
|
3
3
|
data to specific users. The data is encrypted using a StreamTree.
|
|
4
4
|
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
5
|
import { StreamTree } from "../StreamTree";
|
|
15
6
|
import { device } from "..";
|
|
16
7
|
import { Permissions } from "../CommandBlock";
|
|
17
8
|
import { StreamTreeCipher } from "../StreamTreeCipher";
|
|
18
9
|
import { DerivationPath, crypto } from "../Crypto";
|
|
19
10
|
const APPLICATION_ID = 12;
|
|
20
|
-
function encryptSharedObject(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return encryptedSharedObject;
|
|
32
|
-
});
|
|
11
|
+
async function encryptSharedObject(device, tree, sharedObject, mapping = new Map()) {
|
|
12
|
+
const cipher = StreamTreeCipher.create(device);
|
|
13
|
+
const encrypt = async (key, defaultPath) => {
|
|
14
|
+
return crypto.to_hex(await cipher.encrypt(tree, DerivationPath.toIndexArray(mapping.get(key) || defaultPath), new TextEncoder().encode(sharedObject[key].toString())));
|
|
15
|
+
};
|
|
16
|
+
const encryptedSharedObject = {
|
|
17
|
+
name: await encrypt("name", `0h/${APPLICATION_ID}h/0h/0h/0h`),
|
|
18
|
+
age: await encrypt("age", `0h/${APPLICATION_ID}h/0h/1h/0h`),
|
|
19
|
+
email: await encrypt("email", `0h/${APPLICATION_ID}h/0h/2h/0h`),
|
|
20
|
+
};
|
|
21
|
+
return encryptedSharedObject;
|
|
33
22
|
}
|
|
34
|
-
function decryptSharedObject(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return sharedObject;
|
|
48
|
-
});
|
|
23
|
+
async function decryptSharedObject(device, tree, encryptedSharedObject, mapping = new Map()) {
|
|
24
|
+
const cipher = StreamTreeCipher.create(device);
|
|
25
|
+
const decrypt = async (key, defaultPath) => {
|
|
26
|
+
const path = DerivationPath.toIndexArray(mapping.get(key) || defaultPath);
|
|
27
|
+
const bytes = await cipher.decrypt(tree, path, crypto.from_hex(encryptedSharedObject[key]));
|
|
28
|
+
return new TextDecoder().decode(bytes);
|
|
29
|
+
};
|
|
30
|
+
const sharedObject = {
|
|
31
|
+
name: await decrypt("name", `0h/${APPLICATION_ID}h/0h/0h/0h`),
|
|
32
|
+
age: parseInt(await decrypt("age", `0h/${APPLICATION_ID}h/0h/1h/0h`)),
|
|
33
|
+
email: await decrypt("email", `0h/${APPLICATION_ID}h/0h/2h/0h`),
|
|
34
|
+
};
|
|
35
|
+
return sharedObject;
|
|
49
36
|
}
|
|
50
37
|
describe("Shared object scenario using StreamTree", () => {
|
|
51
|
-
it("should create a tree with 3 members, one member encrypt a shared object and another one decrypts it", () =>
|
|
52
|
-
const alice =
|
|
53
|
-
const bob =
|
|
54
|
-
const carol =
|
|
38
|
+
it("should create a tree with 3 members, one member encrypt a shared object and another one decrypts it", async () => {
|
|
39
|
+
const alice = await device.software();
|
|
40
|
+
const bob = await device.software();
|
|
41
|
+
const carol = await device.software();
|
|
55
42
|
// Create a new tree owned by alice
|
|
56
|
-
let tree =
|
|
43
|
+
let tree = await StreamTree.createNewTree(alice);
|
|
57
44
|
// Share the application node with bob
|
|
58
|
-
tree =
|
|
45
|
+
tree = await tree.share(tree.getApplicationRootPath(APPLICATION_ID), alice, (await bob.getPublicKey()).publicKey, "Bob", Permissions.OWNER);
|
|
59
46
|
// Bob creates a shared object and encrypt it (1 value -> 1 encryption key)
|
|
60
47
|
const sharedObject = {
|
|
61
48
|
name: "Bob",
|
|
@@ -63,14 +50,14 @@ describe("Shared object scenario using StreamTree", () => {
|
|
|
63
50
|
email: "bob@box.com",
|
|
64
51
|
};
|
|
65
52
|
//console.dir(sharedObject, { depth: null });
|
|
66
|
-
const encryptedObject =
|
|
53
|
+
const encryptedObject = await encryptSharedObject(bob, tree, sharedObject);
|
|
67
54
|
// Share the application node with carol
|
|
68
|
-
tree =
|
|
55
|
+
tree = await tree.share(tree.getApplicationRootPath(APPLICATION_ID), alice, (await carol.getPublicKey()).publicKey, "Carol", Permissions.OWNER);
|
|
69
56
|
// Decrypt with Carol
|
|
70
|
-
const decryptedObject =
|
|
57
|
+
const decryptedObject = await decryptSharedObject(carol, tree, encryptedObject);
|
|
71
58
|
//console.dir(encryptedObject, { depth: null });
|
|
72
59
|
//console.dir(decryptedObject, { depth: null });
|
|
73
60
|
expect(decryptedObject).toEqual(sharedObject);
|
|
74
|
-
})
|
|
61
|
+
});
|
|
75
62
|
});
|
|
76
63
|
//# sourceMappingURL=shared_object.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared_object.js","sourceRoot":"","sources":["../../src/__tests__/shared_object.ts"],"names":[],"mappings":"AAAA;;;EAGE
|
|
1
|
+
{"version":3,"file":"shared_object.js","sourceRoot":"","sources":["../../src/__tests__/shared_object.ts"],"names":[],"mappings":"AAAA;;;EAGE;AAEF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAU,MAAM,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAcnD,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,KAAK,UAAU,mBAAmB,CAChC,MAAc,EACd,IAAgB,EAChB,YAA0B,EAC1B,UAA+B,IAAI,GAAG,EAAE;IAExC,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,KAAK,EAAE,GAA8B,EAAE,WAAmB,EAAmB,EAAE;QAC7F,OAAO,MAAM,CAAC,MAAM,CAClB,MA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EF,qBAAqB;QACrB,MAAM,eAAe,GAAG,MAAM,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC;QAEhF,gDAAgD;QAChD,gDAAgD;QAEhD,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/hw-ledger-key-ring-protocol",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2-next.2",
|
|
4
4
|
"description": "Ledger Key Ring Protocol hardware layer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"tiny-secp256k1": "1.1.7",
|
|
25
25
|
"@ledgerhq/hw-transport": "6.31.4",
|
|
26
26
|
"@ledgerhq/logs": "6.12.0",
|
|
27
|
-
"@ledgerhq/live-env": "2.
|
|
27
|
+
"@ledgerhq/live-env": "2.6.0-next.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/lodash": "4",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"clean": "rimraf lib lib-es",
|
|
54
|
-
"build": "tsc && tsc -m
|
|
54
|
+
"build": "tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es",
|
|
55
55
|
"prewatch": "pnpm build",
|
|
56
56
|
"watch": "tsc --watch",
|
|
57
|
-
"watch:es": "tsc --watch -m
|
|
57
|
+
"watch:es": "tsc --watch -m esnext --moduleResolution bundler --outDir lib-es",
|
|
58
58
|
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
59
59
|
"lint:fix": "pnpm lint --fix",
|
|
60
60
|
"typecheck": "tsc --noEmit",
|