@ledgerhq/ledger-key-ring-protocol 0.5.1-nightly.1 → 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.
@@ -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 } = await cipher.decryptMessage(data);
48
+ const { id, name } = cipher.decryptMessage(data);
49
49
  const trustchain = await addMember({ id, name, permissions: Permissions.OWNER });
50
- const payload = await cipher.encryptMessagePayload({ trustchain });
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 = await cipher.encryptMessagePayload({
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 } = await cipher.decryptMessage(data);
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 = await crypto.randomKeypair();
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 = await crypto.ecdh(ephemeralKey, candidatePublicKey);
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 = await randomDigits(digitsCount);
174
+ const digits = randomDigits(digitsCount);
175
175
  expectedDigits = digits;
176
176
  onDisplayDigits(digits);
177
- const payload = await cipher.encryptMessagePayload({
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 } = await cipher.decryptMessage(data);
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 = await cipher.encryptMessagePayload({});
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 = await crypto.randomKeypair();
276
+ const ephemeralKey = crypto.randomKeypair();
277
277
  const publisher = crypto.to_hex(ephemeralKey.publicKey);
278
- const sessionEncryptionKey = await crypto.ecdh(ephemeralKey, hostPublicKey);
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 = await cipher.decryptMessage(data);
299
+ const config = cipher.decryptMessage(data);
300
300
  onRequestQRCodeInput(config, digits => {
301
- cipher.encryptMessagePayload({ digits }).then(payload => {
302
- send({ version, publisher, message: "CompleteHandshakeChallenge", payload });
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 = await cipher.encryptMessagePayload({});
308
+ const payload = cipher.encryptMessagePayload({});
310
309
  send({ version, publisher, message: "TrustchainRequestCredential", payload });
311
310
  } else {
312
- const payload = await cipher.encryptMessagePayload({
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
- async function randomDigits(count: number): Promise<string> {
350
- const bytes = await crypto.randomBytes(count);
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
@@ -95,7 +95,7 @@ export class SDK implements TrustchainSDK {
95
95
  }
96
96
 
97
97
  async initMemberCredentials(): Promise<MemberCredentials> {
98
- const kp = await crypto.randomKeypair();
98
+ const kp = crypto.randomKeypair();
99
99
  return convertKeyPairToLiveCredentials(kp);
100
100
  }
101
101
 
@@ -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 = async (size: number) => {
98
- const bytes = await originalRandomBytes.call(crypto, size);
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 = async () => {
107
- const keypair = await originalRandomKeypair.call(crypto);
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 Promise.resolve(bytes);
72
+ return bytes;
73
73
  });
74
74
 
75
75
  const recordStore = RecordStore.fromString(json.apdus);