@bsv/sdk 1.2.10 → 1.2.12
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/README.md +5 -2
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/primitives/PrivateKey.js +40 -2
- package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
- package/dist/cjs/src/transaction/Broadcaster.js.map +1 -1
- package/dist/cjs/src/wallet/WalletClient.js +11 -1
- package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js +113 -0
- package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/primitives/PrivateKey.js +40 -2
- package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
- package/dist/esm/src/transaction/Broadcaster.js.map +1 -1
- package/dist/esm/src/wallet/WalletClient.js +11 -1
- package/dist/esm/src/wallet/WalletClient.js.map +1 -1
- package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js +114 -0
- package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/primitives/PrivateKey.d.ts +33 -1
- package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
- package/dist/types/src/transaction/Broadcaster.d.ts +3 -0
- package/dist/types/src/transaction/Broadcaster.d.ts.map +1 -1
- package/dist/types/src/wallet/WalletClient.d.ts +1 -1
- package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts +189 -0
- package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/README.md +9 -0
- package/docs/primitives.md +73 -3
- package/docs/swagger/dist/LICENSE +21 -0
- package/docs/swagger/dist/favicon-16x16.png +0 -0
- package/docs/swagger/dist/favicon-32x32.png +0 -0
- package/docs/swagger/dist/index.css +16 -0
- package/docs/swagger/dist/oauth2-redirect.html +79 -0
- package/docs/swagger/dist/swagger-initializer.js +20 -0
- package/docs/swagger/dist/swagger-ui-bundle.js +2 -0
- package/docs/swagger/dist/swagger-ui-bundle.js.map +1 -0
- package/docs/swagger/dist/swagger-ui-es-bundle-core.js +3 -0
- package/docs/swagger/dist/swagger-ui-es-bundle-core.js.map +1 -0
- package/docs/swagger/dist/swagger-ui-es-bundle.js +2 -0
- package/docs/swagger/dist/swagger-ui-es-bundle.js.map +1 -0
- package/docs/swagger/dist/swagger-ui-standalone-preset.js +2 -0
- package/docs/swagger/dist/swagger-ui-standalone-preset.js.map +1 -0
- package/docs/swagger/dist/swagger-ui.css +3 -0
- package/docs/swagger/dist/swagger-ui.css.map +1 -0
- package/docs/swagger/dist/swagger-ui.js +2 -0
- package/docs/swagger/dist/swagger-ui.js.map +1 -0
- package/docs/swagger/index.html +19 -0
- package/docs/swagger/swagger-ui.version +1 -0
- package/docs/swagger/swagger.yaml +1449 -0
- package/docs/transaction.md +1 -0
- package/docs/wallet.md +226 -1
- package/package.json +1 -1
- package/src/primitives/PrivateKey.ts +43 -2
- package/src/primitives/__tests/PrivateKey.test.ts +87 -7
- package/src/transaction/Broadcaster.ts +4 -0
- package/src/wallet/WalletClient.ts +10 -2
- package/src/wallet/substrates/HTTPWalletJSON.ts +143 -0
package/docs/transaction.md
CHANGED
|
@@ -135,6 +135,7 @@ This interface defines a standard method for broadcasting transactions.
|
|
|
135
135
|
```ts
|
|
136
136
|
export interface Broadcaster {
|
|
137
137
|
broadcast: (transaction: Transaction) => Promise<BroadcastResponse | BroadcastFailure>;
|
|
138
|
+
broadcastMany?: (txs: Transaction[]) => Promise<Array<object>>;
|
|
138
139
|
}
|
|
139
140
|
```
|
|
140
141
|
|
package/docs/wallet.md
CHANGED
|
@@ -1294,6 +1294,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
1294
1294
|
| |
|
|
1295
1295
|
| --- |
|
|
1296
1296
|
| [CachedKeyDeriver](#class-cachedkeyderiver) |
|
|
1297
|
+
| [HTTPWalletJSON](#class-httpwalletjson) |
|
|
1297
1298
|
| [HTTPWalletWire](#class-httpwalletwire) |
|
|
1298
1299
|
| [KeyDeriver](#class-keyderiver) |
|
|
1299
1300
|
| [ProtoWallet](#class-protowallet) |
|
|
@@ -1500,6 +1501,230 @@ Argument Details
|
|
|
1500
1501
|
|
|
1501
1502
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
1502
1503
|
|
|
1504
|
+
---
|
|
1505
|
+
### Class: HTTPWalletJSON
|
|
1506
|
+
|
|
1507
|
+
```ts
|
|
1508
|
+
export default class HTTPWalletJSON implements Wallet {
|
|
1509
|
+
baseUrl: string;
|
|
1510
|
+
httpClient: typeof fetch;
|
|
1511
|
+
originator: OriginatorDomainNameStringUnder250Bytes | undefined;
|
|
1512
|
+
api: (call: string, args: any) => Promise<any>;
|
|
1513
|
+
constructor(originator: OriginatorDomainNameStringUnder250Bytes | undefined, baseUrl: string = "http://localhost:3321", httpClient = fetch)
|
|
1514
|
+
async createAction(args: CreateActionArgs): Promise<CreateActionResult>
|
|
1515
|
+
async signAction(args: SignActionArgs): Promise<SignActionResult>
|
|
1516
|
+
async abortAction(args: {
|
|
1517
|
+
reference: Base64String;
|
|
1518
|
+
}): Promise<{
|
|
1519
|
+
aborted: true;
|
|
1520
|
+
}>
|
|
1521
|
+
async listActions(args: ListActionsArgs): Promise<ListActionsResult>
|
|
1522
|
+
async internalizeAction(args: InternalizeActionArgs): Promise<{
|
|
1523
|
+
accepted: true;
|
|
1524
|
+
}>
|
|
1525
|
+
async listOutputs(args: ListOutputsArgs): Promise<ListOutputsResult>
|
|
1526
|
+
async relinquishOutput(args: {
|
|
1527
|
+
basket: BasketStringUnder300Bytes;
|
|
1528
|
+
output: OutpointString;
|
|
1529
|
+
}): Promise<{
|
|
1530
|
+
relinquished: true;
|
|
1531
|
+
}>
|
|
1532
|
+
async getPublicKey(args: {
|
|
1533
|
+
seekPermission?: BooleanDefaultTrue;
|
|
1534
|
+
identityKey?: true;
|
|
1535
|
+
protocolID?: [
|
|
1536
|
+
SecurityLevel,
|
|
1537
|
+
ProtocolString5To400Bytes
|
|
1538
|
+
];
|
|
1539
|
+
keyID?: KeyIDStringUnder800Bytes;
|
|
1540
|
+
privileged?: BooleanDefaultFalse;
|
|
1541
|
+
privilegedReason?: DescriptionString5to50Bytes;
|
|
1542
|
+
counterparty?: PubKeyHex | "self" | "anyone";
|
|
1543
|
+
forSelf?: BooleanDefaultFalse;
|
|
1544
|
+
}): Promise<{
|
|
1545
|
+
publicKey: PubKeyHex;
|
|
1546
|
+
}>
|
|
1547
|
+
async revealCounterpartyKeyLinkage(args: {
|
|
1548
|
+
counterparty: PubKeyHex;
|
|
1549
|
+
verifier: PubKeyHex;
|
|
1550
|
+
privilegedReason?: DescriptionString5to50Bytes;
|
|
1551
|
+
privileged?: BooleanDefaultFalse;
|
|
1552
|
+
}): Promise<{
|
|
1553
|
+
prover: PubKeyHex;
|
|
1554
|
+
verifier: PubKeyHex;
|
|
1555
|
+
counterparty: PubKeyHex;
|
|
1556
|
+
revelationTime: ISOTimestampString;
|
|
1557
|
+
encryptedLinkage: Byte[];
|
|
1558
|
+
encryptedLinkageProof: number[];
|
|
1559
|
+
}>
|
|
1560
|
+
async revealSpecificKeyLinkage(args: {
|
|
1561
|
+
counterparty: PubKeyHex;
|
|
1562
|
+
verifier: PubKeyHex;
|
|
1563
|
+
protocolID: [
|
|
1564
|
+
SecurityLevel,
|
|
1565
|
+
ProtocolString5To400Bytes
|
|
1566
|
+
];
|
|
1567
|
+
keyID: KeyIDStringUnder800Bytes;
|
|
1568
|
+
privilegedReason?: DescriptionString5to50Bytes;
|
|
1569
|
+
privileged?: BooleanDefaultFalse;
|
|
1570
|
+
}): Promise<{
|
|
1571
|
+
prover: PubKeyHex;
|
|
1572
|
+
verifier: PubKeyHex;
|
|
1573
|
+
counterparty: PubKeyHex;
|
|
1574
|
+
protocolID: [
|
|
1575
|
+
SecurityLevel,
|
|
1576
|
+
ProtocolString5To400Bytes
|
|
1577
|
+
];
|
|
1578
|
+
keyID: KeyIDStringUnder800Bytes;
|
|
1579
|
+
encryptedLinkage: Byte[];
|
|
1580
|
+
encryptedLinkageProof: Byte[];
|
|
1581
|
+
proofType: Byte;
|
|
1582
|
+
}>
|
|
1583
|
+
async encrypt(args: {
|
|
1584
|
+
seekPermission?: BooleanDefaultTrue;
|
|
1585
|
+
plaintext: Byte[];
|
|
1586
|
+
protocolID: [
|
|
1587
|
+
SecurityLevel,
|
|
1588
|
+
ProtocolString5To400Bytes
|
|
1589
|
+
];
|
|
1590
|
+
keyID: KeyIDStringUnder800Bytes;
|
|
1591
|
+
privilegedReason?: DescriptionString5to50Bytes;
|
|
1592
|
+
counterparty?: PubKeyHex | "self" | "anyone";
|
|
1593
|
+
privileged?: BooleanDefaultFalse;
|
|
1594
|
+
}): Promise<{
|
|
1595
|
+
ciphertext: Byte[];
|
|
1596
|
+
}>
|
|
1597
|
+
async decrypt(args: {
|
|
1598
|
+
seekPermission?: BooleanDefaultTrue;
|
|
1599
|
+
ciphertext: Byte[];
|
|
1600
|
+
protocolID: [
|
|
1601
|
+
SecurityLevel,
|
|
1602
|
+
ProtocolString5To400Bytes
|
|
1603
|
+
];
|
|
1604
|
+
keyID: KeyIDStringUnder800Bytes;
|
|
1605
|
+
privilegedReason?: DescriptionString5to50Bytes;
|
|
1606
|
+
counterparty?: PubKeyHex | "self" | "anyone";
|
|
1607
|
+
privileged?: BooleanDefaultFalse;
|
|
1608
|
+
}): Promise<{
|
|
1609
|
+
plaintext: Byte[];
|
|
1610
|
+
}>
|
|
1611
|
+
async createHmac(args: {
|
|
1612
|
+
seekPermission?: BooleanDefaultTrue;
|
|
1613
|
+
data: Byte[];
|
|
1614
|
+
protocolID: [
|
|
1615
|
+
SecurityLevel,
|
|
1616
|
+
ProtocolString5To400Bytes
|
|
1617
|
+
];
|
|
1618
|
+
keyID: KeyIDStringUnder800Bytes;
|
|
1619
|
+
privilegedReason?: DescriptionString5to50Bytes;
|
|
1620
|
+
counterparty?: PubKeyHex | "self" | "anyone";
|
|
1621
|
+
privileged?: BooleanDefaultFalse;
|
|
1622
|
+
}): Promise<{
|
|
1623
|
+
hmac: Byte[];
|
|
1624
|
+
}>
|
|
1625
|
+
async verifyHmac(args: {
|
|
1626
|
+
seekPermission?: BooleanDefaultTrue;
|
|
1627
|
+
data: Byte[];
|
|
1628
|
+
hmac: Byte[];
|
|
1629
|
+
protocolID: [
|
|
1630
|
+
SecurityLevel,
|
|
1631
|
+
ProtocolString5To400Bytes
|
|
1632
|
+
];
|
|
1633
|
+
keyID: KeyIDStringUnder800Bytes;
|
|
1634
|
+
privilegedReason?: DescriptionString5to50Bytes;
|
|
1635
|
+
counterparty?: PubKeyHex | "self" | "anyone";
|
|
1636
|
+
privileged?: BooleanDefaultFalse;
|
|
1637
|
+
}): Promise<{
|
|
1638
|
+
valid: true;
|
|
1639
|
+
}>
|
|
1640
|
+
async createSignature(args: {
|
|
1641
|
+
seekPermission?: BooleanDefaultTrue;
|
|
1642
|
+
data?: Byte[];
|
|
1643
|
+
hashToDirectlySign?: Byte[];
|
|
1644
|
+
protocolID: [
|
|
1645
|
+
SecurityLevel,
|
|
1646
|
+
ProtocolString5To400Bytes
|
|
1647
|
+
];
|
|
1648
|
+
keyID: KeyIDStringUnder800Bytes;
|
|
1649
|
+
privilegedReason?: DescriptionString5to50Bytes;
|
|
1650
|
+
counterparty?: PubKeyHex | "self" | "anyone";
|
|
1651
|
+
privileged?: BooleanDefaultFalse;
|
|
1652
|
+
}): Promise<{
|
|
1653
|
+
signature: Byte[];
|
|
1654
|
+
}>
|
|
1655
|
+
async verifySignature(args: {
|
|
1656
|
+
seekPermission?: BooleanDefaultTrue;
|
|
1657
|
+
data?: Byte[];
|
|
1658
|
+
hashToDirectlyVerify?: Byte[];
|
|
1659
|
+
signature: Byte[];
|
|
1660
|
+
protocolID: [
|
|
1661
|
+
SecurityLevel,
|
|
1662
|
+
ProtocolString5To400Bytes
|
|
1663
|
+
];
|
|
1664
|
+
keyID: KeyIDStringUnder800Bytes;
|
|
1665
|
+
privilegedReason?: DescriptionString5to50Bytes;
|
|
1666
|
+
counterparty?: PubKeyHex | "self" | "anyone";
|
|
1667
|
+
forSelf?: BooleanDefaultFalse;
|
|
1668
|
+
privileged?: BooleanDefaultFalse;
|
|
1669
|
+
}): Promise<{
|
|
1670
|
+
valid: true;
|
|
1671
|
+
}>
|
|
1672
|
+
async acquireCertificate(args: AcquireCertificateArgs): Promise<AcquireCertificateResult>
|
|
1673
|
+
async listCertificates(args: {
|
|
1674
|
+
certifiers: PubKeyHex[];
|
|
1675
|
+
types: Base64String[];
|
|
1676
|
+
limit?: PositiveIntegerDefault10Max10000;
|
|
1677
|
+
offset?: PositiveIntegerOrZero;
|
|
1678
|
+
privileged?: BooleanDefaultFalse;
|
|
1679
|
+
privilegedReason?: DescriptionString5to50Bytes;
|
|
1680
|
+
}): Promise<ListCertificatesResult>
|
|
1681
|
+
async proveCertificate(args: ProveCertificateArgs): Promise<ProveCertificateResult>
|
|
1682
|
+
async relinquishCertificate(args: {
|
|
1683
|
+
type: Base64String;
|
|
1684
|
+
serialNumber: Base64String;
|
|
1685
|
+
certifier: PubKeyHex;
|
|
1686
|
+
}): Promise<{
|
|
1687
|
+
relinquished: true;
|
|
1688
|
+
}>
|
|
1689
|
+
async discoverByIdentityKey(args: {
|
|
1690
|
+
seekPermission?: BooleanDefaultTrue;
|
|
1691
|
+
identityKey: PubKeyHex;
|
|
1692
|
+
limit?: PositiveIntegerDefault10Max10000;
|
|
1693
|
+
offset?: PositiveIntegerOrZero;
|
|
1694
|
+
}): Promise<DiscoverCertificatesResult>
|
|
1695
|
+
async discoverByAttributes(args: {
|
|
1696
|
+
seekPermission?: BooleanDefaultTrue;
|
|
1697
|
+
attributes: Record<CertificateFieldNameUnder50Bytes, string>;
|
|
1698
|
+
limit?: PositiveIntegerDefault10Max10000;
|
|
1699
|
+
offset?: PositiveIntegerOrZero;
|
|
1700
|
+
}): Promise<DiscoverCertificatesResult>
|
|
1701
|
+
async isAuthenticated(args: {}): Promise<{
|
|
1702
|
+
authenticated: boolean;
|
|
1703
|
+
}>
|
|
1704
|
+
async waitForAuthentication(args: {}): Promise<{
|
|
1705
|
+
authenticated: true;
|
|
1706
|
+
}>
|
|
1707
|
+
async getHeight(args: {}): Promise<{
|
|
1708
|
+
height: PositiveInteger;
|
|
1709
|
+
}>
|
|
1710
|
+
async getHeaderForHeight(args: {
|
|
1711
|
+
height: PositiveInteger;
|
|
1712
|
+
}): Promise<{
|
|
1713
|
+
header: HexString;
|
|
1714
|
+
}>
|
|
1715
|
+
async getNetwork(args: {}): Promise<{
|
|
1716
|
+
network: "mainnet" | "testnet";
|
|
1717
|
+
}>
|
|
1718
|
+
async getVersion(args: {}): Promise<{
|
|
1719
|
+
version: VersionString7To30Bytes;
|
|
1720
|
+
}>
|
|
1721
|
+
}
|
|
1722
|
+
```
|
|
1723
|
+
|
|
1724
|
+
See also: [AcquireCertificateArgs](#interface-acquirecertificateargs), [AcquireCertificateResult](#interface-acquirecertificateresult), [Base64String](#type-base64string), [BasketStringUnder300Bytes](#type-basketstringunder300bytes), [BooleanDefaultFalse](#type-booleandefaultfalse), [BooleanDefaultTrue](#type-booleandefaulttrue), [Byte](#type-byte), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [CreateActionArgs](#interface-createactionargs), [CreateActionResult](#interface-createactionresult), [DescriptionString5to50Bytes](#type-descriptionstring5to50bytes), [DiscoverCertificatesResult](#interface-discovercertificatesresult), [HexString](#type-hexstring), [ISOTimestampString](#type-isotimestampstring), [InternalizeActionArgs](#interface-internalizeactionargs), [KeyIDStringUnder800Bytes](#type-keyidstringunder800bytes), [ListActionsArgs](#interface-listactionsargs), [ListActionsResult](#interface-listactionsresult), [ListCertificatesResult](#interface-listcertificatesresult), [ListOutputsArgs](#interface-listoutputsargs), [ListOutputsResult](#interface-listoutputsresult), [OriginatorDomainNameStringUnder250Bytes](#type-originatordomainnamestringunder250bytes), [OutpointString](#type-outpointstring), [PositiveInteger](#type-positiveinteger), [PositiveIntegerDefault10Max10000](#type-positiveintegerdefault10max10000), [PositiveIntegerOrZero](#type-positiveintegerorzero), [ProtocolString5To400Bytes](#type-protocolstring5to400bytes), [ProveCertificateArgs](#interface-provecertificateargs), [ProveCertificateResult](#interface-provecertificateresult), [PubKeyHex](#type-pubkeyhex), [SecurityLevel](#type-securitylevel), [SignActionArgs](#interface-signactionargs), [SignActionResult](#interface-signactionresult), [VersionString7To30Bytes](#type-versionstring7to30bytes), [Wallet](#interface-wallet), [decrypt](#variable-decrypt), [encrypt](#variable-encrypt)
|
|
1725
|
+
|
|
1726
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
1727
|
+
|
|
1503
1728
|
---
|
|
1504
1729
|
### Class: HTTPWalletWire
|
|
1505
1730
|
|
|
@@ -2157,7 +2382,7 @@ The SDK is how applications communicate with wallets over a communications subst
|
|
|
2157
2382
|
export default class WalletClient implements Wallet {
|
|
2158
2383
|
public substrate: "auto" | Wallet;
|
|
2159
2384
|
originator?: OriginatorDomainNameStringUnder250Bytes;
|
|
2160
|
-
constructor(substrate: "auto" | "Cicada" | "XDM" | "window.CWI" | Wallet = "auto", originator?: OriginatorDomainNameStringUnder250Bytes)
|
|
2385
|
+
constructor(substrate: "auto" | "Cicada" | "XDM" | "window.CWI" | "json-api" | Wallet = "auto", originator?: OriginatorDomainNameStringUnder250Bytes)
|
|
2161
2386
|
async connectToSubstrate()
|
|
2162
2387
|
async createAction(args: CreateActionArgs): Promise<CreateActionResult>
|
|
2163
2388
|
async signAction(args: SignActionArgs): Promise<SignActionResult>
|
package/package.json
CHANGED
|
@@ -93,8 +93,21 @@ export default class PrivateKey extends BigNumber {
|
|
|
93
93
|
* @returns The generated Private Key.
|
|
94
94
|
* @throws Will throw an error if the string is not valid.
|
|
95
95
|
**/
|
|
96
|
-
static fromString (str: string, base: number | 'hex'): PrivateKey {
|
|
97
|
-
return new PrivateKey(
|
|
96
|
+
static fromString (str: string, base: number | 'hex' = 'hex'): PrivateKey {
|
|
97
|
+
return new PrivateKey(super.fromString(str, base).toArray())
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Generates a private key from a hexadecimal string.
|
|
102
|
+
*
|
|
103
|
+
* @method fromHex
|
|
104
|
+
* @static
|
|
105
|
+
* @param {string} str - The hexadecimal string representing the private key. The string must represent a valid private key in big-endian format.
|
|
106
|
+
* @returns {PrivateKey} The generated Private Key instance.
|
|
107
|
+
* @throws {Error} If the string is not a valid hexadecimal or represents an invalid private key.
|
|
108
|
+
**/
|
|
109
|
+
static fromHex (str: string): PrivateKey {
|
|
110
|
+
return new PrivateKey(super.fromHex(str, 'big'))
|
|
98
111
|
}
|
|
99
112
|
|
|
100
113
|
/**
|
|
@@ -274,6 +287,34 @@ export default class PrivateKey extends BigNumber {
|
|
|
274
287
|
return this.toPublicKey().toAddress(prefix)
|
|
275
288
|
}
|
|
276
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Converts this PrivateKey to a hexadecimal string.
|
|
292
|
+
*
|
|
293
|
+
* @method toHex
|
|
294
|
+
* @param length - The minimum length of the hex string
|
|
295
|
+
* @returns Returns a string representing the hexadecimal value of this BigNumber.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* const bigNumber = new BigNumber(255);
|
|
299
|
+
* const hex = bigNumber.toHex();
|
|
300
|
+
*/
|
|
301
|
+
toHex (): string {
|
|
302
|
+
return super.toHex(32)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Converts this PrivateKey to a string representation.
|
|
307
|
+
*
|
|
308
|
+
* @method toString
|
|
309
|
+
* @param {number | 'hex'} [base='hex'] - The base for representing the number. Default is hexadecimal ('hex').
|
|
310
|
+
* @param {number} [padding=64] - The minimum number of digits for the output string. Default is 64, ensuring a 256-bit representation in hexadecimal.
|
|
311
|
+
* @returns {string} A string representation of the PrivateKey in the specified base, padded to the specified length.
|
|
312
|
+
*
|
|
313
|
+
**/
|
|
314
|
+
toString (base: number | 'hex' = 'hex', padding: number = 64): string {
|
|
315
|
+
return super.toString(base, padding)
|
|
316
|
+
}
|
|
317
|
+
|
|
277
318
|
/**
|
|
278
319
|
* Derives a shared secret from the public key.
|
|
279
320
|
*
|
|
@@ -1,17 +1,97 @@
|
|
|
1
1
|
import PublicKey from '../../../dist/cjs/src/primitives/PublicKey'
|
|
2
2
|
import PrivateKey from '../../../dist/cjs/src/primitives/PrivateKey'
|
|
3
3
|
import BRC42Private from './BRC42.private.vectors'
|
|
4
|
+
import Curve from '../../../dist/cjs/src/primitives/Curve'
|
|
5
|
+
import BigNumber from '../../../dist/cjs/src/primitives/BigNumber'
|
|
4
6
|
|
|
5
7
|
describe('PrivateKey', () => {
|
|
6
8
|
describe('BRC42 vectors', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
9
|
+
const curve = new Curve()
|
|
10
|
+
|
|
11
|
+
BRC42Private.forEach((vector, index) => {
|
|
12
|
+
it(`Passes BRC42 private vector #${index + 1}`, () => {
|
|
13
|
+
const publicKey = PublicKey.fromString(vector.senderPublicKey)
|
|
14
|
+
const privateKey = PrivateKey.fromString(vector.recipientPrivateKey, 16)
|
|
15
|
+
const derived = privateKey.deriveChild(publicKey, vector.invoiceNumber)
|
|
16
|
+
expect(derived.toHex(32)).toEqual(vector.privateKey)
|
|
14
17
|
})
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
describe('PrivateKey Validation and Conversion', () => {
|
|
22
|
+
const curve = new Curve()
|
|
23
|
+
|
|
24
|
+
const isValidPrivateKey = (key) => {
|
|
25
|
+
try {
|
|
26
|
+
const keyAsNumber = new BigNumber(key, 16)
|
|
27
|
+
return (
|
|
28
|
+
!keyAsNumber.isZero() &&
|
|
29
|
+
keyAsNumber.cmp(curve.n) < 0 &&
|
|
30
|
+
key.length === 64
|
|
31
|
+
)
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
15
35
|
}
|
|
36
|
+
|
|
37
|
+
it('Validates and converts valid private keys between hex and string', () => {
|
|
38
|
+
const validKeys = [
|
|
39
|
+
'0000000000000000000000000000000000000000000000000000000000000001',
|
|
40
|
+
'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140',
|
|
41
|
+
'8a2f85e08360a04c8a36b7c22c5e9e9a0d3bcf2f95c97db2b8bd90fc5f5ff66a',
|
|
42
|
+
'1b5a8f2392e6959a7de2b0a58f8a64cc528c9bfc1788ee0d32e1455063e71545'
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
validKeys.forEach((key, index) => {
|
|
46
|
+
const privateKeyFromHex = PrivateKey.fromHex(key)
|
|
47
|
+
const privateKeyFromString = PrivateKey.fromString(key, 'hex')
|
|
48
|
+
const privateKeyToHex = privateKeyFromHex.toHex()
|
|
49
|
+
const privateKeyToString = privateKeyFromString.toString('hex')
|
|
50
|
+
expect(isValidPrivateKey(privateKeyToHex)).toBe(true)
|
|
51
|
+
expect(isValidPrivateKey(privateKeyToString)).toBe(true)
|
|
52
|
+
|
|
53
|
+
// Round-trip conversion checks
|
|
54
|
+
expect(privateKeyToHex).toEqual(key)
|
|
55
|
+
expect(privateKeyToString).toEqual(key)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// it('Rejects invalid private keys during validation and conversion', () => {
|
|
60
|
+
// const invalidKeys = [
|
|
61
|
+
// '0000000000000000000000000000000000000000000000000000000000000000',
|
|
62
|
+
// 'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141',
|
|
63
|
+
// 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
64
|
+
// 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe',
|
|
65
|
+
// '1234567890abcdef',
|
|
66
|
+
// 'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641',
|
|
67
|
+
// 'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364',
|
|
68
|
+
// ]
|
|
69
|
+
|
|
70
|
+
// invalidKeys.forEach((key, index) => {
|
|
71
|
+
// const isValid = isValidPrivateKey(key)
|
|
72
|
+
// expect(isValid).toBe(false)
|
|
73
|
+
// // Ensure invalid keys throw an error during conversion
|
|
74
|
+
// expect(() => PrivateKey.fromHex(key)).toThrow()
|
|
75
|
+
// expect(() => PrivateKey.fromString(key, 'hex')).toThrow()
|
|
76
|
+
// })
|
|
77
|
+
// })
|
|
78
|
+
|
|
79
|
+
it('Tests 10,000 random private keys for valid conversions', () => {
|
|
80
|
+
for (let i = 0; i < 10000; i++) {
|
|
81
|
+
const privateKey = PrivateKey.fromRandom()
|
|
82
|
+
const privateKeyHex = privateKey.toHex()
|
|
83
|
+
const privateKeyString = privateKey.toString('hex')
|
|
84
|
+
|
|
85
|
+
// Validate the random key's format
|
|
86
|
+
expect(isValidPrivateKey(privateKeyHex)).toBe(true)
|
|
87
|
+
expect(isValidPrivateKey(privateKeyString)).toBe(true)
|
|
88
|
+
|
|
89
|
+
// Round-trip conversion checks
|
|
90
|
+
const roundTripHex = PrivateKey.fromHex(privateKeyHex).toHex()
|
|
91
|
+
const roundTripString = PrivateKey.fromString(privateKeyString, 'hex').toString('hex')
|
|
92
|
+
expect(roundTripHex).toEqual(privateKeyHex)
|
|
93
|
+
expect(roundTripString).toEqual(privateKeyString)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
16
96
|
})
|
|
17
97
|
})
|
|
@@ -40,10 +40,14 @@ export interface BroadcastFailure {
|
|
|
40
40
|
* @interface
|
|
41
41
|
* @property {function} broadcast - A function that takes a Transaction object and returns a promise.
|
|
42
42
|
* The promise resolves to either a BroadcastResponse or a BroadcastFailure.
|
|
43
|
+
* @property {function} broadcastMany - A function that takes an array of Transaction objects and returns a promise.
|
|
44
|
+
* The promise resolves to an array of broadcast result response objects.
|
|
43
45
|
*/
|
|
44
46
|
export interface Broadcaster {
|
|
45
47
|
broadcast: (transaction: Transaction) =>
|
|
46
48
|
Promise<BroadcastResponse | BroadcastFailure>
|
|
49
|
+
broadcastMany?: (txs: Transaction[]) =>
|
|
50
|
+
Promise<object[]>
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
/**
|
|
@@ -3,6 +3,7 @@ import WindowCWISubstrate from './substrates/window.CWI.js'
|
|
|
3
3
|
import XDMSubstrate from './substrates/XDM.js'
|
|
4
4
|
import WalletWireTransceiver from './substrates/WalletWireTransceiver.js'
|
|
5
5
|
import HTTPWalletWire from './substrates/HTTPWalletWire.js'
|
|
6
|
+
import HTTPWalletJSON from './substrates/HTTPWalletJSON.js'
|
|
6
7
|
|
|
7
8
|
const MAX_XDM_RESPONSE_WAIT = 200
|
|
8
9
|
|
|
@@ -12,10 +13,11 @@ const MAX_XDM_RESPONSE_WAIT = 200
|
|
|
12
13
|
export default class WalletClient implements Wallet {
|
|
13
14
|
public substrate: 'auto' | Wallet
|
|
14
15
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
15
|
-
constructor (substrate: 'auto' | 'Cicada' | 'XDM' | 'window.CWI' | Wallet = 'auto', originator?: OriginatorDomainNameStringUnder250Bytes) {
|
|
16
|
+
constructor (substrate: 'auto' | 'Cicada' | 'XDM' | 'window.CWI' | 'json-api' | Wallet = 'auto', originator?: OriginatorDomainNameStringUnder250Bytes) {
|
|
16
17
|
if (substrate === 'Cicada') substrate = new WalletWireTransceiver(new HTTPWalletWire(originator))
|
|
17
18
|
if (substrate === 'window.CWI') substrate = new WindowCWISubstrate()
|
|
18
19
|
if (substrate === 'XDM') substrate = new XDMSubstrate()
|
|
20
|
+
if (substrate === 'json-api') substrate = new HTTPWalletJSON(originator)
|
|
19
21
|
this.substrate = substrate
|
|
20
22
|
this.originator = originator
|
|
21
23
|
}
|
|
@@ -54,7 +56,13 @@ export default class WalletClient implements Wallet {
|
|
|
54
56
|
await checkSub()
|
|
55
57
|
this.substrate = sub
|
|
56
58
|
} catch (e) {
|
|
57
|
-
|
|
59
|
+
try {
|
|
60
|
+
sub = new HTTPWalletJSON(this.originator)
|
|
61
|
+
await checkSub()
|
|
62
|
+
this.substrate = sub
|
|
63
|
+
} catch (e) {
|
|
64
|
+
throw new Error('No wallet available over any communication substrate. Install a BSV wallet today!')
|
|
65
|
+
}
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
68
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Wallet, CreateActionArgs, OriginatorDomainNameStringUnder250Bytes, CreateActionResult, BooleanDefaultTrue, AcquireCertificateArgs, AcquireCertificateResult, Base64String, BasketStringUnder300Bytes, BooleanDefaultFalse, Byte, CertificateFieldNameUnder50Bytes, DescriptionString5to50Bytes, DiscoverCertificatesResult, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, InternalizeActionArgs, ISOTimestampString, KeyIDStringUnder800Bytes, ListActionsArgs, ListActionsResult, ListCertificatesResult, ListOutputsArgs, ListOutputsResult, OutpointString, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, ProveCertificateArgs, ProveCertificateResult, PubKeyHex, SecurityLevel, SignActionArgs, SignActionResult, VersionString7To30Bytes } from '../Wallet.interfaces.js'
|
|
2
|
+
|
|
3
|
+
export default class HTTPWalletJSON implements Wallet {
|
|
4
|
+
baseUrl: string
|
|
5
|
+
httpClient: typeof fetch
|
|
6
|
+
originator: OriginatorDomainNameStringUnder250Bytes | undefined
|
|
7
|
+
api: (call: string, args: any) => Promise<any>
|
|
8
|
+
|
|
9
|
+
constructor(originator: OriginatorDomainNameStringUnder250Bytes | undefined, baseUrl: string = 'http://localhost:3321', httpClient = fetch) {
|
|
10
|
+
this.baseUrl = baseUrl
|
|
11
|
+
this.originator = originator
|
|
12
|
+
this.httpClient = httpClient
|
|
13
|
+
this.api = async (call, args) => {
|
|
14
|
+
try {
|
|
15
|
+
const response = await (await httpClient(`${this.baseUrl}/${call}`, {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
'Accept': 'application/json',
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
'Originator': this.originator
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify(args)
|
|
23
|
+
})).json()
|
|
24
|
+
return response
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.log({ 'HTTPWalletJSON': { call, args, error }})
|
|
27
|
+
throw error
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async createAction(args: CreateActionArgs): Promise<CreateActionResult> {
|
|
33
|
+
return await this.api('createAction', args)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async signAction(args: SignActionArgs): Promise<SignActionResult> {
|
|
37
|
+
return await this.api('signAction', args)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async abortAction(args: { reference: Base64String }): Promise<{ aborted: true }> {
|
|
41
|
+
return await this.api('abortAction', args)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async listActions(args: ListActionsArgs): Promise<ListActionsResult> {
|
|
45
|
+
return await this.api('listActions', args)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async internalizeAction(args: InternalizeActionArgs): Promise<{ accepted: true }> {
|
|
49
|
+
return await this.api('internalizeAction', args)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async listOutputs(args: ListOutputsArgs): Promise<ListOutputsResult> {
|
|
53
|
+
return await this.api('listOutputs', args)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async relinquishOutput(args: { basket: BasketStringUnder300Bytes, output: OutpointString }): Promise<{ relinquished: true }> {
|
|
57
|
+
return await this.api('relinquishOutput', args)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async getPublicKey(args: { seekPermission?: BooleanDefaultTrue, identityKey?: true, protocolID?: [SecurityLevel, ProtocolString5To400Bytes], keyID?: KeyIDStringUnder800Bytes, privileged?: BooleanDefaultFalse, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', forSelf?: BooleanDefaultFalse }): Promise<{ publicKey: PubKeyHex }> {
|
|
61
|
+
return await this.api('getPublicKey', args)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async revealCounterpartyKeyLinkage(args: { counterparty: PubKeyHex, verifier: PubKeyHex, privilegedReason?: DescriptionString5to50Bytes, privileged?: BooleanDefaultFalse }): Promise<{ prover: PubKeyHex, verifier: PubKeyHex, counterparty: PubKeyHex, revelationTime: ISOTimestampString, encryptedLinkage: Byte[], encryptedLinkageProof: number[] }> {
|
|
65
|
+
return await this.api('revealCounterpartyKeyLinkage', args)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async revealSpecificKeyLinkage(args: { counterparty: PubKeyHex, verifier: PubKeyHex, protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, privileged?: BooleanDefaultFalse }): Promise<{ prover: PubKeyHex, verifier: PubKeyHex, counterparty: PubKeyHex, protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, encryptedLinkage: Byte[], encryptedLinkageProof: Byte[], proofType: Byte }> {
|
|
69
|
+
return await this.api('revealSpecificKeyLinkage', args)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async encrypt(args: { seekPermission?: BooleanDefaultTrue, plaintext: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ ciphertext: Byte[] }> {
|
|
73
|
+
return await this.api('encrypt', args)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async decrypt(args: { seekPermission?: BooleanDefaultTrue, ciphertext: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ plaintext: Byte[] }> {
|
|
77
|
+
return await this.api('decrypt', args)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async createHmac(args: { seekPermission?: BooleanDefaultTrue, data: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ hmac: Byte[] }> {
|
|
81
|
+
return await this.api('createHmac', args)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async verifyHmac(args: { seekPermission?: BooleanDefaultTrue, data: Byte[], hmac: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ valid: true }> {
|
|
85
|
+
return await this.api('verifyHmac', args)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async createSignature(args: { seekPermission?: BooleanDefaultTrue, data?: Byte[], hashToDirectlySign?: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ signature: Byte[] }> {
|
|
89
|
+
return await this.api('createSignature', args)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async verifySignature(args: { seekPermission?: BooleanDefaultTrue, data?: Byte[], hashToDirectlyVerify?: Byte[], signature: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', forSelf?: BooleanDefaultFalse, privileged?: BooleanDefaultFalse }): Promise<{ valid: true }> {
|
|
93
|
+
return await this.api('verifySignature', args)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async acquireCertificate(args: AcquireCertificateArgs): Promise<AcquireCertificateResult> {
|
|
97
|
+
return await this.api('acquireCertificate', args)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async listCertificates(args: { certifiers: PubKeyHex[], types: Base64String[], limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero, privileged?: BooleanDefaultFalse, privilegedReason?: DescriptionString5to50Bytes }): Promise<ListCertificatesResult> {
|
|
101
|
+
return await this.api('listCertificates', args)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async proveCertificate(args: ProveCertificateArgs): Promise<ProveCertificateResult> {
|
|
105
|
+
return await this.api('proveCertificate', args)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async relinquishCertificate(args: { type: Base64String, serialNumber: Base64String, certifier: PubKeyHex }): Promise<{ relinquished: true }> {
|
|
109
|
+
return await this.api('relinquishCertificate', args)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async discoverByIdentityKey(args: { seekPermission?: BooleanDefaultTrue, identityKey: PubKeyHex, limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero }): Promise<DiscoverCertificatesResult> {
|
|
113
|
+
return await this.api('discoverByIdentityKey', args)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async discoverByAttributes(args: { seekPermission?: BooleanDefaultTrue, attributes: Record<CertificateFieldNameUnder50Bytes, string>, limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero }): Promise<DiscoverCertificatesResult> {
|
|
117
|
+
return await this.api('discoverByAttributes', args)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async isAuthenticated(args: {}): Promise<{ authenticated: boolean }> {
|
|
121
|
+
return await this.api('isAuthenticated', args)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async waitForAuthentication(args: {}): Promise<{ authenticated: true }> {
|
|
125
|
+
return await this.api('waitForAuthentication', args)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async getHeight(args: {}): Promise<{ height: PositiveInteger }> {
|
|
129
|
+
return await this.api('getHeight', args)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async getHeaderForHeight(args: { height: PositiveInteger }): Promise<{ header: HexString }> {
|
|
133
|
+
return await this.api('getHeaderForHeight', args)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async getNetwork(args: {}): Promise<{ network: 'mainnet' | 'testnet' }> {
|
|
137
|
+
return await this.api('getNetwork', args)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async getVersion(args: {}): Promise<{ version: VersionString7To30Bytes }> {
|
|
141
|
+
return await this.api('getVersion', args)
|
|
142
|
+
}
|
|
143
|
+
}
|