@bsv/sdk 1.3.8 → 1.3.9

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 (120) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/auth/Peer.js +1 -1
  3. package/dist/cjs/src/auth/Peer.js.map +1 -1
  4. package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
  5. package/dist/cjs/src/auth/certificates/MasterCertificate.js +3 -3
  6. package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
  7. package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +1 -1
  8. package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
  9. package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js +12 -0
  10. package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  11. package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
  12. package/dist/cjs/src/auth/utils/createNonce.js.map +1 -1
  13. package/dist/cjs/src/auth/utils/getVerifiableCertificates.js.map +1 -1
  14. package/dist/cjs/src/auth/utils/validateCertificates.js.map +1 -1
  15. package/dist/cjs/src/auth/utils/verifyNonce.js.map +1 -1
  16. package/dist/cjs/src/overlay-tools/OverlayAdminTokenTemplate.js.map +1 -1
  17. package/dist/cjs/src/script/templates/PushDrop.js +1 -1
  18. package/dist/cjs/src/script/templates/PushDrop.js.map +1 -1
  19. package/dist/cjs/src/wallet/ProtoWallet.js +10 -58
  20. package/dist/cjs/src/wallet/ProtoWallet.js.map +1 -1
  21. package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
  22. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  23. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  24. package/dist/cjs/src/wallet/substrates/window.CWI.js.map +1 -1
  25. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  26. package/dist/esm/src/auth/Peer.js +1 -1
  27. package/dist/esm/src/auth/Peer.js.map +1 -1
  28. package/dist/esm/src/auth/certificates/Certificate.js +1 -1
  29. package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
  30. package/dist/esm/src/auth/certificates/MasterCertificate.js +3 -3
  31. package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
  32. package/dist/esm/src/auth/certificates/VerifiableCertificate.js +1 -1
  33. package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
  34. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +12 -0
  35. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  36. package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
  37. package/dist/esm/src/auth/utils/createNonce.js.map +1 -1
  38. package/dist/esm/src/auth/utils/getVerifiableCertificates.js.map +1 -1
  39. package/dist/esm/src/auth/utils/validateCertificates.js.map +1 -1
  40. package/dist/esm/src/auth/utils/verifyNonce.js.map +1 -1
  41. package/dist/esm/src/overlay-tools/OverlayAdminTokenTemplate.js.map +1 -1
  42. package/dist/esm/src/script/templates/PushDrop.js +1 -1
  43. package/dist/esm/src/script/templates/PushDrop.js.map +1 -1
  44. package/dist/esm/src/wallet/ProtoWallet.js +10 -58
  45. package/dist/esm/src/wallet/ProtoWallet.js.map +1 -1
  46. package/dist/esm/src/wallet/WalletClient.js.map +1 -1
  47. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  48. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  49. package/dist/esm/src/wallet/substrates/window.CWI.js.map +1 -1
  50. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  51. package/dist/types/src/auth/Peer.d.ts +3 -3
  52. package/dist/types/src/auth/Peer.d.ts.map +1 -1
  53. package/dist/types/src/auth/certificates/Certificate.d.ts +2 -2
  54. package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
  55. package/dist/types/src/auth/certificates/MasterCertificate.d.ts +7 -7
  56. package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
  57. package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +3 -3
  58. package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
  59. package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts +6 -2
  60. package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts.map +1 -1
  61. package/dist/types/src/auth/clients/AuthFetch.d.ts +2 -2
  62. package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
  63. package/dist/types/src/auth/utils/createNonce.d.ts +2 -2
  64. package/dist/types/src/auth/utils/createNonce.d.ts.map +1 -1
  65. package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts +2 -2
  66. package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts.map +1 -1
  67. package/dist/types/src/auth/utils/validateCertificates.d.ts +2 -2
  68. package/dist/types/src/auth/utils/validateCertificates.d.ts.map +1 -1
  69. package/dist/types/src/auth/utils/verifyNonce.d.ts +2 -2
  70. package/dist/types/src/auth/utils/verifyNonce.d.ts.map +1 -1
  71. package/dist/types/src/overlay-tools/OverlayAdminTokenTemplate.d.ts +2 -2
  72. package/dist/types/src/overlay-tools/OverlayAdminTokenTemplate.d.ts.map +1 -1
  73. package/dist/types/src/script/templates/PushDrop.d.ts +4 -4
  74. package/dist/types/src/script/templates/PushDrop.d.ts.map +1 -1
  75. package/dist/types/src/wallet/ProtoWallet.d.ts +12 -24
  76. package/dist/types/src/wallet/ProtoWallet.d.ts.map +1 -1
  77. package/dist/types/src/wallet/Wallet.interfaces.d.ts +5 -18
  78. package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
  79. package/dist/types/src/wallet/WalletClient.d.ts +4 -4
  80. package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
  81. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts +2 -2
  82. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -1
  83. package/dist/types/src/wallet/substrates/WalletWireProcessor.d.ts +3 -3
  84. package/dist/types/src/wallet/substrates/WalletWireProcessor.d.ts.map +1 -1
  85. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts +2 -2
  86. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts.map +1 -1
  87. package/dist/types/src/wallet/substrates/XDM.d.ts +2 -2
  88. package/dist/types/src/wallet/substrates/XDM.d.ts.map +1 -1
  89. package/dist/types/src/wallet/substrates/window.CWI.d.ts +2 -2
  90. package/dist/types/src/wallet/substrates/window.CWI.d.ts.map +1 -1
  91. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  92. package/dist/umd/bundle.js +1 -1
  93. package/docs/auth.md +72 -39
  94. package/docs/overlay-tools.md +4 -4
  95. package/docs/script.md +5 -5
  96. package/docs/wallet-substrates.md +11 -11
  97. package/docs/wallet.md +300 -360
  98. package/package.json +1 -1
  99. package/src/auth/Peer.ts +25 -25
  100. package/src/auth/certificates/Certificate.ts +4 -3
  101. package/src/auth/certificates/MasterCertificate.ts +8 -8
  102. package/src/auth/certificates/VerifiableCertificate.ts +3 -3
  103. package/src/auth/certificates/__tests/CompletedProtoWallet.ts +14 -3
  104. package/src/auth/clients/AuthFetch.ts +3 -3
  105. package/src/auth/utils/createNonce.ts +2 -2
  106. package/src/auth/utils/getVerifiableCertificates.ts +2 -2
  107. package/src/auth/utils/validateCertificates.ts +2 -2
  108. package/src/auth/utils/verifyNonce.ts +2 -2
  109. package/src/overlay-tools/OverlayAdminTokenTemplate.ts +5 -5
  110. package/src/script/templates/PushDrop.ts +4 -4
  111. package/src/wallet/ProtoWallet.ts +11 -77
  112. package/src/wallet/Wallet.interfaces.ts +5 -19
  113. package/src/wallet/WalletClient.ts +62 -62
  114. package/src/wallet/__tests/ProtoWallet.test.ts +0 -31
  115. package/src/wallet/substrates/HTTPWalletJSON.ts +3 -3
  116. package/src/wallet/substrates/WalletWireProcessor.ts +3 -3
  117. package/src/wallet/substrates/WalletWireTransceiver.ts +2 -2
  118. package/src/wallet/substrates/XDM.ts +3 -3
  119. package/src/wallet/substrates/__tests/WalletWire.integration.test.ts +0 -104
  120. package/src/wallet/substrates/window.CWI.ts +5 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
package/src/auth/Peer.ts CHANGED
@@ -2,7 +2,7 @@ import { SessionManager } from './SessionManager.js'
2
2
  import { createNonce, verifyNonce, getVerifiableCertificates, validateCertificates } from './utils/index.js'
3
3
  import { AuthMessage, PeerSession, RequestedCertificateSet, Transport } from './types.js'
4
4
  import { VerifiableCertificate } from './certificates/VerifiableCertificate.js'
5
- import { Random, Utils, Wallet } from '../../mod.js'
5
+ import { Random, Utils, WalletInterface } from '../../mod.js'
6
6
 
7
7
  const AUTH_VERSION = '0.1'
8
8
 
@@ -14,7 +14,7 @@ const AUTH_VERSION = '0.1'
14
14
  export class Peer {
15
15
  public sessionManager: SessionManager
16
16
  private readonly transport: Transport
17
- private readonly wallet: Wallet
17
+ private readonly wallet: WalletInterface
18
18
  certificatesToRequest: RequestedCertificateSet
19
19
  private readonly onGeneralMessageReceivedCallbacks: Map<number, (senderPublicKey: string, payload: number[]) => void> = new Map()
20
20
  private readonly onCertificatesReceivedCallbacks: Map<number, (senderPublicKey: string, certs: VerifiableCertificate[]) => void> = new Map()
@@ -33,14 +33,14 @@ export class Peer {
33
33
  /**
34
34
  * Creates a new Peer instance
35
35
  *
36
- * @param {Wallet} wallet - The wallet instance used for cryptographic operations.
36
+ * @param {WalletInterface} wallet - The wallet instance used for cryptographic operations.
37
37
  * @param {Transport} transport - The transport mechanism used for sending and receiving messages.
38
38
  * @param {RequestedCertificateSet} [certificatesToRequest] - Optional set of certificates to request from a peer during the initial handshake.
39
39
  * @param {SessionManager} [sessionManager] - Optional SessionManager to be used for managing peer sessions.
40
40
  * @param {boolean} [autoPersistLastSession] - Whether to auto-persist the session with the last-interacted-with peer. Defaults to true.
41
41
  */
42
- constructor (
43
- wallet: Wallet,
42
+ constructor(
43
+ wallet: WalletInterface,
44
44
  transport: Transport,
45
45
  certificatesToRequest?: RequestedCertificateSet,
46
46
  sessionManager?: SessionManager,
@@ -66,7 +66,7 @@ export class Peer {
66
66
  * @returns {Promise<void>}
67
67
  * @throws Will throw an error if the message fails to send.
68
68
  */
69
- async toPeer (message: number[], identityKey?: string, maxWaitTime?: number): Promise<void> {
69
+ async toPeer(message: number[], identityKey?: string, maxWaitTime?: number): Promise<void> {
70
70
  if (this.autoPersistLastSession && this.lastInteractedWithPeer && typeof identityKey !== 'string') {
71
71
  identityKey = this.lastInteractedWithPeer
72
72
  }
@@ -111,7 +111,7 @@ export class Peer {
111
111
  * @returns {Promise<void>} Resolves if the certificate request message is successfully sent.
112
112
  * @throws Will throw an error if the peer session is not authenticated or if sending the request fails.
113
113
  */
114
- async requestCertificates (certificatesToRequest: RequestedCertificateSet, identityKey?: string, maxWaitTime = 10000): Promise<void> {
114
+ async requestCertificates(certificatesToRequest: RequestedCertificateSet, identityKey?: string, maxWaitTime = 10000): Promise<void> {
115
115
  const peerSession = await this.getAuthenticatedSession(identityKey, maxWaitTime)
116
116
 
117
117
  // Prepare the general message
@@ -152,7 +152,7 @@ export class Peer {
152
152
  * @returns {Promise<PeerSession>} - A promise that resolves with an authenticated `PeerSession`.
153
153
  * @throws {Error} - Throws an error if the transport is not connected or if the handshake fails.
154
154
  */
155
- async getAuthenticatedSession (identityKey?: string, maxWaitTime?: number): Promise<PeerSession> {
155
+ async getAuthenticatedSession(identityKey?: string, maxWaitTime?: number): Promise<PeerSession> {
156
156
  if (!this.transport) {
157
157
  throw new Error('Peer transport is not connected!')
158
158
  }
@@ -175,7 +175,7 @@ export class Peer {
175
175
  * @param {(senderPublicKey: string, payload: number[]) => void} callback - The function to call when a general message is received.
176
176
  * @returns {number} The ID of the callback listener.
177
177
  */
178
- listenForGeneralMessages (callback: (senderPublicKey: string, payload: number[]) => void): number {
178
+ listenForGeneralMessages(callback: (senderPublicKey: string, payload: number[]) => void): number {
179
179
  const callbackID = this.callbackIdCounter++
180
180
  this.onGeneralMessageReceivedCallbacks.set(callbackID, callback)
181
181
  return callbackID
@@ -186,7 +186,7 @@ export class Peer {
186
186
  *
187
187
  * @param {number} callbackID - The ID of the callback to remove.
188
188
  */
189
- stopListeningForGeneralMessages (callbackID: number): void {
189
+ stopListeningForGeneralMessages(callbackID: number): void {
190
190
  this.onGeneralMessageReceivedCallbacks.delete(callbackID)
191
191
  }
192
192
 
@@ -196,7 +196,7 @@ export class Peer {
196
196
  * @param {(certs: VerifiableCertificate[]) => void} callback - The function to call when certificates are received.
197
197
  * @returns {number} The ID of the callback listener.
198
198
  */
199
- listenForCertificatesReceived (callback: (senderPublicKey: string, certs: VerifiableCertificate[]) => void): number {
199
+ listenForCertificatesReceived(callback: (senderPublicKey: string, certs: VerifiableCertificate[]) => void): number {
200
200
  const callbackID = this.callbackIdCounter++
201
201
  this.onCertificatesReceivedCallbacks.set(callbackID, callback)
202
202
  return callbackID
@@ -207,7 +207,7 @@ export class Peer {
207
207
  *
208
208
  * @param {number} callbackID - The ID of the certificates received callback to cancel.
209
209
  */
210
- stopListeningForCertificatesReceived (callbackID: number): void {
210
+ stopListeningForCertificatesReceived(callbackID: number): void {
211
211
  this.onCertificatesReceivedCallbacks.delete(callbackID)
212
212
  }
213
213
 
@@ -217,7 +217,7 @@ export class Peer {
217
217
  * @param {(requestedCertificates: RequestedCertificateSet) => void} callback - The function to call when a certificate request is received
218
218
  * @returns {number} The ID of the callback listener.
219
219
  */
220
- listenForCertificatesRequested (callback: (senderPublicKey: string, requestedCertificates: RequestedCertificateSet) => void): number {
220
+ listenForCertificatesRequested(callback: (senderPublicKey: string, requestedCertificates: RequestedCertificateSet) => void): number {
221
221
  const callbackID = this.callbackIdCounter++
222
222
  this.onCertificateRequestReceivedCallbacks.set(callbackID, callback)
223
223
  return callbackID
@@ -228,7 +228,7 @@ export class Peer {
228
228
  *
229
229
  * @param {number} callbackID - The ID of the requested certificates callback to cancel.
230
230
  */
231
- stopListeningForCertificatesRequested (callbackID: number): void {
231
+ stopListeningForCertificatesRequested(callbackID: number): void {
232
232
  this.onCertificateRequestReceivedCallbacks.delete(callbackID)
233
233
  }
234
234
 
@@ -239,7 +239,7 @@ export class Peer {
239
239
  * @param {string} [identityKey] - The identity public key of the peer.
240
240
  * @returns {Promise<string>} A promise that resolves to the session nonce.
241
241
  */
242
- private async initiateHandshake (identityKey?: string, maxWaitTime = 10000): Promise<string> {
242
+ private async initiateHandshake(identityKey?: string, maxWaitTime = 10000): Promise<string> {
243
243
  const sessionNonce = await createNonce(this.wallet) // Initial request nonce
244
244
  this.sessionManager.addSession({
245
245
  isAuthenticated: false,
@@ -265,7 +265,7 @@ export class Peer {
265
265
  * @param {string} sessionNonce - The session nonce created in the initial request.
266
266
  * @returns {Promise<string>} A promise that resolves with the session nonce when the initial response is received.
267
267
  */
268
- private async waitForInitialResponse (sessionNonce: string, maxWaitTime = 10000): Promise<string> {
268
+ private async waitForInitialResponse(sessionNonce: string, maxWaitTime = 10000): Promise<string> {
269
269
  return await new Promise((resolve, reject) => {
270
270
  const callbackID = this.listenForInitialResponse(sessionNonce, (sessionNonce) => {
271
271
  clearTimeout(timeoutHandle)
@@ -288,7 +288,7 @@ export class Peer {
288
288
  * @param {(sessionNonce: string) => void} callback - The callback to invoke when the initial response is received.
289
289
  * @returns {number} The ID of the callback listener.
290
290
  */
291
- private listenForInitialResponse (sessionNonce: string, callback: (sessionNonce: string) => void) {
291
+ private listenForInitialResponse(sessionNonce: string, callback: (sessionNonce: string) => void) {
292
292
  const callbackID = this.callbackIdCounter++
293
293
  this.onInitialResponseReceivedCallbacks.set(callbackID, { callback, sessionNonce })
294
294
  return callbackID
@@ -300,7 +300,7 @@ export class Peer {
300
300
  * @private
301
301
  * @param {number} callbackID - The ID of the callback to remove.
302
302
  */
303
- private stopListeningForInitialResponses (callbackID: number) {
303
+ private stopListeningForInitialResponses(callbackID: number) {
304
304
  this.onInitialResponseReceivedCallbacks.delete(callbackID)
305
305
  }
306
306
 
@@ -310,7 +310,7 @@ export class Peer {
310
310
  * @param {AuthMessage} message - The incoming message to process.
311
311
  * @returns {Promise<void>}
312
312
  */
313
- private async handleIncomingMessage (message: AuthMessage): Promise<void> {
313
+ private async handleIncomingMessage(message: AuthMessage): Promise<void> {
314
314
  if (!message.version || message.version !== AUTH_VERSION) {
315
315
  console.error(`Invalid message auth version! Received: ${message.version}, expected: ${AUTH_VERSION}`)
316
316
  return
@@ -343,7 +343,7 @@ export class Peer {
343
343
  * @param {AuthMessage} message - The incoming initial request message.
344
344
  * @returns {Promise<void>}
345
345
  */
346
- async processInitialRequest (message: AuthMessage) {
346
+ async processInitialRequest(message: AuthMessage) {
347
347
  if (!message.identityKey || !message.initialNonce) {
348
348
  throw new Error('Missing required fields in initialResponse message.')
349
349
  }
@@ -406,7 +406,7 @@ export class Peer {
406
406
  * @returns {Promise<void>}
407
407
  * @throws Will throw an error if nonce verification or signature verification fails.
408
408
  */
409
- private async processInitialResponse (message: AuthMessage) {
409
+ private async processInitialResponse(message: AuthMessage) {
410
410
  const validNonce = await verifyNonce(message.yourNonce, this.wallet)
411
411
  if (!validNonce) {
412
412
  throw new Error(`Initial response nonce verification failed from peer: ${message.identityKey}`)
@@ -478,7 +478,7 @@ export class Peer {
478
478
  * @param {AuthMessage} message - The certificate request message received from the peer.
479
479
  * @throws {Error} Throws an error if nonce verification fails, or the message signature is invalid.
480
480
  */
481
- private async processCertificateRequest (message: AuthMessage) {
481
+ private async processCertificateRequest(message: AuthMessage) {
482
482
  const validNonce = await verifyNonce(message.yourNonce, this.wallet)
483
483
  if (!validNonce) {
484
484
  throw new Error(`Unable to verify nonce for certificate request message from: ${message.identityKey}`)
@@ -520,7 +520,7 @@ export class Peer {
520
520
  *
521
521
  * @throws {Error} Throws an error if the peer session could not be authenticated or if message signing fails.
522
522
  */
523
- async sendCertificateResponse (
523
+ async sendCertificateResponse(
524
524
  verifierIdentityKey: string,
525
525
  certificates: VerifiableCertificate[]
526
526
  ) {
@@ -559,7 +559,7 @@ export class Peer {
559
559
  * @returns {Promise<void>}
560
560
  * @throws Will throw an error if nonce verification or signature verification fails.
561
561
  */
562
- private async processCertificateResponse (
562
+ private async processCertificateResponse(
563
563
  message: AuthMessage
564
564
  ) {
565
565
  const validNonce = await verifyNonce(message.yourNonce, this.wallet)
@@ -597,7 +597,7 @@ export class Peer {
597
597
  * @returns {Promise<void>}
598
598
  * @throws Will throw an error if nonce verification or signature verification fails.
599
599
  */
600
- private async processGeneralMessage (message: AuthMessage) {
600
+ private async processGeneralMessage(message: AuthMessage) {
601
601
  const validNonce = await verifyNonce(message.yourNonce, this.wallet)
602
602
  if (!validNonce) {
603
603
  throw new Error(`Unable to verify nonce for general message from: ${message.identityKey}`)
@@ -5,9 +5,10 @@ import {
5
5
  HexString,
6
6
  OutpointString,
7
7
  CertificateFieldNameUnder50Bytes,
8
- ProtoWallet,
8
+ WalletInterface,
9
9
  Signature,
10
- WalletProtocol
10
+ WalletProtocol,
11
+ ProtoWallet
11
12
  } from '../../../mod.js'
12
13
 
13
14
  /**
@@ -231,7 +232,7 @@ export default class Certificate {
231
232
  * @param {Wallet} certifierWallet - The wallet representing the certifier.
232
233
  * @returns {Promise<void>}
233
234
  */
234
- async sign(certifierWallet: ProtoWallet): Promise<void> {
235
+ async sign(certifierWallet: WalletInterface): Promise<void> {
235
236
  if (this.signature) {
236
237
  throw new Error(`Certificate has already been signed! Signature present: ${this.signature}`)
237
238
  }
@@ -6,9 +6,9 @@ import {
6
6
  HexString,
7
7
  OutpointString,
8
8
  PubKeyHex,
9
- ProtoWallet,
10
9
  Random,
11
- WalletCounterparty
10
+ WalletCounterparty,
11
+ WalletInterface
12
12
  } from '../../../mod.js'
13
13
  import Certificate from './Certificate.js'
14
14
 
@@ -61,12 +61,12 @@ export class MasterCertificate extends Certificate {
61
61
  * This method uses the `masterKeyring` to decrypt each field's encryption key and then
62
62
  * decrypts the field values. The result is a record of plaintext field names and values.
63
63
  *
64
- * @param {ProtoWallet} subjectWallet - The wallet of the subject, used to decrypt the master keyring and field values.
64
+ * @param {WalletInterface} subjectWallet - The wallet of the subject, used to decrypt the master keyring and field values.
65
65
  * @returns {Promise<Record<CertificateFieldNameUnder50Bytes, string>>} - A record of field names and their decrypted values in plaintext.
66
66
  *
67
67
  * @throws {Error} Throws an error if the `masterKeyring` is invalid or if decryption fails for any field.
68
68
  */
69
- async decryptFields(subjectWallet: ProtoWallet): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
69
+ async decryptFields(subjectWallet: WalletInterface): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
70
70
  // const fields: Record<CertificateFieldNameUnder50Bytes, Base64String> = this.fields
71
71
  const decryptedFields: Record<CertificateFieldNameUnder50Bytes, string> = {}
72
72
  if (!this.masterKeyring || Object.keys(this.masterKeyring).length === 0) {
@@ -97,7 +97,7 @@ export class MasterCertificate extends Certificate {
97
97
  * for the verifier's identity key. The result is a keyring containing the keys necessary
98
98
  * for the verifier to access the designated fields.
99
99
  *
100
- * @param {ProtoWallet} subjectWallet - The wallet instance of the subject, used to decrypt and re-encrypt field keys.
100
+ * @param {WalletInterface} subjectWallet - The wallet instance of the subject, used to decrypt and re-encrypt field keys.
101
101
  * @param {WalletCounterparty} verifier - The verifier who will receive access to the selectively revealed fields. Can be an identity key as hex, 'anyone', or 'self'.
102
102
  * @param {string[]} fieldsToReveal - An array of field names to be revealed to the verifier. Must be a subset of the certificate's fields.
103
103
  * @param {string} [originator] - Optional originator identifier, used if additional context is needed for decryption and encryption operations.
@@ -107,7 +107,7 @@ export class MasterCertificate extends Certificate {
107
107
  * - A field in `fieldsToReveal` does not exist in the certificate.
108
108
  * - The decrypted master field key fails to decrypt the corresponding field (indicating an invalid key).
109
109
  */
110
- async createKeyringForVerifier(subjectWallet: ProtoWallet, verifier: WalletCounterparty, fieldsToReveal: string[], originator?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
110
+ async createKeyringForVerifier(subjectWallet: WalletInterface, verifier: WalletCounterparty, fieldsToReveal: string[], originator?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
111
111
  if (!Array.isArray(fieldsToReveal)) {
112
112
  throw new Error('fieldsToReveal must be an array of strings')
113
113
  }
@@ -157,7 +157,7 @@ export class MasterCertificate extends Certificate {
157
157
  * generated symmetric key, which is then encrypted for the subject. The certificate
158
158
  * can also includes a revocation outpoint to manage potential revocation.
159
159
  *
160
- * @param {ProtoWallet} certifierWallet - The wallet of the certifier, used to sign the certificate and encrypt field keys.
160
+ * @param {WalletInterface} certifierWallet - The wallet of the certifier, used to sign the certificate and encrypt field keys.
161
161
  * @param {WalletCounterparty} subject - The subject for whom the certificate is issued.
162
162
  * @param {Record<CertificateFieldNameUnder50Bytes, string>} fields - Unencrypted certificate fields to include, with their names and values.
163
163
  * @param {string} certificateType - The type of certificate being issued.
@@ -169,7 +169,7 @@ export class MasterCertificate extends Certificate {
169
169
  * @throws {Error} Throws an error if any operation (e.g., encryption, signing) fails during certificate issuance.
170
170
  */
171
171
  static async issueCertificateForSubject(
172
- certifierWallet: ProtoWallet,
172
+ certifierWallet: WalletInterface,
173
173
  subject: WalletCounterparty,
174
174
  fields: Record<CertificateFieldNameUnder50Bytes, string>,
175
175
  certificateType: string,
@@ -6,7 +6,7 @@ import {
6
6
  HexString,
7
7
  OutpointString,
8
8
  PubKeyHex,
9
- Wallet,
9
+ WalletInterface,
10
10
  WalletError
11
11
  } from '../../../mod.js'
12
12
  import Certificate from './Certificate.js'
@@ -45,11 +45,11 @@ export class VerifiableCertificate extends Certificate {
45
45
 
46
46
  /**
47
47
  * Decrypts selectively revealed certificate fields using the provided keyring and verifier wallet
48
- * @param {Wallet} verifierWallet - The wallet instance of the certificate's verifier, used to decrypt field keys.
48
+ * @param {WalletInterface} verifierWallet - The wallet instance of the certificate's verifier, used to decrypt field keys.
49
49
  * @returns {Promise<Record<CertificateFieldNameUnder50Bytes, string>>} - A promise that resolves to an object where each key is a field name and each value is the decrypted field value as a string.
50
50
  * @throws {Error} Throws an error if any of the decryption operations fail, with a message indicating the failure context.
51
51
  */
52
- async decryptFields(verifierWallet: Wallet): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
52
+ async decryptFields(verifierWallet: WalletInterface): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
53
53
  if (!this.keyring || Object.keys(this.keyring).length === 0) {
54
54
  throw new Error('A keyring is required to decrypt certificate fields for the verifier.')
55
55
  }
@@ -1,9 +1,9 @@
1
1
  import { PrivateKey } from "mod.js"
2
- import { ProtoWallet, Wallet, CreateActionArgs, OriginatorDomainNameStringUnder250Bytes, CreateActionResult, SignActionArgs, SignActionResult, AbortActionArgs, AbortActionResult, ListActionsArgs, ListActionsResult, InternalizeActionArgs, InternalizeActionResult, ListOutputsArgs, ListOutputsResult, RelinquishOutputArgs, RelinquishOutputResult, AcquireCertificateArgs, AcquireCertificateResult, ListCertificatesArgs, ListCertificatesResult, ProveCertificateArgs, ProveCertificateResult, RelinquishCertificateArgs, RelinquishCertificateResult, DiscoverByIdentityKeyArgs, DiscoverCertificatesResult, DiscoverByAttributesArgs, GetHeightResult, GetHeaderArgs, GetHeaderResult, KeyDeriverApi, KeyDeriver, GetPublicKeyArgs, GetPublicKeyResult, PubKeyHex } from "../../../wallet/index.js"
2
+ import { ProtoWallet, WalletInterface, CreateActionArgs, OriginatorDomainNameStringUnder250Bytes, CreateActionResult, SignActionArgs, SignActionResult, AbortActionArgs, AbortActionResult, ListActionsArgs, ListActionsResult, InternalizeActionArgs, InternalizeActionResult, ListOutputsArgs, ListOutputsResult, RelinquishOutputArgs, RelinquishOutputResult, AcquireCertificateArgs, AcquireCertificateResult, ListCertificatesArgs, ListCertificatesResult, ProveCertificateArgs, ProveCertificateResult, RelinquishCertificateArgs, RelinquishCertificateResult, DiscoverByIdentityKeyArgs, DiscoverCertificatesResult, DiscoverByAttributesArgs, GetHeightResult, GetHeaderArgs, GetHeaderResult, KeyDeriverApi, KeyDeriver, GetPublicKeyArgs, GetPublicKeyResult, PubKeyHex, AuthenticatedResult, GetNetworkResult, GetVersionResult } from "../../../wallet/index.js"
3
3
 
4
4
  // Test Mock wallet which extends ProtoWallet but still implements Wallet interface
5
5
  // Unsupported methods throw
6
- export class CompletedProtoWallet extends ProtoWallet implements Wallet {
6
+ export class CompletedProtoWallet extends ProtoWallet implements WalletInterface {
7
7
  constructor(rootKeyOrKeyDeriver: PrivateKey | 'anyone' | KeyDeriverApi) {
8
8
  super(rootKeyOrKeyDeriver)
9
9
  if (typeof rootKeyOrKeyDeriver['identityKey'] !== 'string') {
@@ -11,7 +11,18 @@ export class CompletedProtoWallet extends ProtoWallet implements Wallet {
11
11
  }
12
12
  this.keyDeriver = rootKeyOrKeyDeriver as KeyDeriver
13
13
  }
14
-
14
+ isAuthenticated(args: {}, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<AuthenticatedResult> {
15
+ throw new Error("not implemented")
16
+ }
17
+ waitForAuthentication(args: {}, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<AuthenticatedResult> {
18
+ throw new Error("not implemented")
19
+ }
20
+ getNetwork(args: {}, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<GetNetworkResult> {
21
+ throw new Error("not implemented")
22
+ }
23
+ getVersion(args: {}, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<GetVersionResult> {
24
+ throw new Error("not implemented")
25
+ }
15
26
  async getPublicKey(
16
27
  args: GetPublicKeyArgs,
17
28
  originator?: OriginatorDomainNameStringUnder250Bytes
@@ -1,4 +1,4 @@
1
- import { Utils, Random, P2PKH, PublicKey, Wallet } from '../../../mod.js'
1
+ import { Utils, Random, P2PKH, PublicKey, WalletInterface } from '../../../mod.js'
2
2
  import { Peer } from '../Peer.js'
3
3
  import { SimplifiedFetchTransport } from '../transports/SimplifiedFetchTransport.js'
4
4
  import { SessionManager } from '../SessionManager.js'
@@ -26,7 +26,7 @@ const PAYMENT_VERSION = '1.0'
26
26
  */
27
27
  export class AuthFetch {
28
28
  private sessionManager: SessionManager
29
- private wallet: Wallet
29
+ private wallet: WalletInterface
30
30
  private callbacks: Record<string, { resolve: Function, reject: Function }> = {}
31
31
  private certificatesReceived: VerifiableCertificate[] = []
32
32
  private requestedCertificates?: RequestedCertificateSet
@@ -37,7 +37,7 @@ export class AuthFetch {
37
37
  * @param wallet - The wallet instance for signing and authentication.
38
38
  * @param requestedCertificates - Optional set of certificates to request from peers.
39
39
  */
40
- constructor(wallet: Wallet, requestedCertificates?: RequestedCertificateSet, sessionManager?: SessionManager) {
40
+ constructor(wallet: WalletInterface, requestedCertificates?: RequestedCertificateSet, sessionManager?: SessionManager) {
41
41
  this.wallet = wallet
42
42
  this.requestedCertificates = requestedCertificates
43
43
  this.sessionManager = sessionManager || new SessionManager()
@@ -1,11 +1,11 @@
1
- import { Utils, Random, Wallet } from '../../../mod.js'
1
+ import { Utils, Random, WalletInterface } from '../../../mod.js'
2
2
 
3
3
  /**
4
4
  * Creates a nonce derived from a privateKey
5
5
  * @param wallet
6
6
  * @returns A random nonce derived with a wallet
7
7
  */
8
- export async function createNonce(wallet: Wallet): Promise<string> {
8
+ export async function createNonce(wallet: WalletInterface): Promise<string> {
9
9
  // Generate 16 random bytes for the first half of the data
10
10
  const firstHalf = Random(16)
11
11
  // Create an sha256 HMAC
@@ -1,5 +1,5 @@
1
1
  import { VerifiableCertificate } from "../certificates/VerifiableCertificate.js"
2
- import { Wallet } from "../../../mod.js"
2
+ import { WalletInterface } from "../../../mod.js"
3
3
  import { RequestedCertificateSet } from "../types.js"
4
4
 
5
5
  /**
@@ -10,7 +10,7 @@ import { RequestedCertificateSet } from "../types.js"
10
10
  * @param {string} verifierIdentityKey - The public key of the verifier requesting the certificates.
11
11
  * @returns {Promise<VerifiableCertificate[]>} An array of verifiable certificates.
12
12
  */
13
- export const getVerifiableCertificates = async (wallet: Wallet, requestedCertificates: RequestedCertificateSet, verifierIdentityKey: string): Promise<VerifiableCertificate[]> => {
13
+ export const getVerifiableCertificates = async (wallet: WalletInterface, requestedCertificates: RequestedCertificateSet, verifierIdentityKey: string): Promise<VerifiableCertificate[]> => {
14
14
  // Find matching certificates we have
15
15
  // Note: This may return multiple certificates that match the correct type.
16
16
  const matchingCertificates = await wallet.listCertificates({
@@ -1,4 +1,4 @@
1
- import { Wallet } from "../../wallet/index.js"
1
+ import { WalletInterface } from "../../wallet/index.js"
2
2
  import { AuthMessage, RequestedCertificateSet } from "../types.js"
3
3
  import { VerifiableCertificate } from "../certificates/VerifiableCertificate.js"
4
4
 
@@ -10,7 +10,7 @@ import { VerifiableCertificate } from "../certificates/VerifiableCertificate.js"
10
10
  * @returns {Promise<void>}
11
11
  * @throws Will throw an error if certificate validation or field decryption fails.
12
12
  */
13
- export const validateCertificates = async (verifierWallet: Wallet, message: AuthMessage, certificatesRequested?: RequestedCertificateSet): Promise<void> => {
13
+ export const validateCertificates = async (verifierWallet: WalletInterface, message: AuthMessage, certificatesRequested?: RequestedCertificateSet): Promise<void> => {
14
14
  await Promise.all(message.certificates.map(async (incomingCert: VerifiableCertificate) => {
15
15
  if (incomingCert.subject !== message.identityKey) {
16
16
  throw new Error(`The subject of one of your certificates ("${incomingCert.subject}") is not the same as the request sender ("${message.identityKey}").`)
@@ -1,4 +1,4 @@
1
- import { Utils, Wallet } from '../../../mod.js'
1
+ import { Utils, WalletInterface } from '../../../mod.js'
2
2
 
3
3
  /**
4
4
  * Verifies a nonce derived from a wallet
@@ -6,7 +6,7 @@ import { Utils, Wallet } from '../../../mod.js'
6
6
  * @param wallet
7
7
  * @returns The status of the validation
8
8
  */
9
- export async function verifyNonce(nonce: string, wallet: Wallet): Promise<boolean> {
9
+ export async function verifyNonce(nonce: string, wallet: WalletInterface): Promise<boolean> {
10
10
  // Convert nonce from base64 string to Uint8Array
11
11
  const buffer = Utils.toArray(nonce, 'base64')
12
12
 
@@ -1,5 +1,5 @@
1
1
  import PushDrop from '../script/templates/PushDrop.js'
2
- import { Wallet } from '../wallet/Wallet.interfaces.js'
2
+ import { WalletInterface } from '../wallet/Wallet.interfaces.js'
3
3
  import { LockingScript, ScriptTemplate, UnlockingScript } from '../script/index.js'
4
4
  import { Transaction } from '../transaction/index.js'
5
5
  import { Utils } from '../primitives/index.js'
@@ -15,7 +15,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
15
15
  * @param script Locking script comprising a SHIP or SLAP token to decode
16
16
  * @returns Decoded SHIP or SLAP advertisement
17
17
  */
18
- static decode (script: LockingScript): { protocol: 'SHIP' | 'SLAP', identityKey: string, domain: string, topicOrService: string } {
18
+ static decode(script: LockingScript): { protocol: 'SHIP' | 'SLAP', identityKey: string, domain: string, topicOrService: string } {
19
19
  const result = PushDrop.decode(script)
20
20
  if (result.fields.length < 4) {
21
21
  throw new Error('Invalid SHIP/SLAP advertisement!')
@@ -39,7 +39,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
39
39
  * Constructs a new Overlay Admin template instance
40
40
  * @param wallet Wallet to use for locking and unlocking
41
41
  */
42
- constructor (wallet: Wallet) {
42
+ constructor(wallet: WalletInterface) {
43
43
  this.pushDrop = new PushDrop(wallet)
44
44
  }
45
45
 
@@ -50,7 +50,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
50
50
  * @param topicOrService Topic or service to advertise
51
51
  * @returns Locking script comprising the advertisement token
52
52
  */
53
- async lock (protocol: 'SHIP' | 'SLAP', domain: string, topicOrService: string): Promise<LockingScript> {
53
+ async lock(protocol: 'SHIP' | 'SLAP', domain: string, topicOrService: string): Promise<LockingScript> {
54
54
  const { publicKey: identityKey } = await this.pushDrop.wallet.getPublicKey({ identityKey: true })
55
55
  return await this.pushDrop.lock(
56
56
  [
@@ -70,7 +70,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
70
70
  * @param protocol SHIP or SLAP, depending on the token to unlock
71
71
  * @returns Script unlocker capable of unlocking the advertisement token
72
72
  */
73
- unlock (protocol: 'SHIP' | 'SLAP'): {
73
+ unlock(protocol: 'SHIP' | 'SLAP'): {
74
74
  sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>
75
75
  estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>
76
76
  } {
@@ -1,6 +1,6 @@
1
1
  import { ScriptTemplate, LockingScript, UnlockingScript, OP } from '../index.js'
2
2
  import { Utils, Hash, TransactionSignature, Signature, PublicKey } from '../../primitives/index.js'
3
- import { Wallet } from '../../wallet/Wallet.interfaces.js'
3
+ import { WalletInterface } from '../../wallet/Wallet.interfaces.js'
4
4
  import { Transaction } from '../../transaction/index.js'
5
5
  import { SecurityLevel } from '../../wallet/Wallet.interfaces.js'
6
6
 
@@ -44,7 +44,7 @@ const createMinimallyEncodedScriptChunk = (data: number[]): { op: number, data?:
44
44
  }
45
45
 
46
46
  export default class PushDrop implements ScriptTemplate {
47
- wallet: Wallet
47
+ wallet: WalletInterface
48
48
 
49
49
  /**
50
50
  * Decodes a PushDrop script back into its token fields and the locking public key. If a signature was present, it will be the last field returned.
@@ -84,9 +84,9 @@ export default class PushDrop implements ScriptTemplate {
84
84
  /**
85
85
  * Constructs a new instance of the PushDrop class.
86
86
  *
87
- * @param {Wallet} wallet - The wallet interface used for creating signatures and accessing public keys.
87
+ * @param {WalletInterface} wallet - The wallet interface used for creating signatures and accessing public keys.
88
88
  */
89
- constructor(wallet: Wallet) {
89
+ constructor(wallet: WalletInterface) {
90
90
  this.wallet = wallet
91
91
  }
92
92