@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/README.md
CHANGED
|
@@ -6,4 +6,13 @@ The documentation is split into various pages, each covering a set of related fu
|
|
|
6
6
|
- [Script](./script.md) — Covers Bitcoin scripts, the templating system, serialization, and the Spend class (script interpreter)
|
|
7
7
|
- [Transaction](./transaction.md) — Covers transaction construction, signing, broadcasters, fee models, merkle proofs, and SPV structures like BUMP
|
|
8
8
|
- [Messages](./messages.md) — Covers generalizable message signing, verification, encryption and decryption
|
|
9
|
+
- [TOTP](./totp.md) - Covers Time-based One Time Password, useful for validating counterparties across unsecured mediums.
|
|
10
|
+
- [Wallet](./wallet-substrates.md) - Covers the Wallet Substrates for communication between applications and wallets using a standard interface.
|
|
11
|
+
- [Overlay Tools](./overlay-tools.md) - Covers the use of Overlays for broadcast of transactions based on topics, as well as distributed lookup of tokens.
|
|
9
12
|
- [Compat](./compat.md) — Covers deprecated functionality for legacy systems like BIP32 and ECIES
|
|
13
|
+
|
|
14
|
+
## Swagger
|
|
15
|
+
|
|
16
|
+
[BRC-100](https://brc.dev/100) defines a Unified, Vendor-Neutral, Unchanging, and Open BSV Blockchain Standard Wallet-to-Application Interface which is implemented in this library within the WalletClient class. The API is laid out here as a swagger openapi document to offer a fast-track to understanding the interface which is implemented across multiple substrates. The JSON api is generally considered a developer friendly introduction to the WalletClient, where an binary equivalent ABI may be preferred for production use cases.
|
|
17
|
+
|
|
18
|
+
- [Wallet JSON API Swagger](./swagger)
|
package/docs/primitives.md
CHANGED
|
@@ -5254,7 +5254,8 @@ create a corresponding public key and derive a shared secret from a public key.
|
|
|
5254
5254
|
```ts
|
|
5255
5255
|
export default class PrivateKey extends BigNumber {
|
|
5256
5256
|
static fromRandom(): PrivateKey
|
|
5257
|
-
static fromString(str: string, base: number | "hex"): PrivateKey
|
|
5257
|
+
static fromString(str: string, base: number | "hex" = "hex"): PrivateKey
|
|
5258
|
+
static fromHex(str: string): PrivateKey
|
|
5258
5259
|
static fromWif(wif: string, prefixLength: number = 1): PrivateKey
|
|
5259
5260
|
constructor(number: BigNumber | number | string | number[] = 0, base: number | "be" | "le" | "hex" = 10, endian: "be" | "le" = "be", modN: "apply" | "nocheck" | "error" = "apply")
|
|
5260
5261
|
checkInField(): {
|
|
@@ -5267,6 +5268,8 @@ export default class PrivateKey extends BigNumber {
|
|
|
5267
5268
|
toPublicKey(): PublicKey
|
|
5268
5269
|
toWif(prefix: number[] = [128]): string
|
|
5269
5270
|
toAddress(prefix: number[] | string = [0]): string
|
|
5271
|
+
toHex(): string
|
|
5272
|
+
toString(base: number | "hex" = "hex", padding: number = 64): string
|
|
5270
5273
|
deriveSharedSecret(key: PublicKey): Point
|
|
5271
5274
|
deriveChild(publicKey: PublicKey, invoiceNumber: string): PrivateKey
|
|
5272
5275
|
toKeyShares(threshold: number, totalShares: number): KeyShares
|
|
@@ -5276,7 +5279,7 @@ export default class PrivateKey extends BigNumber {
|
|
|
5276
5279
|
}
|
|
5277
5280
|
```
|
|
5278
5281
|
|
|
5279
|
-
See also: [BigNumber](#class-bignumber), [KeyShares](#class-keyshares), [Point](#class-point), [PublicKey](#class-publickey), [Signature](#class-signature), [sign](#variable-sign), [verify](#variable-verify)
|
|
5282
|
+
See also: [BigNumber](#class-bignumber), [KeyShares](#class-keyshares), [Point](#class-point), [PublicKey](#class-publickey), [Signature](#class-signature), [sign](#variable-sign), [toHex](#variable-tohex), [verify](#variable-verify)
|
|
5280
5283
|
|
|
5281
5284
|
<details>
|
|
5282
5285
|
|
|
@@ -5394,6 +5397,28 @@ const share2 = 'Cm5fuUc39X5xgdedao8Pr1kvCSm8Gk7Cfenc7xUKcfLX.2juyK9BxCWn2DiY5JUA
|
|
|
5394
5397
|
const recoveredKey = PrivateKey.fromBackupShares([share1, share2])
|
|
5395
5398
|
```
|
|
5396
5399
|
|
|
5400
|
+
#### Method fromHex
|
|
5401
|
+
|
|
5402
|
+
Generates a private key from a hexadecimal string.
|
|
5403
|
+
|
|
5404
|
+
```ts
|
|
5405
|
+
static fromHex(str: string): PrivateKey
|
|
5406
|
+
```
|
|
5407
|
+
See also: [PrivateKey](#class-privatekey)
|
|
5408
|
+
|
|
5409
|
+
Returns
|
|
5410
|
+
|
|
5411
|
+
The generated Private Key instance.
|
|
5412
|
+
|
|
5413
|
+
Argument Details
|
|
5414
|
+
|
|
5415
|
+
+ **str**
|
|
5416
|
+
+ The hexadecimal string representing the private key. The string must represent a valid private key in big-endian format.
|
|
5417
|
+
|
|
5418
|
+
Throws
|
|
5419
|
+
|
|
5420
|
+
If the string is not a valid hexadecimal or represents an invalid private key.
|
|
5421
|
+
|
|
5397
5422
|
#### Method fromKeyShares
|
|
5398
5423
|
|
|
5399
5424
|
Combines shares to reconstruct the private key.
|
|
@@ -5438,7 +5463,7 @@ const privateKey = PrivateKey.fromRandom();
|
|
|
5438
5463
|
Generates a private key from a string.
|
|
5439
5464
|
|
|
5440
5465
|
```ts
|
|
5441
|
-
static fromString(str: string, base: number | "hex"): PrivateKey
|
|
5466
|
+
static fromString(str: string, base: number | "hex" = "hex"): PrivateKey
|
|
5442
5467
|
```
|
|
5443
5468
|
See also: [PrivateKey](#class-privatekey)
|
|
5444
5469
|
|
|
@@ -5562,6 +5587,30 @@ Argument Details
|
|
|
5562
5587
|
+ **totalShares**
|
|
5563
5588
|
+ The number of shares to generate for distribution.
|
|
5564
5589
|
|
|
5590
|
+
#### Method toHex
|
|
5591
|
+
|
|
5592
|
+
Converts this PrivateKey to a hexadecimal string.
|
|
5593
|
+
|
|
5594
|
+
```ts
|
|
5595
|
+
toHex(): string
|
|
5596
|
+
```
|
|
5597
|
+
|
|
5598
|
+
Returns
|
|
5599
|
+
|
|
5600
|
+
Returns a string representing the hexadecimal value of this BigNumber.
|
|
5601
|
+
|
|
5602
|
+
Argument Details
|
|
5603
|
+
|
|
5604
|
+
+ **length**
|
|
5605
|
+
+ The minimum length of the hex string
|
|
5606
|
+
|
|
5607
|
+
Example
|
|
5608
|
+
|
|
5609
|
+
```ts
|
|
5610
|
+
const bigNumber = new BigNumber(255);
|
|
5611
|
+
const hex = bigNumber.toHex();
|
|
5612
|
+
```
|
|
5613
|
+
|
|
5565
5614
|
#### Method toKeyShares
|
|
5566
5615
|
|
|
5567
5616
|
Splits the private key into shares using Shamir's Secret Sharing Scheme.
|
|
@@ -5613,6 +5662,27 @@ const privateKey = PrivateKey.fromRandom();
|
|
|
5613
5662
|
const publicKey = privateKey.toPublicKey();
|
|
5614
5663
|
```
|
|
5615
5664
|
|
|
5665
|
+
#### Method toString
|
|
5666
|
+
|
|
5667
|
+
function toString() { [native code] }
|
|
5668
|
+
|
|
5669
|
+
Converts this PrivateKey to a string representation.
|
|
5670
|
+
|
|
5671
|
+
```ts
|
|
5672
|
+
toString(base: number | "hex" = "hex", padding: number = 64): string
|
|
5673
|
+
```
|
|
5674
|
+
|
|
5675
|
+
Returns
|
|
5676
|
+
|
|
5677
|
+
A string representation of the PrivateKey in the specified base, padded to the specified length.
|
|
5678
|
+
|
|
5679
|
+
Argument Details
|
|
5680
|
+
|
|
5681
|
+
+ **base**
|
|
5682
|
+
+ The base for representing the number. Default is hexadecimal ('hex').
|
|
5683
|
+
+ **padding**
|
|
5684
|
+
+ The minimum number of digits for the output string. Default is 64, ensuring a 256-bit representation in hexadecimal.
|
|
5685
|
+
|
|
5616
5686
|
#### Method toWif
|
|
5617
5687
|
|
|
5618
5688
|
Converts the private key to a Wallet Import Format (WIF) string.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Peter Evans
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en-US">
|
|
3
|
+
<head>
|
|
4
|
+
<title>Swagger UI: OAuth2 Redirect</title>
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<script>
|
|
8
|
+
'use strict';
|
|
9
|
+
function run () {
|
|
10
|
+
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
|
11
|
+
var sentState = oauth2.state;
|
|
12
|
+
var redirectUrl = oauth2.redirectUrl;
|
|
13
|
+
var isValid, qp, arr;
|
|
14
|
+
|
|
15
|
+
if (/code|token|error/.test(window.location.hash)) {
|
|
16
|
+
qp = window.location.hash.substring(1).replace('?', '&');
|
|
17
|
+
} else {
|
|
18
|
+
qp = location.search.substring(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
arr = qp.split("&");
|
|
22
|
+
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
|
|
23
|
+
qp = qp ? JSON.parse('{' + arr.join() + '}',
|
|
24
|
+
function (key, value) {
|
|
25
|
+
return key === "" ? value : decodeURIComponent(value);
|
|
26
|
+
}
|
|
27
|
+
) : {};
|
|
28
|
+
|
|
29
|
+
isValid = qp.state === sentState;
|
|
30
|
+
|
|
31
|
+
if ((
|
|
32
|
+
oauth2.auth.schema.get("flow") === "accessCode" ||
|
|
33
|
+
oauth2.auth.schema.get("flow") === "authorizationCode" ||
|
|
34
|
+
oauth2.auth.schema.get("flow") === "authorization_code"
|
|
35
|
+
) && !oauth2.auth.code) {
|
|
36
|
+
if (!isValid) {
|
|
37
|
+
oauth2.errCb({
|
|
38
|
+
authId: oauth2.auth.name,
|
|
39
|
+
source: "auth",
|
|
40
|
+
level: "warning",
|
|
41
|
+
message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (qp.code) {
|
|
46
|
+
delete oauth2.state;
|
|
47
|
+
oauth2.auth.code = qp.code;
|
|
48
|
+
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
|
|
49
|
+
} else {
|
|
50
|
+
let oauthErrorMsg;
|
|
51
|
+
if (qp.error) {
|
|
52
|
+
oauthErrorMsg = "["+qp.error+"]: " +
|
|
53
|
+
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
|
|
54
|
+
(qp.error_uri ? "More info: "+qp.error_uri : "");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
oauth2.errCb({
|
|
58
|
+
authId: oauth2.auth.name,
|
|
59
|
+
source: "auth",
|
|
60
|
+
level: "error",
|
|
61
|
+
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
|
|
66
|
+
}
|
|
67
|
+
window.close();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (document.readyState !== 'loading') {
|
|
71
|
+
run();
|
|
72
|
+
} else {
|
|
73
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
74
|
+
run();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
78
|
+
</body>
|
|
79
|
+
</html>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
window.onload = function() {
|
|
2
|
+
//<editor-fold desc="Changeable Configuration Block">
|
|
3
|
+
|
|
4
|
+
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
|
|
5
|
+
window.ui = SwaggerUIBundle({
|
|
6
|
+
url: "swagger.yaml",
|
|
7
|
+
dom_id: '#swagger-ui',
|
|
8
|
+
deepLinking: true,
|
|
9
|
+
presets: [
|
|
10
|
+
SwaggerUIBundle.presets.apis,
|
|
11
|
+
SwaggerUIStandalonePreset
|
|
12
|
+
],
|
|
13
|
+
plugins: [
|
|
14
|
+
SwaggerUIBundle.plugins.DownloadUrl
|
|
15
|
+
],
|
|
16
|
+
layout: "StandaloneLayout"
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
//</editor-fold>
|
|
20
|
+
};
|