@bsv/sdk 1.4.22 → 1.4.23

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.
package/docs/auth.md CHANGED
@@ -1106,11 +1106,12 @@ export class VerifiableCertificate extends Certificate {
1106
1106
  keyring: Record<CertificateFieldNameUnder50Bytes, string>;
1107
1107
  decryptedFields?: Record<CertificateFieldNameUnder50Bytes, Base64String>;
1108
1108
  constructor(type: Base64String, serialNumber: Base64String, subject: PubKeyHex, certifier: PubKeyHex, revocationOutpoint: OutpointString, fields: Record<CertificateFieldNameUnder50Bytes, string>, keyring: Record<CertificateFieldNameUnder50Bytes, string>, signature?: HexString, decryptedFields?: Record<CertificateFieldNameUnder50Bytes, Base64String>)
1109
+ static fromCertificate(certificate: WalletCertificate, keyring: Record<CertificateFieldNameUnder50Bytes, string>): VerifiableCertificate
1109
1110
  async decryptFields(verifierWallet: ProtoWallet, privileged?: boolean, privilegedReason?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
1110
1111
  }
1111
1112
  ```
1112
1113
 
1113
- See also: [Base64String](./wallet.md#type-base64string), [Certificate](./auth.md#class-certificate), [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [HexString](./wallet.md#type-hexstring), [OutpointString](./wallet.md#type-outpointstring), [ProtoWallet](./wallet.md#class-protowallet), [PubKeyHex](./wallet.md#type-pubkeyhex)
1114
+ See also: [Base64String](./wallet.md#type-base64string), [Certificate](./auth.md#class-certificate), [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [HexString](./wallet.md#type-hexstring), [OutpointString](./wallet.md#type-outpointstring), [ProtoWallet](./wallet.md#class-protowallet), [PubKeyHex](./wallet.md#type-pubkeyhex), [WalletCertificate](./wallet.md#interface-walletcertificate)
1114
1115
 
1115
1116
  #### Method decryptFields
1116
1117
 
@@ -1138,6 +1139,25 @@ Throws
1138
1139
 
1139
1140
  Throws an error if any of the decryption operations fail, with a message indicating the failure context.
1140
1141
 
1142
+ #### Method fromCertificate
1143
+
1144
+ ```ts
1145
+ static fromCertificate(certificate: WalletCertificate, keyring: Record<CertificateFieldNameUnder50Bytes, string>): VerifiableCertificate
1146
+ ```
1147
+ See also: [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [VerifiableCertificate](./auth.md#class-verifiablecertificate), [WalletCertificate](./wallet.md#interface-walletcertificate)
1148
+
1149
+ Returns
1150
+
1151
+ – A fully-formed instance containing the
1152
+ original certificate data plus the supplied keyring.
1153
+
1154
+ Argument Details
1155
+
1156
+ + **certificate**
1157
+ + – The source certificate that was issued and signed by the certifier.
1158
+ + **keyring**
1159
+ + – A allows the verifier to decrypt selected certificate fields.
1160
+
1141
1161
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
1142
1162
 
1143
1163
  ---
package/docs/script.md CHANGED
@@ -756,6 +756,9 @@ export default class Spend {
756
756
  stack: number[][];
757
757
  altStack: number[][];
758
758
  ifStack: boolean[];
759
+ memoryLimit: number;
760
+ stackMem: number;
761
+ altStackMem: number;
759
762
  constructor(params: {
760
763
  sourceTXID: string;
761
764
  sourceOutputIndex: number;
@@ -768,9 +771,10 @@ export default class Spend {
768
771
  inputSequence: number;
769
772
  inputIndex: number;
770
773
  lockTime: number;
774
+ memoryLimit?: number;
771
775
  })
772
776
  reset(): void
773
- step(): void
777
+ step(): boolean
774
778
  validate(): boolean
775
779
  }
776
780
  ```
@@ -792,6 +796,7 @@ constructor(params: {
792
796
  inputSequence: number;
793
797
  inputIndex: number;
794
798
  lockTime: number;
799
+ memoryLimit?: number;
795
800
  })
796
801
  ```
797
802
  See also: [LockingScript](./script.md#class-lockingscript), [TransactionInput](./transaction.md#interface-transactioninput), [TransactionOutput](./transaction.md#interface-transactionoutput), [UnlockingScript](./script.md#class-unlockingscript)
@@ -837,6 +842,7 @@ const spend = new Spend({
837
842
  inputIndex: 0, // inputIndex
838
843
  unlockingScript: UnlockingScript.fromASM("3045... 02ab..."),
839
844
  inputSequence: 0xffffffff // inputSequence
845
+ memoryLimit: 100000 // memoryLimit
840
846
  });
841
847
  ```
842
848
 
@@ -1491,7 +1491,7 @@ export default class Transaction {
1491
1491
  id(): number[];
1492
1492
  id(enc: "hex"): string;
1493
1493
  id(enc?: "hex"): number[] | string
1494
- async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker(), feeModel?: FeeModel): Promise<boolean>
1494
+ async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker(), feeModel?: FeeModel, memoryLimit?: number): Promise<boolean>
1495
1495
  toBEEF(allowPartial?: boolean): number[]
1496
1496
  toAtomicBEEF(allowPartial?: boolean): number[]
1497
1497
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.4.22",
3
+ "version": "1.4.23",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -4,6 +4,7 @@ import type {
4
4
  CertificateFieldNameUnder50Bytes,
5
5
  HexString,
6
6
  OutpointString,
7
+ WalletCertificate,
7
8
  } from '../../wallet/Wallet.interfaces.js'
8
9
  import SymmetricKey from '../../primitives/SymmetricKey.js'
9
10
  import * as Utils from '../../primitives/utils.js'
@@ -50,6 +51,29 @@ export class VerifiableCertificate extends Certificate {
50
51
  this.decryptedFields = decryptedFields
51
52
  }
52
53
 
54
+ /**
55
+ *
56
+ * @param {WalletCertificate} certificate – The source certificate that was issued and signed by the certifier.
57
+ * @param {Record<CertificateFieldNameUnder50Bytes, string>} keyring – A allows the verifier to decrypt selected certificate fields.
58
+ * @returns {VerifiableCertificate} – A fully-formed instance containing the
59
+ * original certificate data plus the supplied keyring.
60
+ */
61
+ static fromCertificate(
62
+ certificate: WalletCertificate,
63
+ keyring: Record<CertificateFieldNameUnder50Bytes, string>
64
+ ): VerifiableCertificate {
65
+ return new VerifiableCertificate(
66
+ certificate.type,
67
+ certificate.serialNumber,
68
+ certificate.subject,
69
+ certificate.certifier,
70
+ certificate.revocationOutpoint,
71
+ certificate.fields,
72
+ keyring,
73
+ certificate.signature
74
+ )
75
+ }
76
+
53
77
  /**
54
78
  * Decrypts selectively revealed certificate fields using the provided keyring and verifier wallet
55
79
  * @param {ProtoWallet} verifierWallet - The wallet instance of the certificate's verifier, used to decrypt field keys.
@@ -1,8 +1,9 @@
1
1
  import { VerifiableCertificate } from '../../../auth/certificates/VerifiableCertificate'
2
+ import Certificate from '../../../auth/certificates/Certificate'
2
3
  import { PrivateKey, Utils } from '../../../../mod'
3
4
  import { CompletedProtoWallet } from '../../../auth/certificates/__tests/CompletedProtoWallet'
4
5
  import { MasterCertificate } from '../../../auth/certificates/MasterCertificate'
5
- import { ProtoWallet } from '../../../wallet/index'
6
+ import { ProtoWallet, WalletCertificate } from '../../../wallet/index'
6
7
 
7
8
  describe('VerifiableCertificate', () => {
8
9
  const subjectPrivateKey = PrivateKey.fromRandom()
@@ -149,4 +150,30 @@ describe('VerifiableCertificate', () => {
149
150
  expect(decrypted).toEqual(plaintextFields)
150
151
  })
151
152
  })
153
+
154
+ describe('fromCertificate', () => {
155
+ it('should create an equivalent VerifiableCertificate and decrypt correctly', async () => {
156
+ const baseCert = new Certificate(
157
+ verifiableCert.type,
158
+ verifiableCert.serialNumber,
159
+ verifiableCert.subject,
160
+ verifiableCert.certifier,
161
+ verifiableCert.revocationOutpoint,
162
+ verifiableCert.fields,
163
+ verifiableCert.signature
164
+ ) as WalletCertificate
165
+
166
+ const verifiable = VerifiableCertificate.fromCertificate(
167
+ baseCert,
168
+ verifiableCert.keyring
169
+ )
170
+
171
+ expect(verifiable).toBeInstanceOf(VerifiableCertificate)
172
+ expect(verifiable.serialNumber).toEqual(sampleSerialNumber)
173
+ expect(verifiable.keyring).toEqual(verifiableCert.keyring)
174
+
175
+ const decrypted = await verifiable.decryptFields(verifierWallet)
176
+ expect(decrypted).toEqual(plaintextFields)
177
+ })
178
+ })
152
179
  })
@@ -495,6 +495,8 @@ export class AuthFetch {
495
495
  }
496
496
  })
497
497
 
498
+
499
+
498
500
  // Attach the payment to the request headers
499
501
  config.headers = config.headers || {}
500
502
  config.headers['x-bsv-payment'] = JSON.stringify({