@ledgerhq/hw-ledger-key-ring-protocol 0.2.1-nightly.0 → 0.2.1-spl-test.0
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 +1 -1
- package/CHANGELOG.md +3 -3
- package/lib/ApduDevice.d.ts.map +1 -1
- package/lib/ApduDevice.js +37 -41
- package/lib/ApduDevice.js.map +1 -1
- package/lib/CommandBlock.d.ts +4 -4
- package/lib/CommandBlock.d.ts.map +1 -1
- package/lib/CommandBlock.js +18 -35
- package/lib/CommandBlock.js.map +1 -1
- package/lib/CommandStream.d.ts +1 -1
- package/lib/CommandStream.d.ts.map +1 -1
- package/lib/CommandStream.js +5 -7
- package/lib/CommandStream.js.map +1 -1
- package/lib/Crypto.d.ts +11 -11
- package/lib/Crypto.d.ts.map +1 -1
- package/lib/Device.d.ts +1 -1
- package/lib/Device.d.ts.map +1 -1
- package/lib/Device.js +28 -36
- package/lib/Device.js.map +1 -1
- package/lib/NobleCrypto.d.ts +13 -15
- package/lib/NobleCrypto.d.ts.map +1 -1
- package/lib/NobleCrypto.js +90 -148
- package/lib/NobleCrypto.js.map +1 -1
- package/lib/StreamTreeCipher.d.ts.map +1 -1
- package/lib/StreamTreeCipher.js +32 -36
- package/lib/StreamTreeCipher.js.map +1 -1
- package/lib/__tests__/codec.js +33 -33
- package/lib/__tests__/codec.js.map +1 -1
- package/lib-es/ApduDevice.d.ts.map +1 -1
- package/lib-es/ApduDevice.js +37 -41
- package/lib-es/ApduDevice.js.map +1 -1
- package/lib-es/CommandBlock.d.ts +4 -4
- package/lib-es/CommandBlock.d.ts.map +1 -1
- package/lib-es/CommandBlock.js +18 -35
- package/lib-es/CommandBlock.js.map +1 -1
- package/lib-es/CommandStream.d.ts +1 -1
- package/lib-es/CommandStream.d.ts.map +1 -1
- package/lib-es/CommandStream.js +5 -7
- package/lib-es/CommandStream.js.map +1 -1
- package/lib-es/Crypto.d.ts +11 -11
- package/lib-es/Crypto.d.ts.map +1 -1
- package/lib-es/Device.d.ts +1 -1
- package/lib-es/Device.d.ts.map +1 -1
- package/lib-es/Device.js +28 -36
- package/lib-es/Device.js.map +1 -1
- package/lib-es/NobleCrypto.d.ts +13 -15
- package/lib-es/NobleCrypto.d.ts.map +1 -1
- package/lib-es/NobleCrypto.js +90 -148
- package/lib-es/NobleCrypto.js.map +1 -1
- package/lib-es/StreamTreeCipher.d.ts.map +1 -1
- package/lib-es/StreamTreeCipher.js +32 -36
- package/lib-es/StreamTreeCipher.js.map +1 -1
- package/lib-es/__tests__/codec.js +33 -33
- package/lib-es/__tests__/codec.js.map +1 -1
- package/package.json +2 -2
- package/src/ApduDevice.ts +10 -14
- package/src/CommandBlock.ts +11 -14
- package/src/CommandStream.ts +6 -8
- package/src/Crypto.ts +11 -11
- package/src/Device.ts +26 -34
- package/src/NobleCrypto.ts +20 -59
- package/src/StreamTreeCipher.ts +15 -15
- package/src/__tests__/codec.ts +32 -32
package/src/__tests__/codec.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { crypto } from "../Crypto";
|
|
|
13
13
|
import { CommandStream } from "..";
|
|
14
14
|
|
|
15
15
|
describe("Encode/Decode command stream tester", () => {
|
|
16
|
-
it("should encode and decode a byte",
|
|
16
|
+
it("should encode and decode a byte", () => {
|
|
17
17
|
const byte = 42;
|
|
18
18
|
let buffer = new Uint8Array();
|
|
19
19
|
buffer = TLV.pushByte(buffer, 42);
|
|
@@ -21,7 +21,7 @@ describe("Encode/Decode command stream tester", () => {
|
|
|
21
21
|
expect(decoded.value).toBe(byte);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it("should encode and decode a Int32",
|
|
24
|
+
it("should encode and decode a Int32", () => {
|
|
25
25
|
const varint = 0xdeadbeef;
|
|
26
26
|
let buffer = new Uint8Array();
|
|
27
27
|
buffer = TLV.pushInt32(buffer, varint);
|
|
@@ -29,7 +29,7 @@ describe("Encode/Decode command stream tester", () => {
|
|
|
29
29
|
expect(decoded.value).toBe(varint);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
it("should encode and decode a string",
|
|
32
|
+
it("should encode and decode a string", () => {
|
|
33
33
|
const str = "Hello World";
|
|
34
34
|
let buffer = new Uint8Array();
|
|
35
35
|
buffer = TLV.pushString(buffer, str);
|
|
@@ -37,15 +37,15 @@ describe("Encode/Decode command stream tester", () => {
|
|
|
37
37
|
expect(decoded.value).toBe(str);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
it("should encode and decode a hash",
|
|
41
|
-
const hash =
|
|
40
|
+
it("should encode and decode a hash", () => {
|
|
41
|
+
const hash = crypto.hash(new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));
|
|
42
42
|
let buffer = new Uint8Array();
|
|
43
43
|
buffer = TLV.pushHash(buffer, hash);
|
|
44
44
|
const decoded = TLV.readHash(TLV.readTLV(buffer, 0));
|
|
45
45
|
expect(crypto.to_hex(decoded.value)).toEqual(crypto.to_hex(hash));
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it("should encode and decode bytes",
|
|
48
|
+
it("should encode and decode bytes", () => {
|
|
49
49
|
const bytes = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
50
50
|
let buffer = new Uint8Array();
|
|
51
51
|
buffer = TLV.pushBytes(buffer, bytes);
|
|
@@ -53,10 +53,10 @@ describe("Encode/Decode command stream tester", () => {
|
|
|
53
53
|
expect(decoded.value).toEqual(bytes);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
it("should encode and decode a signature",
|
|
57
|
-
const alice =
|
|
58
|
-
const block =
|
|
59
|
-
|
|
56
|
+
it("should encode and decode a signature", () => {
|
|
57
|
+
const alice = crypto.randomKeypair();
|
|
58
|
+
const block = signCommandBlock(
|
|
59
|
+
createCommandBlock(alice.publicKey, []),
|
|
60
60
|
alice.publicKey,
|
|
61
61
|
alice.privateKey,
|
|
62
62
|
);
|
|
@@ -66,28 +66,28 @@ describe("Encode/Decode command stream tester", () => {
|
|
|
66
66
|
expect(decoded.value).toEqual(block.signature);
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
it("should encode and decode a public key",
|
|
70
|
-
const alice =
|
|
69
|
+
it("should encode and decode a public key", () => {
|
|
70
|
+
const alice = crypto.randomKeypair();
|
|
71
71
|
let buffer = new Uint8Array();
|
|
72
72
|
buffer = TLV.pushPublicKey(buffer, alice.publicKey);
|
|
73
73
|
const decoded = TLV.readPublicKey(TLV.readTLV(buffer, 0));
|
|
74
74
|
expect(decoded.value).toEqual(alice.publicKey);
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
it("should encode and decode a stream. Encoding/Decoding should not alter the stream",
|
|
78
|
-
const alice =
|
|
79
|
-
const groupPk =
|
|
80
|
-
const groupChainCode =
|
|
77
|
+
it("should encode and decode a stream. Encoding/Decoding should not alter the stream", () => {
|
|
78
|
+
const alice = crypto.randomKeypair();
|
|
79
|
+
const groupPk = crypto.randomKeypair();
|
|
80
|
+
const groupChainCode = crypto.randomBytes(32);
|
|
81
81
|
const xpriv = new Uint8Array(64);
|
|
82
|
-
const initializationVector =
|
|
82
|
+
const initializationVector = crypto.randomBytes(16);
|
|
83
83
|
xpriv.set(groupPk.privateKey);
|
|
84
84
|
xpriv.set(groupChainCode, 32);
|
|
85
|
-
const ephemeralPk =
|
|
85
|
+
const ephemeralPk = crypto.randomKeypair();
|
|
86
86
|
|
|
87
|
-
const block1 =
|
|
88
|
-
|
|
87
|
+
const block1 = signCommandBlock(
|
|
88
|
+
createCommandBlock(alice.publicKey, [
|
|
89
89
|
new Seed(
|
|
90
|
-
|
|
90
|
+
crypto.randomBytes(16),
|
|
91
91
|
0,
|
|
92
92
|
groupPk.publicKey,
|
|
93
93
|
initializationVector,
|
|
@@ -99,21 +99,21 @@ describe("Encode/Decode command stream tester", () => {
|
|
|
99
99
|
alice.privateKey,
|
|
100
100
|
);
|
|
101
101
|
|
|
102
|
-
const block2 =
|
|
103
|
-
|
|
104
|
-
new AddMember("Alice",
|
|
102
|
+
const block2 = signCommandBlock(
|
|
103
|
+
createCommandBlock(alice.publicKey, [
|
|
104
|
+
new AddMember("Alice", crypto.randomBytes(32), Permissions.OWNER),
|
|
105
105
|
new PublishKey(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
crypto.randomBytes(16),
|
|
107
|
+
crypto.randomBytes(32),
|
|
108
|
+
crypto.randomBytes(32),
|
|
109
|
+
crypto.randomBytes(32),
|
|
110
110
|
),
|
|
111
111
|
]),
|
|
112
112
|
alice.publicKey,
|
|
113
113
|
alice.privateKey,
|
|
114
114
|
);
|
|
115
|
-
const block3 =
|
|
116
|
-
|
|
115
|
+
const block3 = signCommandBlock(
|
|
116
|
+
createCommandBlock(alice.publicKey, []),
|
|
117
117
|
alice.publicKey,
|
|
118
118
|
alice.privateKey,
|
|
119
119
|
);
|
|
@@ -121,11 +121,11 @@ describe("Encode/Decode command stream tester", () => {
|
|
|
121
121
|
const stream = [block1, block2, block3];
|
|
122
122
|
|
|
123
123
|
const encoded = CommandStreamEncoder.encode(stream);
|
|
124
|
-
const digestEncoded =
|
|
124
|
+
const digestEncoded = crypto.hash(encoded);
|
|
125
125
|
|
|
126
126
|
const decoded = CommandStreamDecoder.decode(encoded);
|
|
127
127
|
const reencoded = CommandStreamEncoder.encode(decoded);
|
|
128
|
-
const digestReencoded =
|
|
128
|
+
const digestReencoded = crypto.hash(reencoded);
|
|
129
129
|
expect(digestEncoded).toEqual(digestReencoded);
|
|
130
130
|
});
|
|
131
131
|
|