@did-btcr2/cli 0.25.2 → 0.27.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.
Files changed (37) hide show
  1. package/README.md +2 -2
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/cjs/index.js +39 -21
  4. package/dist/esm/bin/btcr2.js +10 -1
  5. package/dist/esm/bin/btcr2.js.map +1 -1
  6. package/dist/esm/src/cli.js +1 -2
  7. package/dist/esm/src/cli.js.map +1 -1
  8. package/dist/esm/src/commands/create.js +29 -22
  9. package/dist/esm/src/commands/create.js.map +1 -1
  10. package/dist/esm/src/commands/write.js +4 -2
  11. package/dist/esm/src/commands/write.js.map +1 -1
  12. package/dist/esm/src/config.js +9 -7
  13. package/dist/esm/src/config.js.map +1 -1
  14. package/dist/esm/src/keystore/envelope.js +17 -2
  15. package/dist/esm/src/keystore/envelope.js.map +1 -1
  16. package/dist/esm/src/keystore/file-key-store.js +7 -3
  17. package/dist/esm/src/keystore/file-key-store.js.map +1 -1
  18. package/dist/types/src/cli.d.ts.map +1 -1
  19. package/dist/types/src/commands/create.d.ts +9 -8
  20. package/dist/types/src/commands/create.d.ts.map +1 -1
  21. package/dist/types/src/commands/write.d.ts +1 -0
  22. package/dist/types/src/commands/write.d.ts.map +1 -1
  23. package/dist/types/src/config.d.ts +7 -7
  24. package/dist/types/src/config.d.ts.map +1 -1
  25. package/dist/types/src/keystore/envelope.d.ts +6 -0
  26. package/dist/types/src/keystore/envelope.d.ts.map +1 -1
  27. package/dist/types/src/keystore/file-key-store.d.ts.map +1 -1
  28. package/dist/types/src/types.d.ts +0 -1
  29. package/dist/types/src/types.d.ts.map +1 -1
  30. package/package.json +4 -4
  31. package/src/cli.ts +1 -2
  32. package/src/commands/create.ts +33 -23
  33. package/src/commands/write.ts +8 -2
  34. package/src/config.ts +8 -8
  35. package/src/keystore/envelope.ts +18 -2
  36. package/src/keystore/file-key-store.ts +6 -3
  37. package/src/types.ts +0 -1
@@ -1,7 +1,7 @@
1
1
  import { xchacha20poly1305 } from '@noble/ciphers/chacha.js';
2
- import { argon2id } from '@noble/hashes/argon2.js';
3
2
  import { randomBytes, utf8ToBytes } from '@noble/hashes/utils.js';
4
3
  import { base64urlnopad } from '@scure/base';
4
+ import { argon2Sync } from 'node:crypto';
5
5
  import { KeyStoreError } from './error.js';
6
6
 
7
7
  /** Current keystore secret-envelope format version. */
@@ -81,6 +81,22 @@ function headerAad(header: EnvelopeHeader): Uint8Array {
81
81
  return utf8ToBytes(JSON.stringify(header));
82
82
  }
83
83
 
84
+ /**
85
+ * Runs argon2id over a password with the native argon2 of Node.js (ADR 126).
86
+ * The output is the same as the output of `argon2id` from `@noble/hashes`, which
87
+ * sealed the envelopes of cli 0.25 and earlier. A test holds the two equal.
88
+ */
89
+ export function argon2idKey(password: Uint8Array, salt: Uint8Array, params: ArgonParams): Uint8Array {
90
+ return argon2Sync('argon2id', {
91
+ message : password,
92
+ nonce : salt,
93
+ parallelism : params.p,
94
+ tagLength : params.dkLen,
95
+ memory : params.m,
96
+ passes : params.t,
97
+ });
98
+ }
99
+
84
100
  /**
85
101
  * Stretches a passphrase into the symmetric key. The transient UTF-8 copy of
86
102
  * the passphrase is zeroized here; the caller is responsible for zeroizing the
@@ -89,7 +105,7 @@ function headerAad(header: EnvelopeHeader): Uint8Array {
89
105
  function deriveKey(passphrase: string, salt: Uint8Array, params: ArgonParams): Uint8Array {
90
106
  const password = utf8ToBytes(passphrase);
91
107
  try {
92
- return argon2id(password, salt, { t: params.t, m: params.m, p: params.p, dkLen: params.dkLen });
108
+ return argon2idKey(password, salt, params);
93
109
  } finally {
94
110
  password.fill(0);
95
111
  }
@@ -456,8 +456,7 @@ export class FileKeyStore implements KeyValueStore<KeyIdentifier, KeyEntry> {
456
456
  } else if (this.#verifier !== undefined && passphrase !== undefined) {
457
457
  // A verifier exists: it pre-existed, was established concurrently while we
458
458
  // sealed, or was rotated by a concurrent change-passphrase. If it was
459
- // rotated out from under our seal, abort with a clear message; otherwise
460
- // assert our passphrase still opens it before persisting the key.
459
+ // rotated out from under our seal, abort with a clear message.
461
460
  if (verifierAtSeal !== undefined && !sameEnvelope(this.#verifier, verifierAtSeal)) {
462
461
  throw new KeyStoreError(
463
462
  `The keystore passphrase at ${this.#path} changed concurrently; re-run the command.`,
@@ -465,7 +464,11 @@ export class FileKeyStore implements KeyValueStore<KeyIdentifier, KeyEntry> {
465
464
  { path: this.#path },
466
465
  );
467
466
  }
468
- this.#assertPassphrase(passphrase);
467
+ // #sealPassphrase already checked the passphrase against verifierAtSeal,
468
+ // and the verifier on disk is the same envelope. A second argon2id call
469
+ // in the lock gives the same result, so only a verifier from a concurrent
470
+ // establishment gets a check here (ADR 126).
471
+ if (verifierAtSeal === undefined) this.#assertPassphrase(passphrase);
469
472
  }
470
473
  }
471
474
  this.#cache.set(id, {
package/src/types.ts CHANGED
@@ -146,5 +146,4 @@ export interface GlobalOptions {
146
146
  btcSignalDiscovery? : string;
147
147
  keystore? : string;
148
148
  passphraseFile? : string;
149
- signingKey? : string;
150
149
  }