@smartledger/bsv 7.4.0 → 7.5.1

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/bsv.d.ts CHANGED
@@ -176,19 +176,30 @@ declare module '@smartledger/bsv' {
176
176
  toAddress(): Address;
177
177
  toPublicKey(): PublicKey;
178
178
  toString(): string;
179
- toObject(): object;
180
- toJSON(): object;
179
+ /** Deliberate export, INCLUDING the secret scalar. Round-trips with fromObject(). */
180
+ toObject(): { bn: string; compressed: boolean; network: string };
181
+ /**
182
+ * What JSON.stringify() calls — the scalar is REDACTED. Use toObject() or toWIF()
183
+ * when you actually intend to export the secret.
184
+ */
185
+ toJSON(): { bn: '[REDACTED]'; compressed: boolean; network: string };
181
186
  toWIF(): string;
182
187
  toHex(): string;
183
188
  toBigNumber(): any; //BN;
184
189
  toBuffer(): Buffer;
185
190
  inspect(): string;
186
191
 
187
- static fromString(str: string): PrivateKey;
188
- static fromWIF(str: string): PrivateKey;
189
- static fromRandom(netowrk?: string): PrivateKey;
190
- static fromBuffer(buf: Buffer, network: string | Networks.Network): PrivateKey;
191
- static fromHex(hex: string, network: string | Networks.Network): PrivateKey;
192
+ /**
193
+ * From a WIF string, or a hex-encoded scalar. `network` is honoured; for a WIF,
194
+ * which encodes its own network, a conflicting value throws.
195
+ */
196
+ static fromString(str: string, network?: string | Networks.Network): PrivateKey;
197
+ static fromWIF(str: string, network?: string | Networks.Network): PrivateKey;
198
+ static fromRandom(network?: string): PrivateKey;
199
+ /** `compressed` defaults to true, matching every other constructor path. */
200
+ static fromBuffer(buf: Buffer, network?: string | Networks.Network, compressed?: boolean): PrivateKey;
201
+ /** `compressed` defaults to true, matching every other constructor path. */
202
+ static fromHex(hex: string, network?: string | Networks.Network, compressed?: boolean): PrivateKey;
192
203
  static getValidationError(data: string): any | null;
193
204
  static isValid(data: string): boolean;
194
205
  }
@@ -344,20 +355,33 @@ declare module '@smartledger/bsv' {
344
355
  namespace Interpreter {
345
356
  const SCRIPT_ENABLE_SIGHASH_FORKID: any;
346
357
 
347
- // Pre-Genesis consensus caps (defaults: 520 / 4 / 201).
358
+ // Pre-Genesis consensus caps (defaults: 520 / 4 / 201 / 10,000).
348
359
  // Mutable: see useGenesisLimits() for a one-call opt-in.
349
360
  let MAX_SCRIPT_ELEMENT_SIZE: number;
350
361
  let MAXIMUM_ELEMENT_SIZE: number;
351
362
  let MAX_OPS_PER_SCRIPT: number;
363
+ /** Total serialized script size. Anything larger fails SCRIPT_ERR_SCRIPT_SIZE. */
364
+ let MAX_SCRIPT_SIZE: number;
365
+
366
+ interface Limits {
367
+ maxScriptElementSize: number;
368
+ maximumElementSize: number;
369
+ maxOpsPerScript: number;
370
+ maxScriptSize: number;
371
+ }
352
372
 
353
373
  /**
354
374
  * Opt into post-Genesis BSV consensus limits (no caps on stack
355
- * element size, script-number width, or opcode count). Mutates
356
- * Interpreter-wide static state — call once at app startup.
357
- * Pass an explicit `max` (e.g. 64 KB) when verifying scripts
358
- * from untrusted sources.
375
+ * element size, script-number width, opcode count, or total script
376
+ * size). Mutates Interpreter-wide static state — call once at app
377
+ * startup. Pass an explicit `max` (e.g. 64 KB) when verifying
378
+ * scripts from untrusted sources.
359
379
  */
360
380
  function useGenesisLimits(max?: number): typeof Interpreter;
381
+ /** Capture the four caps, for restoring with setLimits(). */
382
+ function getLimits(): Limits;
383
+ /** Restore caps captured by getLimits(). */
384
+ function setLimits(limits: Partial<Limits>): typeof Interpreter;
361
385
  }
362
386
 
363
387
  function Interpreter(): {
@@ -699,6 +723,24 @@ declare module '@smartledger/bsv' {
699
723
 
700
724
  // -------- GDAF (Global Digital Attestation Framework) ---------------
701
725
 
726
+ /** A spendable output supplied to the anchoring helpers. */
727
+ export interface Utxo {
728
+ txId: string;
729
+ outputIndex: number;
730
+ script: string;
731
+ satoshis: number;
732
+ }
733
+
734
+ export interface AnchorOptions {
735
+ /** UTXOs funding the anchor transaction. */
736
+ utxos?: Utxo[];
737
+ /**
738
+ * Serialised into the OP_RETURN: PUBLIC AND PERMANENT. Anchoring a PrivateKey, or
739
+ * any key-shaped field (`bn`, `wif`, `privateJwk`, `seed`, `xprv`, ...), throws.
740
+ */
741
+ metadata?: object;
742
+ }
743
+
702
744
  export class GDAF {
703
745
  constructor(options?: {
704
746
  attestationSigner?: object;
@@ -734,10 +776,15 @@ declare module '@smartledger/bsv' {
734
776
  verifyMembershipProof(proof: object, validSet: string[]): boolean;
735
777
 
736
778
  // Anchoring
737
- anchorCredential(credential: object, privateKey: PrivateKey, options?: object): object;
738
- anchorBatch(credentials: object[], privateKey: PrivateKey, options?: object): object;
739
- registerDID(did: string, didDocument: object, privateKey: PrivateKey, options?: object): object;
740
- revokeCredential(credentialId: string, reason: string, privateKey: PrivateKey, options?: object): object;
779
+ /**
780
+ * Anchor options. `metadata` is JSON-serialised into the OP_RETURN and is therefore
781
+ * PUBLIC AND PERMANENT — anchoring anything key-shaped throws. A bare UTXO array is
782
+ * also accepted in place of this object.
783
+ */
784
+ anchorCredential(credentialHash: string | Buffer, privateKey: PrivateKey, options?: AnchorOptions | Utxo[]): Promise<object>;
785
+ anchorBatch(credentialHashes: Array<string | Buffer>, privateKey: PrivateKey, options?: AnchorOptions | Utxo[]): Promise<object>;
786
+ registerDID(did: string, didDocument: object, privateKey: PrivateKey, options?: AnchorOptions | Utxo[]): Promise<object>;
787
+ revokeCredential(credentialId: string, reason: string, privateKey: PrivateKey, options?: AnchorOptions | Utxo[]): Promise<object>;
741
788
  queryAnchoredData(hash: string): object;
742
789
 
743
790
  // Schemas