@bsv/wallet-toolbox 1.1.25 → 1.1.26

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 (123) hide show
  1. package/docs/client.md +78 -2313
  2. package/docs/wallet.md +78 -2313
  3. package/out/src/Wallet.d.ts +1 -6
  4. package/out/src/Wallet.d.ts.map +1 -1
  5. package/out/src/Wallet.js +2 -29
  6. package/out/src/Wallet.js.map +1 -1
  7. package/out/src/index.all.d.ts +0 -9
  8. package/out/src/index.all.d.ts.map +1 -1
  9. package/out/src/index.all.js +0 -9
  10. package/out/src/index.all.js.map +1 -1
  11. package/out/src/index.client.d.ts +0 -9
  12. package/out/src/index.client.d.ts.map +1 -1
  13. package/out/src/index.client.js +0 -9
  14. package/out/src/index.client.js.map +1 -1
  15. package/out/tsconfig.all.tsbuildinfo +1 -1
  16. package/package.json +3 -3
  17. package/src/Wallet.ts +3 -47
  18. package/src/index.all.ts +0 -9
  19. package/src/index.client.ts +0 -9
  20. package/out/src/CWIStyleWalletManager.d.ts +0 -411
  21. package/out/src/CWIStyleWalletManager.d.ts.map +0 -1
  22. package/out/src/CWIStyleWalletManager.js +0 -1131
  23. package/out/src/CWIStyleWalletManager.js.map +0 -1
  24. package/out/src/SetupClient.d.ts +0 -249
  25. package/out/src/SetupClient.d.ts.map +0 -1
  26. package/out/src/SetupClient.js +0 -252
  27. package/out/src/SetupClient.js.map +0 -1
  28. package/out/src/SimpleWalletManager.d.ts +0 -169
  29. package/out/src/SimpleWalletManager.d.ts.map +0 -1
  30. package/out/src/SimpleWalletManager.js +0 -315
  31. package/out/src/SimpleWalletManager.js.map +0 -1
  32. package/out/src/WalletAuthenticationManager.d.ts +0 -33
  33. package/out/src/WalletAuthenticationManager.d.ts.map +0 -1
  34. package/out/src/WalletAuthenticationManager.js +0 -107
  35. package/out/src/WalletAuthenticationManager.js.map +0 -1
  36. package/out/src/WalletPermissionsManager.d.ts +0 -575
  37. package/out/src/WalletPermissionsManager.d.ts.map +0 -1
  38. package/out/src/WalletPermissionsManager.js +0 -1807
  39. package/out/src/WalletPermissionsManager.js.map +0 -1
  40. package/out/src/WalletSettingsManager.d.ts +0 -59
  41. package/out/src/WalletSettingsManager.d.ts.map +0 -1
  42. package/out/src/WalletSettingsManager.js +0 -168
  43. package/out/src/WalletSettingsManager.js.map +0 -1
  44. package/out/src/__tests/CWIStyleWalletManager.test.d.ts +0 -2
  45. package/out/src/__tests/CWIStyleWalletManager.test.d.ts.map +0 -1
  46. package/out/src/__tests/CWIStyleWalletManager.test.js +0 -472
  47. package/out/src/__tests/CWIStyleWalletManager.test.js.map +0 -1
  48. package/out/src/__tests/WalletPermissionsManager.callbacks.test.d.ts +0 -2
  49. package/out/src/__tests/WalletPermissionsManager.callbacks.test.d.ts.map +0 -1
  50. package/out/src/__tests/WalletPermissionsManager.callbacks.test.js +0 -239
  51. package/out/src/__tests/WalletPermissionsManager.callbacks.test.js.map +0 -1
  52. package/out/src/__tests/WalletPermissionsManager.checks.test.d.ts +0 -2
  53. package/out/src/__tests/WalletPermissionsManager.checks.test.d.ts.map +0 -1
  54. package/out/src/__tests/WalletPermissionsManager.checks.test.js +0 -644
  55. package/out/src/__tests/WalletPermissionsManager.checks.test.js.map +0 -1
  56. package/out/src/__tests/WalletPermissionsManager.encryption.test.d.ts +0 -2
  57. package/out/src/__tests/WalletPermissionsManager.encryption.test.d.ts.map +0 -1
  58. package/out/src/__tests/WalletPermissionsManager.encryption.test.js +0 -295
  59. package/out/src/__tests/WalletPermissionsManager.encryption.test.js.map +0 -1
  60. package/out/src/__tests/WalletPermissionsManager.fixtures.d.ts +0 -82
  61. package/out/src/__tests/WalletPermissionsManager.fixtures.d.ts.map +0 -1
  62. package/out/src/__tests/WalletPermissionsManager.fixtures.js +0 -260
  63. package/out/src/__tests/WalletPermissionsManager.fixtures.js.map +0 -1
  64. package/out/src/__tests/WalletPermissionsManager.flows.test.d.ts +0 -2
  65. package/out/src/__tests/WalletPermissionsManager.flows.test.d.ts.map +0 -1
  66. package/out/src/__tests/WalletPermissionsManager.flows.test.js +0 -389
  67. package/out/src/__tests/WalletPermissionsManager.flows.test.js.map +0 -1
  68. package/out/src/__tests/WalletPermissionsManager.initialization.test.d.ts +0 -2
  69. package/out/src/__tests/WalletPermissionsManager.initialization.test.d.ts.map +0 -1
  70. package/out/src/__tests/WalletPermissionsManager.initialization.test.js +0 -227
  71. package/out/src/__tests/WalletPermissionsManager.initialization.test.js.map +0 -1
  72. package/out/src/__tests/WalletPermissionsManager.proxying.test.d.ts +0 -2
  73. package/out/src/__tests/WalletPermissionsManager.proxying.test.d.ts.map +0 -1
  74. package/out/src/__tests/WalletPermissionsManager.proxying.test.js +0 -566
  75. package/out/src/__tests/WalletPermissionsManager.proxying.test.js.map +0 -1
  76. package/out/src/__tests/WalletPermissionsManager.tokens.test.d.ts +0 -2
  77. package/out/src/__tests/WalletPermissionsManager.tokens.test.d.ts.map +0 -1
  78. package/out/src/__tests/WalletPermissionsManager.tokens.test.js +0 -460
  79. package/out/src/__tests/WalletPermissionsManager.tokens.test.js.map +0 -1
  80. package/out/src/utility/identityUtils.d.ts +0 -31
  81. package/out/src/utility/identityUtils.d.ts.map +0 -1
  82. package/out/src/utility/identityUtils.js +0 -114
  83. package/out/src/utility/identityUtils.js.map +0 -1
  84. package/out/src/wab-client/WABClient.d.ts +0 -38
  85. package/out/src/wab-client/WABClient.d.ts.map +0 -1
  86. package/out/src/wab-client/WABClient.js +0 -95
  87. package/out/src/wab-client/WABClient.js.map +0 -1
  88. package/out/src/wab-client/__tests/WABClient.test.d.ts +0 -2
  89. package/out/src/wab-client/__tests/WABClient.test.d.ts.map +0 -1
  90. package/out/src/wab-client/__tests/WABClient.test.js +0 -47
  91. package/out/src/wab-client/__tests/WABClient.test.js.map +0 -1
  92. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.d.ts +0 -34
  93. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.d.ts.map +0 -1
  94. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.js +0 -16
  95. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.js.map +0 -1
  96. package/out/src/wab-client/auth-method-interactors/PersonaIDInteractor.d.ts +0 -7
  97. package/out/src/wab-client/auth-method-interactors/PersonaIDInteractor.d.ts.map +0 -1
  98. package/out/src/wab-client/auth-method-interactors/PersonaIDInteractor.js +0 -40
  99. package/out/src/wab-client/auth-method-interactors/PersonaIDInteractor.js.map +0 -1
  100. package/out/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.d.ts +0 -28
  101. package/out/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.d.ts.map +0 -1
  102. package/out/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.js +0 -73
  103. package/out/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.js.map +0 -1
  104. package/src/CWIStyleWalletManager.ts +0 -1891
  105. package/src/SimpleWalletManager.ts +0 -553
  106. package/src/WalletAuthenticationManager.ts +0 -183
  107. package/src/WalletPermissionsManager.ts +0 -2639
  108. package/src/WalletSettingsManager.ts +0 -241
  109. package/src/__tests/CWIStyleWalletManager.test.ts +0 -709
  110. package/src/__tests/WalletPermissionsManager.callbacks.test.ts +0 -328
  111. package/src/__tests/WalletPermissionsManager.checks.test.ts +0 -857
  112. package/src/__tests/WalletPermissionsManager.encryption.test.ts +0 -407
  113. package/src/__tests/WalletPermissionsManager.fixtures.ts +0 -283
  114. package/src/__tests/WalletPermissionsManager.flows.test.ts +0 -490
  115. package/src/__tests/WalletPermissionsManager.initialization.test.ts +0 -333
  116. package/src/__tests/WalletPermissionsManager.proxying.test.ts +0 -753
  117. package/src/__tests/WalletPermissionsManager.tokens.test.ts +0 -584
  118. package/src/utility/identityUtils.ts +0 -170
  119. package/src/wab-client/WABClient.ts +0 -103
  120. package/src/wab-client/__tests/WABClient.test.ts +0 -58
  121. package/src/wab-client/auth-method-interactors/AuthMethodInteractor.ts +0 -47
  122. package/src/wab-client/auth-method-interactors/PersonaIDInteractor.ts +0 -45
  123. package/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.ts +0 -82
@@ -1,183 +0,0 @@
1
- import {
2
- CWIStyleWalletManager,
3
- UMPTokenInteractor,
4
- OverlayUMPTokenInteractor
5
- } from './CWIStyleWalletManager'
6
- import { PrivilegedKeyManager } from './sdk/PrivilegedKeyManager'
7
- import {
8
- WalletInterface,
9
- Random,
10
- Utils,
11
- Transaction,
12
- RPuzzle,
13
- PrivateKey,
14
- BigNumber
15
- } from '@bsv/sdk'
16
- import { WABClient } from './wab-client/WABClient'
17
- import { AuthMethodInteractor } from './wab-client/auth-method-interactors/AuthMethodInteractor'
18
-
19
- /**
20
- * WalletAuthenticationManager
21
- *
22
- * A wallet manager that integrates
23
- * with a WABClient for user authentication flows (e.g. Twilio phone).
24
- */
25
- export class WalletAuthenticationManager extends CWIStyleWalletManager {
26
- private wabClient: WABClient // instance of WABClient
27
- private authMethod?: AuthMethodInteractor // chosen AuthMethod interactor
28
- private tempPresentationKey?: string // for temporary persistence between auth steps
29
-
30
- constructor(
31
- adminOriginator: string,
32
- walletBuilder: (
33
- primaryKey: number[],
34
- privilegedKeyManager: PrivilegedKeyManager
35
- ) => Promise<WalletInterface>,
36
- interactor: UMPTokenInteractor = new OverlayUMPTokenInteractor(),
37
- recoveryKeySaver: (key: number[]) => Promise<true>,
38
- passwordRetriever: (
39
- reason: string,
40
- test: (passwordCandidate: string) => boolean
41
- ) => Promise<string>,
42
- wabClient: WABClient,
43
- authMethod?: AuthMethodInteractor,
44
- stateSnapshot?: number[]
45
- ) {
46
- super(
47
- adminOriginator,
48
- walletBuilder,
49
- interactor,
50
- recoveryKeySaver,
51
- passwordRetriever,
52
- // Here, we provide a custom new wallet funder that uses the Secret Server
53
- async (
54
- presentationKey: number[],
55
- wallet: WalletInterface,
56
- adminOriginator: string
57
- ) => {
58
- const faucetResultJSON = await this.wabClient.requestFaucet(
59
- Utils.toHex(presentationKey)
60
- )
61
- if (!faucetResultJSON.k || !faucetResultJSON.tx) {
62
- throw new Error('Invalid')
63
- }
64
- const faucetTx = Transaction.fromBinary(faucetResultJSON.tx)
65
- const faucetRedeemTXCreationResult = await wallet.createAction(
66
- {
67
- inputBEEF: faucetTx.toBEEF(),
68
- inputs: [
69
- {
70
- outpoint: `${faucetTx.id('hex')}.0`,
71
- unlockingScriptLength: 104,
72
- inputDescription: 'Fund from faucet'
73
- }
74
- ],
75
- description: 'Fund wallet'
76
- },
77
- adminOriginator
78
- )
79
- const faucetRedeemTX = Transaction.fromAtomicBEEF(
80
- faucetRedeemTXCreationResult.signableTransaction!.tx
81
- )
82
- const faucetRedemptionPuzzle = new RPuzzle()
83
- const randomRedemptionPrivateKey = PrivateKey.fromRandom()
84
- const faucetRedeemUnlocker = faucetRedemptionPuzzle.unlock(
85
- new BigNumber(faucetResultJSON.k, 16),
86
- randomRedemptionPrivateKey
87
- )
88
- const faucetRedeemUnlockingScript = await faucetRedeemUnlocker.sign(
89
- faucetRedeemTX,
90
- 0
91
- )
92
- await wallet.signAction({
93
- reference:
94
- faucetRedeemTXCreationResult.signableTransaction!.reference,
95
- spends: {
96
- 0: {
97
- unlockingScript: faucetRedeemUnlockingScript.toHex()
98
- }
99
- }
100
- })
101
- },
102
- stateSnapshot
103
- )
104
-
105
- this.wabClient = wabClient
106
- this.authMethod = authMethod
107
- }
108
-
109
- /**
110
- * Sets (or switches) the chosen AuthMethodInteractor at runtime,
111
- * in case the user changes their mind or picks a new method in the UI.
112
- */
113
- public setAuthMethod(method: AuthMethodInteractor) {
114
- this.authMethod = method
115
- }
116
-
117
- /**
118
- * Initiate the WAB-based flow, e.g. sending an SMS code or starting an ID check,
119
- * using the chosen AuthMethodInteractor.
120
- */
121
- public async startAuth(payload: any): Promise<void> {
122
- if (!this.authMethod) {
123
- throw new Error('No AuthMethod selected in WalletAuthenticationManager')
124
- }
125
- this.tempPresentationKey = this.generateTemporaryPresentationKey()
126
-
127
- // For example, if this.authMethod is Twilio, `payload` might contain { phoneNumber: "+1..." }
128
- const startRes = await this.wabClient.startAuthMethod(
129
- this.authMethod,
130
- // The user might not have a presentationKey yet, so we generate one locally to pass to the server.
131
- // If it’s an existing user on the WAB side, the WAB will give us the stored key later.
132
- // But we do need some placeholder key for the 'startAuth' call:
133
- this.tempPresentationKey,
134
- payload
135
- )
136
-
137
- if (!startRes.success) {
138
- throw new Error(startRes.message || 'Failed to start WAB auth method')
139
- }
140
- }
141
-
142
- /**
143
- * Completes the WAB-based flow, retrieving the final presentationKey from WAB if successful.
144
- */
145
- public async completeAuth(payload: any): Promise<void> {
146
- if (!this.authMethod || !this.tempPresentationKey) {
147
- throw new Error(
148
- 'No AuthMethod selected in WalletAuthenticationManager or startAuth has yet to be called.'
149
- )
150
- }
151
-
152
- // Unser the temp presentation key early (for security)
153
- const tempKey = this.tempPresentationKey
154
- this.tempPresentationKey = undefined
155
-
156
- const result = await this.wabClient.completeAuthMethod(
157
- this.authMethod,
158
- tempKey,
159
- payload
160
- )
161
-
162
- if (!result.success || !result.presentationKey) {
163
- throw new Error(result.message || 'Failed to complete WAB auth')
164
- }
165
-
166
- // We now have the final 256-bit key in hex from the WAB
167
- const presentationKeyHex = result.presentationKey
168
- const presentationKeyBytes = Utils.toArray(presentationKeyHex, 'hex')
169
-
170
- // Provide this presentation key to the underlying CWI logic:
171
- // This sets 'this.presentationKey' and determines if it's a new or existing user
172
- // based on whether a UMP token exists on chain. We'll do "presentation-key-and-password"
173
- // for new user flows, for example, or user might choose "presentation-key-and-recovery-key" if we wanted.
174
- // Either way, WAB has now done its job and we are off to base-layer CWI logic at this point!
175
- await this.providePresentationKey(presentationKeyBytes)
176
- }
177
-
178
- private generateTemporaryPresentationKey(): string {
179
- // For the 'startAuth' call, we can generate a random 32 bytes → 64 hex chars.
180
- const randomBytes = Random(32) // array of length 32
181
- return Utils.toHex(randomBytes)
182
- }
183
- }