@bsv/wallet-toolbox 2.4.21 → 2.5.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 (83) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +56 -1
  3. package/docs/authentication-observability.md +21 -9
  4. package/out/src/CWIStyleWalletManager.d.ts +31 -3
  5. package/out/src/CWIStyleWalletManager.d.ts.map +1 -1
  6. package/out/src/CWIStyleWalletManager.js +164 -56
  7. package/out/src/CWIStyleWalletManager.js.map +1 -1
  8. package/out/src/Wallet.d.ts +3 -3
  9. package/out/src/Wallet.d.ts.map +1 -1
  10. package/out/src/Wallet.js +45 -6
  11. package/out/src/Wallet.js.map +1 -1
  12. package/out/src/sdk/WalletStorage.interfaces.d.ts +1 -0
  13. package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
  14. package/out/src/signer/methods/completeSignedTransaction.d.ts.map +1 -1
  15. package/out/src/signer/methods/completeSignedTransaction.js +54 -13
  16. package/out/src/signer/methods/completeSignedTransaction.js.map +1 -1
  17. package/out/src/signer/methods/createAction.d.ts.map +1 -1
  18. package/out/src/signer/methods/createAction.js +14 -10
  19. package/out/src/signer/methods/createAction.js.map +1 -1
  20. package/out/src/signer/methods/verifyUnlockScripts.d.ts.map +1 -1
  21. package/out/src/signer/methods/verifyUnlockScripts.js +257 -21
  22. package/out/src/signer/methods/verifyUnlockScripts.js.map +1 -1
  23. package/out/src/storage/StorageIdb.d.ts +14 -1
  24. package/out/src/storage/StorageIdb.d.ts.map +1 -1
  25. package/out/src/storage/StorageIdb.js +128 -17
  26. package/out/src/storage/StorageIdb.js.map +1 -1
  27. package/out/src/storage/StorageKnex.d.ts +11 -2
  28. package/out/src/storage/StorageKnex.d.ts.map +1 -1
  29. package/out/src/storage/StorageKnex.js +196 -5
  30. package/out/src/storage/StorageKnex.js.map +1 -1
  31. package/out/src/storage/StorageProvider.d.ts +30 -1
  32. package/out/src/storage/StorageProvider.d.ts.map +1 -1
  33. package/out/src/storage/StorageProvider.js +94 -2
  34. package/out/src/storage/StorageProvider.js.map +1 -1
  35. package/out/src/storage/idbHelpers.d.ts.map +1 -1
  36. package/out/src/storage/idbHelpers.js +2 -0
  37. package/out/src/storage/idbHelpers.js.map +1 -1
  38. package/out/src/storage/methods/actionBatch.d.ts.map +1 -1
  39. package/out/src/storage/methods/actionBatch.js +2 -14
  40. package/out/src/storage/methods/actionBatch.js.map +1 -1
  41. package/out/src/storage/methods/actionPlanning.d.ts +14 -0
  42. package/out/src/storage/methods/actionPlanning.d.ts.map +1 -1
  43. package/out/src/storage/methods/actionPlanning.js +55 -0
  44. package/out/src/storage/methods/actionPlanning.js.map +1 -1
  45. package/out/src/storage/methods/availableManagedChange.d.ts +11 -0
  46. package/out/src/storage/methods/availableManagedChange.d.ts.map +1 -0
  47. package/out/src/storage/methods/availableManagedChange.js +25 -0
  48. package/out/src/storage/methods/availableManagedChange.js.map +1 -0
  49. package/out/src/storage/methods/createAction.d.ts.map +1 -1
  50. package/out/src/storage/methods/createAction.js +521 -173
  51. package/out/src/storage/methods/createAction.js.map +1 -1
  52. package/out/src/storage/methods/generateChange.d.ts.map +1 -1
  53. package/out/src/storage/methods/generateChange.js +29 -14
  54. package/out/src/storage/methods/generateChange.js.map +1 -1
  55. package/out/src/storage/methods/getBeefForTransaction.d.ts +7 -0
  56. package/out/src/storage/methods/getBeefForTransaction.d.ts.map +1 -1
  57. package/out/src/storage/methods/getBeefForTransaction.js +219 -20
  58. package/out/src/storage/methods/getBeefForTransaction.js.map +1 -1
  59. package/out/src/storage/methods/processAction.d.ts.map +1 -1
  60. package/out/src/storage/methods/processAction.js +36 -15
  61. package/out/src/storage/methods/processAction.js.map +1 -1
  62. package/out/src/storage/remoting/KnexSessionManager.d.ts +20 -0
  63. package/out/src/storage/remoting/KnexSessionManager.d.ts.map +1 -1
  64. package/out/src/storage/remoting/KnexSessionManager.js +74 -16
  65. package/out/src/storage/remoting/KnexSessionManager.js.map +1 -1
  66. package/out/src/storage/schema/KnexMigrations.d.ts +1 -0
  67. package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -1
  68. package/out/src/storage/schema/KnexMigrations.js +39 -1
  69. package/out/src/storage/schema/KnexMigrations.js.map +1 -1
  70. package/out/src/storage/schema/StorageIdbSchema.d.ts +2 -0
  71. package/out/src/storage/schema/StorageIdbSchema.d.ts.map +1 -1
  72. package/out/src/storage/schema/entities/EntityProvenTx.d.ts +2 -1
  73. package/out/src/storage/schema/entities/EntityProvenTx.d.ts.map +1 -1
  74. package/out/src/storage/schema/entities/EntityProvenTx.js +8 -3
  75. package/out/src/storage/schema/entities/EntityProvenTx.js.map +1 -1
  76. package/out/src/storage/storageProviderHelpers.d.ts.map +1 -1
  77. package/out/src/storage/storageProviderHelpers.js +8 -2
  78. package/out/src/storage/storageProviderHelpers.js.map +1 -1
  79. package/out/src/utility/ScriptTemplateBRC29.d.ts +3 -2
  80. package/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -1
  81. package/out/src/utility/ScriptTemplateBRC29.js +13 -5
  82. package/out/src/utility/ScriptTemplateBRC29.js.map +1 -1
  83. package/package.json +5 -2
@@ -1,4 +1,4 @@
1
- import { HexString, KeyDeriverApi, WalletProtocol, ScriptTemplate, ScriptTemplateUnlock, LockingScript, P2PKH, PrivateKey, Script } from '@bsv/sdk';
1
+ import { HexString, KeyDeriverApi, WalletProtocol, ScriptTemplate, ScriptTemplateUnlock, LockingScript, P2PKH, PrivateKey, PublicKey, Script } from '@bsv/sdk';
2
2
  export declare const brc29ProtocolID: WalletProtocol;
3
3
  export interface ScriptTemplateParamsBRC29 {
4
4
  derivationPrefix?: string;
@@ -16,7 +16,8 @@ export declare class ScriptTemplateBRC29 implements ScriptTemplate {
16
16
  getKeyID(): string;
17
17
  getKeyDeriver(privKey: PrivateKey | HexString): KeyDeriverApi;
18
18
  lock(lockerPrivKey: string, unlockerPubKey: string): LockingScript;
19
- unlock(unlockerPrivKey: string, lockerPubKey: string, sourceSatoshis?: number, lockingScript?: Script): ScriptTemplateUnlock;
19
+ unlock(unlockerPrivKey: PrivateKey | HexString, lockerPubKey: PublicKey | string, sourceSatoshis?: number, lockingScript?: Script): ScriptTemplateUnlock;
20
+ unlockWithDerivedPrivateKey(derivedPrivateKey: PrivateKey, sourceSatoshis?: number, lockingScript?: Script): ScriptTemplateUnlock;
20
21
  /**
21
22
  * P2PKH unlock estimateLength is a constant
22
23
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ScriptTemplateBRC29.d.ts","sourceRoot":"","sources":["../../../src/utility/ScriptTemplateBRC29.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,aAAa,EACb,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,KAAK,EACL,UAAU,EACV,MAAM,EAEP,MAAM,UAAU,CAAA;AAGjB,eAAO,MAAM,eAAe,EAAE,cAAoC,CAAA;AAElE,MAAM,WAAW,yBAAyB;IACxC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,UAAU,EAAE,aAAa,CAAA;CAC1B;AAED;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,cAAc;IAGpC,MAAM,EAAE,yBAAyB;IAFrD,KAAK,EAAE,KAAK,CAAA;IAEZ,YAAoB,MAAM,EAAE,yBAAyB,EAKpD;IAED,QAAQ,IAAK,MAAM,CAElB;IAED,aAAa,CAAE,OAAO,EAAE,UAAU,GAAG,SAAS,GAAG,aAAa,CAI7D;IAED,IAAI,CAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,aAAa,CAMlE;IAED,MAAM,CACJ,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,cAAc,CAAC,EAAE,MAAM,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB,oBAAoB,CAMtB;IAED;;OAEG;IACH,YAAY,SAAM;CACnB"}
1
+ {"version":3,"file":"ScriptTemplateBRC29.d.ts","sourceRoot":"","sources":["../../../src/utility/ScriptTemplateBRC29.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,aAAa,EACb,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,KAAK,EACL,UAAU,EACV,SAAS,EACT,MAAM,EAEP,MAAM,UAAU,CAAA;AAGjB,eAAO,MAAM,eAAe,EAAE,cAAoC,CAAA;AAElE,MAAM,WAAW,yBAAyB;IACxC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,UAAU,EAAE,aAAa,CAAA;CAC1B;AAED;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,cAAc;IAGpC,MAAM,EAAE,yBAAyB;IAFrD,KAAK,EAAE,KAAK,CAAA;IAEZ,YAAoB,MAAM,EAAE,yBAAyB,EAKpD;IAED,QAAQ,IAAK,MAAM,CAElB;IAED,aAAa,CAAE,OAAO,EAAE,UAAU,GAAG,SAAS,GAAG,aAAa,CAU7D;IAED,IAAI,CAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,aAAa,CAMlE;IAED,MAAM,CACJ,eAAe,EAAE,UAAU,GAAG,SAAS,EACvC,YAAY,EAAE,SAAS,GAAG,MAAM,EAChC,cAAc,CAAC,EAAE,MAAM,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB,oBAAoB,CAItB;IAED,2BAA2B,CACzB,iBAAiB,EAAE,UAAU,EAC7B,cAAc,CAAC,EAAE,MAAM,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB,oBAAoB,CAEtB;IAED;;OAEG;IACH,YAAY,SAAM;CACnB"}
@@ -21,8 +21,15 @@ class ScriptTemplateBRC29 {
21
21
  return `${this.params.derivationPrefix ?? ''} ${this.params.derivationSuffix ?? ''}`;
22
22
  }
23
23
  getKeyDeriver(privKey) {
24
- if (typeof privKey === 'string')
24
+ if (this.params.keyDeriver?.rootKey === privKey)
25
+ return this.params.keyDeriver;
26
+ if (typeof privKey === 'string') {
27
+ // The wallet signing path supplies its existing root key on every input.
28
+ // Avoid parsing the same hex key into a BigNumber for each template.
29
+ if (this.params.keyDeriver?.rootKey.toHex() === privKey)
30
+ return this.params.keyDeriver;
25
31
  privKey = sdk_1.PrivateKey.fromHex(privKey);
32
+ }
26
33
  if (this.params.keyDeriver == null || this.params.keyDeriver.rootKey.toHex() !== privKey.toHex()) {
27
34
  return new sdk_1.CachedKeyDeriver(privKey);
28
35
  }
@@ -37,10 +44,11 @@ class ScriptTemplateBRC29 {
37
44
  }
38
45
  unlock(unlockerPrivKey, lockerPubKey, sourceSatoshis, lockingScript) {
39
46
  const derivedPrivateKey = this.getKeyDeriver(unlockerPrivKey)
40
- .derivePrivateKey(exports.brc29ProtocolID, this.getKeyID(), lockerPubKey)
41
- .toHex();
42
- const r = this.p2pkh.unlock((0, utilityHelpers_1.asBsvSdkPrivateKey)(derivedPrivateKey), 'all', false, sourceSatoshis, lockingScript);
43
- return r;
47
+ .derivePrivateKey(exports.brc29ProtocolID, this.getKeyID(), lockerPubKey);
48
+ return this.unlockWithDerivedPrivateKey(derivedPrivateKey, sourceSatoshis, lockingScript);
49
+ }
50
+ unlockWithDerivedPrivateKey(derivedPrivateKey, sourceSatoshis, lockingScript) {
51
+ return this.p2pkh.unlock(derivedPrivateKey, 'all', false, sourceSatoshis, lockingScript);
44
52
  }
45
53
  /**
46
54
  * P2PKH unlock estimateLength is a constant
@@ -1 +1 @@
1
- {"version":3,"file":"ScriptTemplateBRC29.js","sourceRoot":"","sources":["../../../src/utility/ScriptTemplateBRC29.ts"],"names":[],"mappings":";;;AAAA,kCAWiB;AACjB,qDAAmE;AAEtD,QAAA,eAAe,GAAmB,CAAC,CAAC,EAAE,cAAc,CAAC,CAAA;AAQlE;;;GAGG;AACH;IAGsB,MAAM;IAF1B,KAAK,CAAO;IAEZ,YAAoB,MAAiC;sBAAjC,MAAM;QACxB,IAAI,CAAC,KAAK,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AAA;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/wallet-toolbox",
3
- "version": "2.4.21",
3
+ "version": "2.5.0",
4
4
  "sideEffects": false,
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -69,7 +69,8 @@
69
69
  "ws": "^8.21.1"
70
70
  },
71
71
  "devDependencies": {
72
- "@bsv/sdk": "^2.2.17",
72
+ "@bsv/sdk": "^2.3.0",
73
+ "@bsv/verifast": "^0.3.4",
73
74
  "@jest/globals": "^30.4.1",
74
75
  "@types/body-parser": "^1.19.6",
75
76
  "@types/cors": "^2.8.19",
@@ -108,6 +109,8 @@
108
109
  "operator:build": "pnpm build && tsc --project operator/tsconfig.json --pretty false",
109
110
  "operator": "pnpm operator:build && node .operator-build/cli.js",
110
111
  "bench:action-batch": "pnpm build && jest --runInBand --runTestsByPath benchmarks/action-batch.bench.test.ts --testPathIgnorePatterns=man.test.ts",
112
+ "bench:create-action-funding": "pnpm build && jest --runInBand --runTestsByPath benchmarks/create-action-funding.bench.test.ts --testPathIgnorePatterns=man.test.ts",
113
+ "bench:create-action-beef": "pnpm build && jest --runInBand --runTestsByPath benchmarks/create-action-beef.bench.test.ts --testPathIgnorePatterns=man.test.ts",
111
114
  "format:check": "pnpm --workspace-root exec prettier --check \"packages/wallet/wallet-toolbox/{README.md,jest.config.cjs,package.json,tsconfig*.json}\"",
112
115
  "lint": "oxlint src test benchmarks examples operator --deny-warnings",
113
116
  "lint:ci": "pnpm lint",