@bsv/sdk 1.10.4 → 2.0.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 (156) hide show
  1. package/dist/cjs/mod.js +1 -0
  2. package/dist/cjs/mod.js.map +1 -1
  3. package/dist/cjs/package.json +2 -3
  4. package/dist/cjs/src/auth/Peer.js +18 -20
  5. package/dist/cjs/src/auth/Peer.js.map +1 -1
  6. package/dist/cjs/src/identity/IdentityClient.js +20 -124
  7. package/dist/cjs/src/identity/IdentityClient.js.map +1 -1
  8. package/dist/cjs/src/primitives/TransactionSignature.js +115 -10
  9. package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -1
  10. package/dist/cjs/src/primitives/utils.js +13 -112
  11. package/dist/cjs/src/primitives/utils.js.map +1 -1
  12. package/dist/cjs/src/remittance/CommsLayer.js +3 -0
  13. package/dist/cjs/src/remittance/CommsLayer.js.map +1 -0
  14. package/dist/cjs/src/remittance/IdentityLayer.js +3 -0
  15. package/dist/cjs/src/remittance/IdentityLayer.js.map +1 -0
  16. package/dist/cjs/src/remittance/RemittanceManager.js +1245 -0
  17. package/dist/cjs/src/remittance/RemittanceManager.js.map +1 -0
  18. package/dist/cjs/src/remittance/RemittanceModule.js +3 -0
  19. package/dist/cjs/src/remittance/RemittanceModule.js.map +1 -0
  20. package/dist/cjs/src/remittance/index.js +23 -0
  21. package/dist/cjs/src/remittance/index.js.map +1 -0
  22. package/dist/cjs/src/remittance/modules/BasicBRC29.js +225 -0
  23. package/dist/cjs/src/remittance/modules/BasicBRC29.js.map +1 -0
  24. package/dist/cjs/src/remittance/modules/index.js +18 -0
  25. package/dist/cjs/src/remittance/modules/index.js.map +1 -0
  26. package/dist/cjs/src/remittance/types.js +22 -0
  27. package/dist/cjs/src/remittance/types.js.map +1 -0
  28. package/dist/cjs/src/script/OP.js +15 -13
  29. package/dist/cjs/src/script/OP.js.map +1 -1
  30. package/dist/cjs/src/script/Script.js +4 -1
  31. package/dist/cjs/src/script/Script.js.map +1 -1
  32. package/dist/cjs/src/script/Spend.js +128 -46
  33. package/dist/cjs/src/script/Spend.js.map +1 -1
  34. package/dist/cjs/src/transaction/BeefTx.js +2 -2
  35. package/dist/cjs/src/transaction/Transaction.js +160 -0
  36. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  37. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  38. package/dist/esm/mod.js +1 -0
  39. package/dist/esm/mod.js.map +1 -1
  40. package/dist/esm/src/auth/Peer.js +18 -20
  41. package/dist/esm/src/auth/Peer.js.map +1 -1
  42. package/dist/esm/src/identity/IdentityClient.js +20 -124
  43. package/dist/esm/src/identity/IdentityClient.js.map +1 -1
  44. package/dist/esm/src/primitives/TransactionSignature.js +115 -10
  45. package/dist/esm/src/primitives/TransactionSignature.js.map +1 -1
  46. package/dist/esm/src/primitives/utils.js +13 -112
  47. package/dist/esm/src/primitives/utils.js.map +1 -1
  48. package/dist/esm/src/remittance/CommsLayer.js +2 -0
  49. package/dist/esm/src/remittance/CommsLayer.js.map +1 -0
  50. package/dist/esm/src/remittance/IdentityLayer.js +2 -0
  51. package/dist/esm/src/remittance/IdentityLayer.js.map +1 -0
  52. package/dist/esm/src/remittance/RemittanceManager.js +1254 -0
  53. package/dist/esm/src/remittance/RemittanceManager.js.map +1 -0
  54. package/dist/esm/src/remittance/RemittanceModule.js +2 -0
  55. package/dist/esm/src/remittance/RemittanceModule.js.map +1 -0
  56. package/dist/esm/src/remittance/index.js +7 -0
  57. package/dist/esm/src/remittance/index.js.map +1 -0
  58. package/dist/esm/src/remittance/modules/BasicBRC29.js +227 -0
  59. package/dist/esm/src/remittance/modules/BasicBRC29.js.map +1 -0
  60. package/dist/esm/src/remittance/modules/index.js +2 -0
  61. package/dist/esm/src/remittance/modules/index.js.map +1 -0
  62. package/dist/esm/src/remittance/types.js +19 -0
  63. package/dist/esm/src/remittance/types.js.map +1 -0
  64. package/dist/esm/src/script/OP.js +15 -13
  65. package/dist/esm/src/script/OP.js.map +1 -1
  66. package/dist/esm/src/script/Script.js +4 -1
  67. package/dist/esm/src/script/Script.js.map +1 -1
  68. package/dist/esm/src/script/Spend.js +129 -46
  69. package/dist/esm/src/script/Spend.js.map +1 -1
  70. package/dist/esm/src/transaction/BeefTx.js +3 -3
  71. package/dist/esm/src/transaction/BeefTx.js.map +1 -1
  72. package/dist/esm/src/transaction/Transaction.js +160 -0
  73. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  74. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  75. package/dist/types/mod.d.ts +1 -0
  76. package/dist/types/mod.d.ts.map +1 -1
  77. package/dist/types/src/auth/Peer.d.ts +3 -7
  78. package/dist/types/src/auth/Peer.d.ts.map +1 -1
  79. package/dist/types/src/identity/IdentityClient.d.ts +0 -8
  80. package/dist/types/src/identity/IdentityClient.d.ts.map +1 -1
  81. package/dist/types/src/primitives/TransactionSignature.d.ts +16 -4
  82. package/dist/types/src/primitives/TransactionSignature.d.ts.map +1 -1
  83. package/dist/types/src/primitives/utils.d.ts +1 -0
  84. package/dist/types/src/primitives/utils.d.ts.map +1 -1
  85. package/dist/types/src/remittance/CommsLayer.d.ts +50 -0
  86. package/dist/types/src/remittance/CommsLayer.d.ts.map +1 -0
  87. package/dist/types/src/remittance/IdentityLayer.d.ts +35 -0
  88. package/dist/types/src/remittance/IdentityLayer.d.ts.map +1 -0
  89. package/dist/types/src/remittance/RemittanceManager.d.ts +452 -0
  90. package/dist/types/src/remittance/RemittanceManager.d.ts.map +1 -0
  91. package/dist/types/src/remittance/RemittanceModule.d.ts +106 -0
  92. package/dist/types/src/remittance/RemittanceModule.d.ts.map +1 -0
  93. package/dist/types/src/remittance/index.d.ts +7 -0
  94. package/dist/types/src/remittance/index.d.ts.map +1 -0
  95. package/dist/types/src/remittance/modules/BasicBRC29.d.ts +133 -0
  96. package/dist/types/src/remittance/modules/BasicBRC29.d.ts.map +1 -0
  97. package/dist/types/src/remittance/modules/index.d.ts +2 -0
  98. package/dist/types/src/remittance/modules/index.d.ts.map +1 -0
  99. package/dist/types/src/remittance/types.d.ts +238 -0
  100. package/dist/types/src/remittance/types.d.ts.map +1 -0
  101. package/dist/types/src/script/OP.d.ts +5 -3
  102. package/dist/types/src/script/OP.d.ts.map +1 -1
  103. package/dist/types/src/script/Script.d.ts.map +1 -1
  104. package/dist/types/src/script/Spend.d.ts +7 -0
  105. package/dist/types/src/script/Spend.d.ts.map +1 -1
  106. package/dist/types/src/transaction/BeefTx.d.ts +2 -2
  107. package/dist/types/src/transaction/Transaction.d.ts +14 -0
  108. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  109. package/dist/types/src/wallet/Wallet.interfaces.d.ts +5 -5
  110. package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
  111. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  112. package/dist/umd/bundle.js +13 -13
  113. package/dist/umd/bundle.js.map +1 -1
  114. package/docs/index.md +2 -14
  115. package/docs/reference/auth.md +6 -12
  116. package/docs/reference/primitives.md +20 -78
  117. package/docs/reference/remittance.md +2166 -0
  118. package/docs/reference/script.md +11 -3
  119. package/docs/reference/transaction.md +27 -1
  120. package/docs/reference/wallet.md +6 -5
  121. package/docs/remittance-getting-started.md +138 -0
  122. package/mod.ts +1 -0
  123. package/package.json +12 -3
  124. package/src/auth/Peer.ts +18 -29
  125. package/src/auth/__tests/Peer.test.ts +253 -1
  126. package/src/identity/IdentityClient.ts +29 -153
  127. package/src/identity/__tests/IdentityClient.test.ts +1 -289
  128. package/src/overlay-tools/__tests/SHIPBroadcaster.test.ts +7 -9
  129. package/src/primitives/TransactionSignature.ts +129 -10
  130. package/src/primitives/__tests/utils.test.ts +30 -7
  131. package/src/primitives/utils.ts +13 -129
  132. package/src/remittance/CommsLayer.ts +41 -0
  133. package/src/remittance/IdentityLayer.ts +32 -0
  134. package/src/remittance/RemittanceManager.ts +1672 -0
  135. package/src/remittance/RemittanceModule.ts +92 -0
  136. package/src/remittance/__tests/BasicBRC29.test.ts +188 -0
  137. package/src/remittance/__tests/RemittanceManager.test.ts +493 -0
  138. package/src/remittance/__tests/examples.ts +130 -0
  139. package/src/remittance/index.ts +6 -0
  140. package/src/remittance/modules/BasicBRC29.ts +361 -0
  141. package/src/remittance/modules/index.ts +1 -0
  142. package/src/remittance/types.ts +284 -0
  143. package/src/script/OP.ts +15 -13
  144. package/src/script/Script.ts +3 -1
  145. package/src/script/Spend.ts +128 -52
  146. package/src/script/__tests/Chronicle.test.ts +186 -0
  147. package/src/script/__tests/Spend.test.ts +1 -1
  148. package/src/script/__tests/SpendValildVectors.test.ts +63 -0
  149. package/src/script/__tests/lrshiftnum.test.ts +185 -0
  150. package/src/script/__tests/sighashTestData.ts +1031 -0
  151. package/src/script/__tests/spend.valid.vectors.ts +9 -16
  152. package/src/transaction/BeefTx.ts +3 -3
  153. package/src/transaction/Transaction.ts +186 -0
  154. package/src/transaction/__tests/Beef.test.ts +2 -0
  155. package/src/transaction/__tests/Transaction.test.ts +641 -3
  156. package/src/wallet/Wallet.interfaces.ts +5 -5
package/docs/index.md CHANGED
@@ -48,6 +48,7 @@ Finally, you can deep dive into the details of the interface and types in the re
48
48
 
49
49
  ## Reference Material
50
50
 
51
+ - [Remittance Getting Started](./remittance-getting-started.md)
51
52
  - [Wallet](./reference/wallet.md)
52
53
  - [Primitives](./reference/primitives.md)
53
54
  - [Script](./reference/script.md)
@@ -58,8 +59,8 @@ Finally, you can deep dive into the details of the interface and types in the re
58
59
  - [Registry](./reference/registry.md)
59
60
  - [Storage](./reference/storage.md)
60
61
  - [KV Store](./reference/kvstore.md)
62
+ - [Remittance](./reference/remittance.md)
61
63
  - [Messages](./reference/messages.md)
62
- - Please note [*Security Considerations*](#security-considerations-for-encrypted-messages).
63
64
  - [TOTP](./reference/totp.md)
64
65
  - [Compatibility](./reference/compat.md)
65
66
 
@@ -76,16 +77,3 @@ Finally, you can deep dive into the details of the interface and types in the re
76
77
  ## Performance Reports
77
78
 
78
79
  - [Benchmarks](./performance.md)
79
-
80
- ## Security Considerations for Encrypted Messages
81
-
82
- The encrypted message protocol implemented in this SDK derives per-message encryption keys deterministically from the parties’ long-term keys and a caller-supplied invoice number (BRC-42 style derivation).
83
-
84
- This construction does not provide the guarantees of a standard authenticated key exchange (AKE). In particular:
85
-
86
- No forward secrecy: Compromise of a long-term private key compromises all past and future messages derived from it.
87
- No replay protection: Messages encrypted under the same invoice number and key pair can be replayed.
88
- Potential identity misbinding: Public keys alone do not guarantee peer identity without additional authentication or identity verification.
89
- This protocol is intended for lightweight, deterministic messaging between parties that already trust each other’s long-term public keys. It SHOULD NOT be used for high-security or high-value communications without additional protocol-layer protections.
90
-
91
- Applications requiring strong authentication, replay protection, or forward secrecy should use a formally analyzed protocol such as X3DH, Noise, or SIGMA.
@@ -681,9 +681,9 @@ export class Peer {
681
681
  public sessionManager: SessionManager;
682
682
  certificatesToRequest: RequestedCertificateSet;
683
683
  constructor(wallet: WalletInterface, transport: Transport, certificatesToRequest?: RequestedCertificateSet, sessionManager?: SessionManager, autoPersistLastSession?: boolean, originator?: OriginatorDomainNameStringUnder250Bytes)
684
- async toPeer(message: number[], identityKey?: string, maxWaitTime?: number): Promise<void>
685
- async requestCertificates(certificatesToRequest: RequestedCertificateSet, identityKey?: string, maxWaitTime = 10000): Promise<void>
686
- async getAuthenticatedSession(identityKey?: string, maxWaitTime?: number): Promise<PeerSession>
684
+ async toPeer(message: number[], identityKey?: string): Promise<void>
685
+ async requestCertificates(certificatesToRequest: RequestedCertificateSet, identityKey?: string): Promise<void>
686
+ async getAuthenticatedSession(identityKey?: string): Promise<PeerSession>
687
687
  listenForGeneralMessages(callback: (senderPublicKey: string, payload: number[]) => void): number
688
688
  stopListeningForGeneralMessages(callbackID: number): void
689
689
  listenForCertificatesReceived(callback: (senderPublicKey: string, certs: VerifiableCertificate[]) => void): number
@@ -728,7 +728,7 @@ or the session is not authenticated, initiates a handshake to create or authenti
728
728
  - If `identityKey` is not provided, but we have a `lastInteractedWithPeer`, we try that key.
729
729
 
730
730
  ```ts
731
- async getAuthenticatedSession(identityKey?: string, maxWaitTime?: number): Promise<PeerSession>
731
+ async getAuthenticatedSession(identityKey?: string): Promise<PeerSession>
732
732
  ```
733
733
  See also: [PeerSession](./auth.md#interface-peersession)
734
734
 
@@ -740,8 +740,6 @@ Argument Details
740
740
 
741
741
  + **identityKey**
742
742
  + The identity public key of the peer.
743
- + **maxWaitTime**
744
- + The maximum time in milliseconds to wait for the handshake.
745
743
 
746
744
  #### Method listenForCertificatesReceived
747
745
 
@@ -803,7 +801,7 @@ This method allows a peer to dynamically request specific certificates after
803
801
  an initial handshake or message has been exchanged.
804
802
 
805
803
  ```ts
806
- async requestCertificates(certificatesToRequest: RequestedCertificateSet, identityKey?: string, maxWaitTime = 10000): Promise<void>
804
+ async requestCertificates(certificatesToRequest: RequestedCertificateSet, identityKey?: string): Promise<void>
807
805
  ```
808
806
  See also: [RequestedCertificateSet](./auth.md#interface-requestedcertificateset)
809
807
 
@@ -817,8 +815,6 @@ Argument Details
817
815
  + Specifies the certifiers and types of certificates required from the peer.
818
816
  + **identityKey**
819
817
  + The identity public key of the peer. If not provided, the current or last session identity is used.
820
- + **maxWaitTime**
821
- + Maximum time in milliseconds to wait for the peer session to be authenticated.
822
818
 
823
819
  Throws
824
820
 
@@ -888,7 +884,7 @@ Argument Details
888
884
  Sends a general message to a peer, and initiates a handshake if necessary.
889
885
 
890
886
  ```ts
891
- async toPeer(message: number[], identityKey?: string, maxWaitTime?: number): Promise<void>
887
+ async toPeer(message: number[], identityKey?: string): Promise<void>
892
888
  ```
893
889
 
894
890
  Argument Details
@@ -897,8 +893,6 @@ Argument Details
897
893
  + The message payload to send.
898
894
  + **identityKey**
899
895
  + The identity public key of the peer. If not provided, uses lastInteractedWithPeer (if any).
900
- + **maxWaitTime**
901
- + optional max wait time in ms
902
896
 
903
897
  Throws
904
898
 
@@ -4940,9 +4940,12 @@ export default class TransactionSignature extends Signature {
4940
4940
  public static readonly SIGHASH_ALL = 1;
4941
4941
  public static readonly SIGHASH_NONE = 2;
4942
4942
  public static readonly SIGHASH_SINGLE = 3;
4943
+ public static readonly SIGHASH_CHRONICLE = 32;
4943
4944
  public static readonly SIGHASH_FORKID = 64;
4944
4945
  public static readonly SIGHASH_ANYONECANPAY = 128;
4945
4946
  scope: number;
4947
+ static formatOTDA(params: TransactionSignatureFormatParams): Uint8Array
4948
+ static formatBip143(params: TransactionSignatureFormatParams): Uint8Array
4946
4949
  static format(params: TransactionSignatureFormatParams): number[]
4947
4950
  static formatBytes(params: TransactionSignatureFormatParams): Uint8Array
4948
4951
  static fromChecksigFormat(buf: number[]): TransactionSignature
@@ -4969,12 +4972,12 @@ Argument Details
4969
4972
  + **params.cache**
4970
4973
  + Optional cache storing previously computed `hashPrevouts`, `hashSequence`, or `hashOutputs*` values; it will be populated if present.
4971
4974
 
4972
- #### Method formatBytes
4975
+ #### Method formatBip143
4973
4976
 
4974
4977
  Formats the same SIGHASH preimage bytes as `format`, supporting the optional cache for hash reuse.
4975
4978
 
4976
4979
  ```ts
4977
- static formatBytes(params: TransactionSignatureFormatParams): Uint8Array
4980
+ static formatBip143(params: TransactionSignatureFormatParams): Uint8Array
4978
4981
  ```
4979
4982
 
4980
4983
  Returns
@@ -4988,6 +4991,18 @@ Argument Details
4988
4991
  + **params.cache**
4989
4992
  + Optional `SignatureHashCache` that may already contain hashed prefixes and is populated during formatting.
4990
4993
 
4994
+ #### Method formatOTDA
4995
+
4996
+ Implements the original bitcoin transaction signature digest preimage algorithm (OTDA).
4997
+
4998
+ ```ts
4999
+ static formatOTDA(params: TransactionSignatureFormatParams): Uint8Array
5000
+ ```
5001
+
5002
+ Returns
5003
+
5004
+ preimage as a byte array
5005
+
4991
5006
  #### Method hasLowS
4992
5007
 
4993
5008
  Compares to bitcoind's IsLowDERSignature
@@ -5010,6 +5025,7 @@ export class Writer {
5010
5025
  getLength(): number
5011
5026
  toUint8Array(): Uint8Array
5012
5027
  toArray(): number[]
5028
+ toHex(): string
5013
5029
  write(buf: WriterChunk): this
5014
5030
  writeReverse(buf: number[]): this
5015
5031
  writeUInt8(n: number): this
@@ -5032,7 +5048,7 @@ export class Writer {
5032
5048
  }
5033
5049
  ```
5034
5050
 
5035
- See also: [BigNumber](./primitives.md#class-bignumber), [toArray](./primitives.md#variable-toarray), [toUint8Array](./primitives.md#variable-touint8array)
5051
+ See also: [BigNumber](./primitives.md#class-bignumber), [toArray](./primitives.md#variable-toarray), [toHex](./primitives.md#variable-tohex), [toUint8Array](./primitives.md#variable-touint8array)
5036
5052
 
5037
5053
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
5038
5054
 
@@ -6444,81 +6460,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
6444
6460
 
6445
6461
  ```ts
6446
6462
  toUTF8 = (arr: number[]): string => {
6447
- let result = "";
6448
- const replacementChar = "\uFFFD";
6449
- for (let i = 0; i < arr.length; i++) {
6450
- const byte1 = arr[i];
6451
- if (byte1 <= 127) {
6452
- result += String.fromCharCode(byte1);
6453
- continue;
6454
- }
6455
- const emitReplacement = (): void => {
6456
- result += replacementChar;
6457
- };
6458
- if (byte1 >= 192 && byte1 <= 223) {
6459
- if (i + 1 >= arr.length) {
6460
- emitReplacement();
6461
- continue;
6462
- }
6463
- const byte2 = arr[i + 1];
6464
- if ((byte2 & 192) !== 128) {
6465
- emitReplacement();
6466
- i += 1;
6467
- continue;
6468
- }
6469
- const codePoint = ((byte1 & 31) << 6) | (byte2 & 63);
6470
- result += String.fromCharCode(codePoint);
6471
- i += 1;
6472
- continue;
6473
- }
6474
- if (byte1 >= 224 && byte1 <= 239) {
6475
- if (i + 2 >= arr.length) {
6476
- emitReplacement();
6477
- continue;
6478
- }
6479
- const byte2 = arr[i + 1];
6480
- const byte3 = arr[i + 2];
6481
- if ((byte2 & 192) !== 128 || (byte3 & 192) !== 128) {
6482
- emitReplacement();
6483
- i += 2;
6484
- continue;
6485
- }
6486
- const codePoint = ((byte1 & 15) << 12) |
6487
- ((byte2 & 63) << 6) |
6488
- (byte3 & 63);
6489
- result += String.fromCharCode(codePoint);
6490
- i += 2;
6491
- continue;
6492
- }
6493
- if (byte1 >= 240 && byte1 <= 247) {
6494
- if (i + 3 >= arr.length) {
6495
- emitReplacement();
6496
- continue;
6497
- }
6498
- const byte2 = arr[i + 1];
6499
- const byte3 = arr[i + 2];
6500
- const byte4 = arr[i + 3];
6501
- if ((byte2 & 192) !== 128 ||
6502
- (byte3 & 192) !== 128 ||
6503
- (byte4 & 192) !== 128) {
6504
- emitReplacement();
6505
- i += 3;
6506
- continue;
6507
- }
6508
- const codePoint = ((byte1 & 7) << 18) |
6509
- ((byte2 & 63) << 12) |
6510
- ((byte3 & 63) << 6) |
6511
- (byte4 & 63);
6512
- const offset = codePoint - 65536;
6513
- const highSurrogate = 55296 + (offset >> 10);
6514
- const lowSurrogate = 56320 + (offset & 1023);
6515
- result += String.fromCharCode(highSurrogate, lowSurrogate);
6516
- i += 3;
6517
- continue;
6518
- }
6519
- emitReplacement();
6520
- }
6521
- return result;
6463
+ return new TextDecoder().decode(new Uint8Array(arr));
6522
6464
  }
6523
6465
  ```
6524
6466