@ledgerhq/ledger-key-ring-protocol 0.5.1-nightly.0 → 0.5.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 +6 -6
- package/lib/qrcode/cipher.d.ts +4 -4
- package/lib/qrcode/cipher.d.ts.map +1 -1
- package/lib/qrcode/cipher.js +26 -43
- package/lib/qrcode/cipher.js.map +1 -1
- package/lib/qrcode/cipher.test.js +16 -25
- package/lib/qrcode/cipher.test.js.map +1 -1
- package/lib/qrcode/index.d.ts.map +1 -1
- package/lib/qrcode/index.js +23 -26
- package/lib/qrcode/index.js.map +1 -1
- package/lib/sdk.js +1 -1
- package/lib/sdk.js.map +1 -1
- package/lib-es/qrcode/cipher.d.ts +4 -4
- package/lib-es/qrcode/cipher.d.ts.map +1 -1
- package/lib-es/qrcode/cipher.js +26 -43
- package/lib-es/qrcode/cipher.js.map +1 -1
- package/lib-es/qrcode/cipher.test.js +16 -25
- package/lib-es/qrcode/cipher.test.js.map +1 -1
- package/lib-es/qrcode/index.d.ts.map +1 -1
- package/lib-es/qrcode/index.js +23 -26
- package/lib-es/qrcode/index.js.map +1 -1
- package/lib-es/sdk.js +1 -1
- package/lib-es/sdk.js.map +1 -1
- package/package.json +5 -5
- package/src/qrcode/cipher.test.ts +14 -14
- package/src/qrcode/cipher.ts +14 -16
- package/src/qrcode/index.ts +19 -20
- package/src/sdk.ts +1 -1
- package/tests/test-helpers/recordTrustchainSdkTests.ts +4 -4
- package/tests/test-helpers/replayTrustchainSdkTests.ts +1 -1
package/src/qrcode/index.ts
CHANGED
|
@@ -45,9 +45,9 @@ const commonSwitch = async ({
|
|
|
45
45
|
if (!cipher) {
|
|
46
46
|
throw new Error("sessionEncryptionKey not set");
|
|
47
47
|
}
|
|
48
|
-
const { id, name } =
|
|
48
|
+
const { id, name } = cipher.decryptMessage(data);
|
|
49
49
|
const trustchain = await addMember({ id, name, permissions: Permissions.OWNER });
|
|
50
|
-
const payload =
|
|
50
|
+
const payload = cipher.encryptMessagePayload({ trustchain });
|
|
51
51
|
send({ version, publisher, message: "TrustchainAddedMember", payload });
|
|
52
52
|
resolve();
|
|
53
53
|
break;
|
|
@@ -62,7 +62,7 @@ const commonSwitch = async ({
|
|
|
62
62
|
send({ version, publisher, message: "Failure", payload });
|
|
63
63
|
throw new TrustchainAlreadyInitialized(initialTrustchainId);
|
|
64
64
|
}
|
|
65
|
-
const payload =
|
|
65
|
+
const payload = cipher.encryptMessagePayload({
|
|
66
66
|
id: memberCredentials.pubkey,
|
|
67
67
|
name: memberName,
|
|
68
68
|
});
|
|
@@ -71,7 +71,7 @@ const commonSwitch = async ({
|
|
|
71
71
|
}
|
|
72
72
|
case "TrustchainAddedMember": {
|
|
73
73
|
setFinished(true);
|
|
74
|
-
const { trustchain } =
|
|
74
|
+
const { trustchain } = cipher.decryptMessage(data);
|
|
75
75
|
resolve(trustchain);
|
|
76
76
|
ws.close();
|
|
77
77
|
break;
|
|
@@ -136,7 +136,7 @@ export async function createQRCodeHostInstance({
|
|
|
136
136
|
*/
|
|
137
137
|
initialTrustchainId?: string;
|
|
138
138
|
}): Promise<Trustchain | void> {
|
|
139
|
-
const ephemeralKey =
|
|
139
|
+
const ephemeralKey = crypto.randomKeypair();
|
|
140
140
|
const publisher = crypto.to_hex(ephemeralKey.publicKey);
|
|
141
141
|
const url = `${trustchainApiBaseUrl.replace("http", "ws")}/v1/qr?host=${publisher}`;
|
|
142
142
|
const ws = new WebSocket(url);
|
|
@@ -167,14 +167,14 @@ export async function createQRCodeHostInstance({
|
|
|
167
167
|
switch (data.message) {
|
|
168
168
|
case "InitiateHandshake": {
|
|
169
169
|
const candidatePublicKey = crypto.from_hex(data.payload.ephemeral_public_key);
|
|
170
|
-
sessionEncryptionKey =
|
|
170
|
+
sessionEncryptionKey = crypto.ecdh(ephemeralKey, candidatePublicKey);
|
|
171
171
|
cipher = makeMessageCipher(makeCipher(sessionEncryptionKey));
|
|
172
172
|
// --- end of handshake first phase ---
|
|
173
173
|
const digitsCount = 3;
|
|
174
|
-
const digits =
|
|
174
|
+
const digits = randomDigits(digitsCount);
|
|
175
175
|
expectedDigits = digits;
|
|
176
176
|
onDisplayDigits(digits);
|
|
177
|
-
const payload =
|
|
177
|
+
const payload = cipher.encryptMessagePayload({
|
|
178
178
|
digits: digitsCount,
|
|
179
179
|
connected: false,
|
|
180
180
|
});
|
|
@@ -185,7 +185,7 @@ export async function createQRCodeHostInstance({
|
|
|
185
185
|
if (!cipher) {
|
|
186
186
|
throw new Error("sessionEncryptionKey not set");
|
|
187
187
|
}
|
|
188
|
-
const { digits } =
|
|
188
|
+
const { digits } = cipher.decryptMessage(data);
|
|
189
189
|
if (digits !== expectedDigits) {
|
|
190
190
|
console.warn("User invalid digits", { digits, expectedDigits });
|
|
191
191
|
const payload = {
|
|
@@ -195,7 +195,7 @@ export async function createQRCodeHostInstance({
|
|
|
195
195
|
send({ version, publisher, message: "Failure", payload });
|
|
196
196
|
throw new InvalidDigitsError("invalid digits");
|
|
197
197
|
}
|
|
198
|
-
const payload =
|
|
198
|
+
const payload = cipher.encryptMessagePayload({});
|
|
199
199
|
send({ version, publisher, message: "HandshakeCompletionSucceeded", payload });
|
|
200
200
|
break;
|
|
201
201
|
}
|
|
@@ -273,9 +273,9 @@ export async function createQRCodeCandidateInstance({
|
|
|
273
273
|
throw new ScannedInvalidQrCode();
|
|
274
274
|
}
|
|
275
275
|
const hostPublicKey = crypto.from_hex(m[1]);
|
|
276
|
-
const ephemeralKey =
|
|
276
|
+
const ephemeralKey = crypto.randomKeypair();
|
|
277
277
|
const publisher = crypto.to_hex(ephemeralKey.publicKey);
|
|
278
|
-
const sessionEncryptionKey =
|
|
278
|
+
const sessionEncryptionKey = crypto.ecdh(ephemeralKey, hostPublicKey);
|
|
279
279
|
const cipher = makeMessageCipher(makeCipher(sessionEncryptionKey));
|
|
280
280
|
const ws = new WebSocket(scannedUrl);
|
|
281
281
|
function send(message: Message) {
|
|
@@ -296,20 +296,19 @@ export async function createQRCodeCandidateInstance({
|
|
|
296
296
|
const data = parseMessage(e.data);
|
|
297
297
|
switch (data.message) {
|
|
298
298
|
case "HandshakeChallenge": {
|
|
299
|
-
const config =
|
|
299
|
+
const config = cipher.decryptMessage(data);
|
|
300
300
|
onRequestQRCodeInput(config, digits => {
|
|
301
|
-
cipher.encryptMessagePayload({ digits })
|
|
302
|
-
|
|
303
|
-
});
|
|
301
|
+
const payload = cipher.encryptMessagePayload({ digits });
|
|
302
|
+
send({ version, publisher, message: "CompleteHandshakeChallenge", payload });
|
|
304
303
|
});
|
|
305
304
|
break;
|
|
306
305
|
}
|
|
307
306
|
case "HandshakeCompletionSucceeded": {
|
|
308
307
|
if (initialTrustchainId) {
|
|
309
|
-
const payload =
|
|
308
|
+
const payload = cipher.encryptMessagePayload({});
|
|
310
309
|
send({ version, publisher, message: "TrustchainRequestCredential", payload });
|
|
311
310
|
} else {
|
|
312
|
-
const payload =
|
|
311
|
+
const payload = cipher.encryptMessagePayload({
|
|
313
312
|
id: memberCredentials.pubkey,
|
|
314
313
|
name: memberName,
|
|
315
314
|
});
|
|
@@ -346,8 +345,8 @@ export async function createQRCodeCandidateInstance({
|
|
|
346
345
|
});
|
|
347
346
|
}
|
|
348
347
|
|
|
349
|
-
|
|
350
|
-
const bytes =
|
|
348
|
+
function randomDigits(count: number) {
|
|
349
|
+
const bytes = crypto.randomBytes(count);
|
|
351
350
|
let digits = "";
|
|
352
351
|
for (let i = 0; i < count; i++) {
|
|
353
352
|
digits += (bytes[i] % 10).toString();
|
package/src/sdk.ts
CHANGED
|
@@ -94,8 +94,8 @@ export async function recordTestTrustchainSdk(
|
|
|
94
94
|
// Monkey patches the `crypto.randomBytes` method to log generated random bytes in hexadecimal format in order to deterministically replay them in unit tests.
|
|
95
95
|
const randomBytesOutputs: string[] = [];
|
|
96
96
|
const originalRandomBytes = crypto.randomBytes;
|
|
97
|
-
crypto.randomBytes =
|
|
98
|
-
const bytes =
|
|
97
|
+
crypto.randomBytes = (size: number) => {
|
|
98
|
+
const bytes = originalRandomBytes.call(crypto, size);
|
|
99
99
|
randomBytesOutputs.push(crypto.to_hex(bytes));
|
|
100
100
|
return bytes;
|
|
101
101
|
};
|
|
@@ -103,8 +103,8 @@ export async function recordTestTrustchainSdk(
|
|
|
103
103
|
// Monkey patches the `crypto.randomKeypair` method to log generated random keypairs in hexadecimal format in order to deterministically replay them in unit tests.
|
|
104
104
|
const randomKeypairOutputs: string[] = [];
|
|
105
105
|
const originalRandomKeypair = crypto.randomKeypair;
|
|
106
|
-
crypto.randomKeypair =
|
|
107
|
-
const keypair =
|
|
106
|
+
crypto.randomKeypair = () => {
|
|
107
|
+
const keypair = originalRandomKeypair.call(crypto);
|
|
108
108
|
randomKeypairOutputs.push(crypto.to_hex(keypair.privateKey));
|
|
109
109
|
return keypair;
|
|
110
110
|
};
|
|
@@ -69,7 +69,7 @@ export async function replayTrustchainSdkTests<Json extends JsonShape>(
|
|
|
69
69
|
if (bytes.length !== size) {
|
|
70
70
|
throw new Error("unexpected randomBytes size. Expected " + size + " but got " + bytes.length);
|
|
71
71
|
}
|
|
72
|
-
return
|
|
72
|
+
return bytes;
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
const recordStore = RecordStore.fromString(json.apdus);
|