@smartledger/bsv 7.5.1 → 7.5.3

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
@@ -230,6 +230,11 @@ declare module '@smartledger/bsv' {
230
230
  static isValid(data: string): boolean;
231
231
  }
232
232
 
233
+ /**
234
+ * Callable with or without `new` — `bsv.Message(msg)` is the form the docs and
235
+ * examples use, and was previously untyped.
236
+ */
237
+ export function Message(message: string | Buffer): Message;
233
238
  export class Message {
234
239
  constructor(message: string | Buffer);
235
240
 
@@ -344,7 +349,13 @@ declare module '@smartledger/bsv' {
344
349
  function buildP2SHMultisigIn(pubkeys: PublicKey[], threshold: number, signatures: Buffer[], opts: object): Script;
345
350
  function buildPublicKeyHashOut(address: Address): Script;
346
351
  function buildPublicKeyOut(pubkey: PublicKey): Script;
352
+ /**
353
+ * Bare `OP_RETURN <data>`. Prefer buildSafeDataOut: a bare OP_RETURN is not
354
+ * provably unspendable.
355
+ */
347
356
  function buildDataOut(data: string | Buffer, encoding?: string): Script;
357
+ /** `OP_FALSE OP_RETURN <data>` — provably unspendable. Partner of isSafeDataOut(). */
358
+ function buildSafeDataOut(data: string | Buffer, encoding?: string): Script;
348
359
  function buildScriptHashOut(script: Script): Script;
349
360
  function buildPublicKeyIn(signature: crypto.Signature | Buffer, sigtype: number): Script;
350
361
  function buildPublicKeyHashIn(publicKey: PublicKey, signature: crypto.Signature | Buffer, sigtype: number): Script;
@@ -468,7 +479,7 @@ declare module '@smartledger/bsv' {
468
479
 
469
480
  function add(data: any): Network;
470
481
  function remove(network: Network): void;
471
- function get(args: string | number | Network, keys: string | string[]): Network;
482
+ function get(args: string | number | Network, keys?: string | string[]): Network;
472
483
  }
473
484
 
474
485
  export class Address {
@@ -624,27 +635,55 @@ declare module '@smartledger/bsv' {
624
635
 
625
636
  // -------- StatusList2021 --------------------------------------------
626
637
 
627
- export type CredentialStatus = 'valid' | 'revoked' | 'suspended' | string;
638
+ /**
639
+ * 'suspended' is part of the StatusList2021 vocabulary but is NOT writable here:
640
+ * this implementation hardcodes statusPurpose 'revocation' and uses one bit, so
641
+ * updateStatusList throws on it rather than recording a suspension as a revocation.
642
+ */
643
+ export type CredentialStatus = 'valid' | 'revoked' | 'suspended';
628
644
 
629
645
  export namespace StatusList {
646
+ /**
647
+ * Reading revocation state verifies the list JWT's signature and pins its issuer;
648
+ * both are required and were previously absent from these declarations.
649
+ */
650
+ interface StatusListReadParams {
651
+ listVcJwt: string;
652
+ index: number;
653
+ /** Required: the issuer this list must be signed by. */
654
+ expectedIssuerDid: string;
655
+ /** Supply exactly one key source. */
656
+ didResolver?: (did: string) => Promise<{ jwks: { keys: Jwk[] } }>;
657
+ issuerJwks?: { keys: Jwk[] };
658
+ issuerPublicJwk?: Jwk;
659
+ allowedAlgs?: string[];
660
+ }
630
661
  function createStatusList(params: {
631
662
  issuerDid: string;
632
663
  privateJwk: Jwk;
633
664
  listId?: string;
634
665
  listSize?: number;
635
666
  }): Promise<{ listVcJwt: string; listId: string }>;
636
- function updateStatusList(params: {
637
- listVcJwt: string;
638
- index: number;
667
+ /**
668
+ * Verifying the existing list before building on it requires pinning its issuer,
669
+ * so `expectedIssuerDid` plus one key source are mandatory at runtime.
670
+ */
671
+ function updateStatusList(params: StatusListReadParams & {
639
672
  status: CredentialStatus;
640
673
  privateJwk: Jwk;
641
674
  }): Promise<{ listVcJwt: string }>;
642
- function getCredentialStatusEntry(params: { listVcJwt: string; index: number }): CredentialStatus;
675
+ /**
676
+ * ASYNC — returns a Promise. Declared synchronous until 7.5.2, which meant
677
+ * `if (getCredentialStatusEntry(...) === 'revoked')` type-checked and was ALWAYS
678
+ * false, so every revoked credential passed. Await it.
679
+ */
680
+ function getCredentialStatusEntry(params: StatusListReadParams): Promise<CredentialStatus>;
643
681
  }
644
682
 
645
683
  // -------- Anchor (top-level hash anchoring) -------------------------
646
684
 
647
- export type AnchorKind = 'VC_ANCHOR_SHA256' | 'STATUSLIST_SHA256' | 'PRESENTATION_SHA256' | string;
685
+ /** Closed set: the runtime rejects anything else with "Invalid kind. Must be one of: ...". */
686
+ export type AnchorKind = 'VC_ANCHOR_SHA256' | 'STATUSLIST_SHA256' | 'PRESENTATION_SHA256';
648
687
 
649
688
  export interface AnchorPayload {
650
689
  json: object;
@@ -942,7 +981,8 @@ declare module '@smartledger/bsv' {
942
981
  /** Perpetually Enforcing Locking Script: every spend recreates the same script (value - fee). */
943
982
  function perpetualCovenant(fee: number): Script;
944
983
  /** Stateful ownership token (NFT) locking script. */
945
- function ownershipToken(fee: number, ownerHash: Buffer): Script;
984
+ /** Alias of SmartContract.Token.ownershipToken, authorizer included. */
985
+ function ownershipToken(fee: number, ownerHash: Buffer, auth?: SmartContract.Authorizer): Script;
946
986
  /** OP_PUSH_TX value/output covenant: coins can only go where the covenant says. */
947
987
  function valueCovenant(expectedHashOutputs: Buffer): Script;
948
988
  /** Ordinal covenant locking script (value-preserving; safe for 1-sat ordinals). */
@@ -1009,8 +1049,12 @@ declare module '@smartledger/bsv' {
1009
1049
  namespace Authorizers {
1010
1050
  /** Single-key (default): owner id = HASH160(pubkey). */
1011
1051
  function singleKey(): Authorizer;
1012
- /** m-of-n multisig authorizer. */
1013
- function multisig(m: number, keys: PublicKey[]): Authorizer;
1052
+ /**
1053
+ * m-of-n multisig authorizer. `nKeys` is the NUMBER of keys, not the keys —
1054
+ * the descriptor supplies them at spend time. (Locks.multisig genuinely does
1055
+ * take keys, which is what made this easy to walk into.)
1056
+ */
1057
+ function multisig(m: number, nKeys: number): Authorizer;
1014
1058
  /** Arbitrary predicate authorizer over a fixed 20-byte commitment. */
1015
1059
  function predicate(commit: Buffer, emit: (script: Script) => Script): Authorizer;
1016
1060
  }
@@ -1360,7 +1404,8 @@ declare module '@smartledger/bsv' {
1360
1404
  export function getClaimSchemaNames(): string[];
1361
1405
  export function getClaimSchema(schemaName: string): object;
1362
1406
  export function createClaimTemplate(schemaName: string): object;
1363
- export function canonicalizeClaim(claim: object): object;
1407
+ /** Returns the canonical JSON STRING, not an object. */
1408
+ export function canonicalizeClaim(claim: object): string;
1364
1409
  export function hashClaim(claim: object): string;
1365
1410
  export function addCustomClaimSchema(name: string, schema: object): void;
1366
1411