@smartledger/bsv 7.5.0 → 7.5.2
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/CHANGELOG.md +148 -0
- package/README.md +38 -38
- package/bsv-gdaf.min.js +33 -33
- package/bsv-ltp.min.js +33 -33
- package/bsv-smartcontract.min.js +2 -2
- package/bsv-statuslist.min.js +1 -1
- package/bsv.bundle.js +33 -33
- package/bsv.d.ts +101 -22
- package/bsv.min.js +33 -33
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/index.js +4 -1
- package/lib/gdaf/index.js +29 -6
- package/lib/gdaf/smartledger-anchor.js +31 -1
- package/lib/privatekey.js +59 -10
- package/lib/smart_contract/authorizers.js +8 -0
- package/lib/smart_contract/index.js +4 -2
- package/lib/statuslist/index.js +11 -3
- package/package.json +12 -1
- package/test/gdaf/anchor_no_key_leak.js +88 -0
- package/test/privatekey.js +79 -2
- package/test/types/dts_drift.js +23 -1
- package/test/types/surface_honesty.js +102 -0
- package/version.js +1 -1
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
|
-
|
|
180
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
static
|
|
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
|
}
|
|
@@ -219,6 +230,11 @@ declare module '@smartledger/bsv' {
|
|
|
219
230
|
static isValid(data: string): boolean;
|
|
220
231
|
}
|
|
221
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;
|
|
222
238
|
export class Message {
|
|
223
239
|
constructor(message: string | Buffer);
|
|
224
240
|
|
|
@@ -333,7 +349,13 @@ declare module '@smartledger/bsv' {
|
|
|
333
349
|
function buildP2SHMultisigIn(pubkeys: PublicKey[], threshold: number, signatures: Buffer[], opts: object): Script;
|
|
334
350
|
function buildPublicKeyHashOut(address: Address): Script;
|
|
335
351
|
function buildPublicKeyOut(pubkey: PublicKey): Script;
|
|
352
|
+
/**
|
|
353
|
+
* Bare `OP_RETURN <data>`. Prefer buildSafeDataOut: a bare OP_RETURN is not
|
|
354
|
+
* provably unspendable.
|
|
355
|
+
*/
|
|
336
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;
|
|
337
359
|
function buildScriptHashOut(script: Script): Script;
|
|
338
360
|
function buildPublicKeyIn(signature: crypto.Signature | Buffer, sigtype: number): Script;
|
|
339
361
|
function buildPublicKeyHashIn(publicKey: PublicKey, signature: crypto.Signature | Buffer, sigtype: number): Script;
|
|
@@ -457,7 +479,7 @@ declare module '@smartledger/bsv' {
|
|
|
457
479
|
|
|
458
480
|
function add(data: any): Network;
|
|
459
481
|
function remove(network: Network): void;
|
|
460
|
-
function get(args: string | number | Network, keys
|
|
482
|
+
function get(args: string | number | Network, keys?: string | string[]): Network;
|
|
461
483
|
}
|
|
462
484
|
|
|
463
485
|
export class Address {
|
|
@@ -613,27 +635,55 @@ declare module '@smartledger/bsv' {
|
|
|
613
635
|
|
|
614
636
|
// -------- StatusList2021 --------------------------------------------
|
|
615
637
|
|
|
616
|
-
|
|
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';
|
|
617
644
|
|
|
618
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
|
+
}
|
|
619
661
|
function createStatusList(params: {
|
|
620
662
|
issuerDid: string;
|
|
621
663
|
privateJwk: Jwk;
|
|
622
664
|
listId?: string;
|
|
623
665
|
listSize?: number;
|
|
624
666
|
}): Promise<{ listVcJwt: string; listId: string }>;
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
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 & {
|
|
628
672
|
status: CredentialStatus;
|
|
629
673
|
privateJwk: Jwk;
|
|
630
674
|
}): Promise<{ listVcJwt: string }>;
|
|
631
|
-
|
|
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>;
|
|
632
681
|
}
|
|
633
682
|
|
|
634
683
|
// -------- Anchor (top-level hash anchoring) -------------------------
|
|
635
684
|
|
|
636
|
-
|
|
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';
|
|
637
687
|
|
|
638
688
|
export interface AnchorPayload {
|
|
639
689
|
json: object;
|
|
@@ -712,6 +762,24 @@ declare module '@smartledger/bsv' {
|
|
|
712
762
|
|
|
713
763
|
// -------- GDAF (Global Digital Attestation Framework) ---------------
|
|
714
764
|
|
|
765
|
+
/** A spendable output supplied to the anchoring helpers. */
|
|
766
|
+
export interface Utxo {
|
|
767
|
+
txId: string;
|
|
768
|
+
outputIndex: number;
|
|
769
|
+
script: string;
|
|
770
|
+
satoshis: number;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
export interface AnchorOptions {
|
|
774
|
+
/** UTXOs funding the anchor transaction. */
|
|
775
|
+
utxos?: Utxo[];
|
|
776
|
+
/**
|
|
777
|
+
* Serialised into the OP_RETURN: PUBLIC AND PERMANENT. Anchoring a PrivateKey, or
|
|
778
|
+
* any key-shaped field (`bn`, `wif`, `privateJwk`, `seed`, `xprv`, ...), throws.
|
|
779
|
+
*/
|
|
780
|
+
metadata?: object;
|
|
781
|
+
}
|
|
782
|
+
|
|
715
783
|
export class GDAF {
|
|
716
784
|
constructor(options?: {
|
|
717
785
|
attestationSigner?: object;
|
|
@@ -747,10 +815,15 @@ declare module '@smartledger/bsv' {
|
|
|
747
815
|
verifyMembershipProof(proof: object, validSet: string[]): boolean;
|
|
748
816
|
|
|
749
817
|
// Anchoring
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
818
|
+
/**
|
|
819
|
+
* Anchor options. `metadata` is JSON-serialised into the OP_RETURN and is therefore
|
|
820
|
+
* PUBLIC AND PERMANENT — anchoring anything key-shaped throws. A bare UTXO array is
|
|
821
|
+
* also accepted in place of this object.
|
|
822
|
+
*/
|
|
823
|
+
anchorCredential(credentialHash: string | Buffer, privateKey: PrivateKey, options?: AnchorOptions | Utxo[]): Promise<object>;
|
|
824
|
+
anchorBatch(credentialHashes: Array<string | Buffer>, privateKey: PrivateKey, options?: AnchorOptions | Utxo[]): Promise<object>;
|
|
825
|
+
registerDID(did: string, didDocument: object, privateKey: PrivateKey, options?: AnchorOptions | Utxo[]): Promise<object>;
|
|
826
|
+
revokeCredential(credentialId: string, reason: string, privateKey: PrivateKey, options?: AnchorOptions | Utxo[]): Promise<object>;
|
|
754
827
|
queryAnchoredData(hash: string): object;
|
|
755
828
|
|
|
756
829
|
// Schemas
|
|
@@ -908,7 +981,8 @@ declare module '@smartledger/bsv' {
|
|
|
908
981
|
/** Perpetually Enforcing Locking Script: every spend recreates the same script (value - fee). */
|
|
909
982
|
function perpetualCovenant(fee: number): Script;
|
|
910
983
|
/** Stateful ownership token (NFT) locking script. */
|
|
911
|
-
|
|
984
|
+
/** Alias of SmartContract.Token.ownershipToken, authorizer included. */
|
|
985
|
+
function ownershipToken(fee: number, ownerHash: Buffer, auth?: SmartContract.Authorizer): Script;
|
|
912
986
|
/** OP_PUSH_TX value/output covenant: coins can only go where the covenant says. */
|
|
913
987
|
function valueCovenant(expectedHashOutputs: Buffer): Script;
|
|
914
988
|
/** Ordinal covenant locking script (value-preserving; safe for 1-sat ordinals). */
|
|
@@ -975,8 +1049,12 @@ declare module '@smartledger/bsv' {
|
|
|
975
1049
|
namespace Authorizers {
|
|
976
1050
|
/** Single-key (default): owner id = HASH160(pubkey). */
|
|
977
1051
|
function singleKey(): Authorizer;
|
|
978
|
-
/**
|
|
979
|
-
|
|
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;
|
|
980
1058
|
/** Arbitrary predicate authorizer over a fixed 20-byte commitment. */
|
|
981
1059
|
function predicate(commit: Buffer, emit: (script: Script) => Script): Authorizer;
|
|
982
1060
|
}
|
|
@@ -1326,7 +1404,8 @@ declare module '@smartledger/bsv' {
|
|
|
1326
1404
|
export function getClaimSchemaNames(): string[];
|
|
1327
1405
|
export function getClaimSchema(schemaName: string): object;
|
|
1328
1406
|
export function createClaimTemplate(schemaName: string): object;
|
|
1329
|
-
|
|
1407
|
+
/** Returns the canonical JSON STRING, not an object. */
|
|
1408
|
+
export function canonicalizeClaim(claim: object): string;
|
|
1330
1409
|
export function hashClaim(claim: object): string;
|
|
1331
1410
|
export function addCustomClaimSchema(name: string, schema: object): void;
|
|
1332
1411
|
|