@bsv/sdk 1.1.12 → 1.1.14

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.
Files changed (146) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/primitives/Point.js +28 -8
  3. package/dist/cjs/src/primitives/Point.js.map +1 -1
  4. package/dist/cjs/src/primitives/Polynomial.js +81 -0
  5. package/dist/cjs/src/primitives/Polynomial.js.map +1 -0
  6. package/dist/cjs/src/primitives/PrivateKey.js +165 -0
  7. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
  8. package/dist/cjs/src/primitives/PublicKey.js +16 -2
  9. package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
  10. package/dist/cjs/src/primitives/index.js +5 -1
  11. package/dist/cjs/src/primitives/index.js.map +1 -1
  12. package/dist/cjs/src/primitives/utils.js +1 -1
  13. package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
  14. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
  15. package/dist/cjs/src/transaction/Transaction.js +9 -4
  16. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  17. package/dist/cjs/src/transaction/broadcasters/ARC.js +4 -4
  18. package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -1
  19. package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  20. package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +3 -3
  21. package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
  22. package/dist/cjs/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
  23. package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js +2 -2
  24. package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
  25. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  26. package/dist/cjs/src/transaction/http/DefaultHttpClient.js +2 -2
  27. package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
  28. package/dist/cjs/src/transaction/http/FetchHttpClient.js +2 -2
  29. package/dist/cjs/src/transaction/http/FetchHttpClient.js.map +1 -1
  30. package/dist/cjs/src/transaction/http/NodejsHttpClient.js +2 -2
  31. package/dist/cjs/src/transaction/http/NodejsHttpClient.js.map +1 -1
  32. package/dist/cjs/src/transaction/http/index.js.map +1 -1
  33. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  34. package/dist/esm/src/primitives/Point.js +28 -8
  35. package/dist/esm/src/primitives/Point.js.map +1 -1
  36. package/dist/esm/src/primitives/Polynomial.js +77 -0
  37. package/dist/esm/src/primitives/Polynomial.js.map +1 -0
  38. package/dist/esm/src/primitives/PrivateKey.js +143 -0
  39. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  40. package/dist/esm/src/primitives/PublicKey.js +16 -2
  41. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  42. package/dist/esm/src/primitives/index.js +2 -1
  43. package/dist/esm/src/primitives/index.js.map +1 -1
  44. package/dist/esm/src/primitives/utils.js +1 -1
  45. package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
  46. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
  47. package/dist/esm/src/transaction/Transaction.js +9 -4
  48. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  49. package/dist/esm/src/transaction/broadcasters/ARC.js +7 -7
  50. package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -1
  51. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
  52. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  53. package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +4 -4
  54. package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
  55. package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js +1 -1
  56. package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
  57. package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js +3 -3
  58. package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
  59. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  60. package/dist/esm/src/transaction/http/DefaultHttpClient.js +2 -2
  61. package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
  62. package/dist/esm/src/transaction/http/FetchHttpClient.js +2 -2
  63. package/dist/esm/src/transaction/http/FetchHttpClient.js.map +1 -1
  64. package/dist/esm/src/transaction/http/NodejsHttpClient.js +2 -2
  65. package/dist/esm/src/transaction/http/NodejsHttpClient.js.map +1 -1
  66. package/dist/esm/src/transaction/http/index.js.map +1 -1
  67. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  68. package/dist/types/src/primitives/Point.d.ts +19 -1
  69. package/dist/types/src/primitives/Point.d.ts.map +1 -1
  70. package/dist/types/src/primitives/Polynomial.d.ts +32 -0
  71. package/dist/types/src/primitives/Polynomial.d.ts.map +1 -0
  72. package/dist/types/src/primitives/PrivateKey.d.ts +72 -0
  73. package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
  74. package/dist/types/src/primitives/PublicKey.d.ts +12 -1
  75. package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
  76. package/dist/types/src/primitives/index.d.ts +2 -1
  77. package/dist/types/src/primitives/index.d.ts.map +1 -1
  78. package/dist/types/src/primitives/utils.d.ts +1 -1
  79. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
  80. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  81. package/dist/types/src/transaction/broadcasters/ARC.d.ts +1 -1
  82. package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -1
  83. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts +1 -1
  84. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts.map +1 -1
  85. package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts +1 -1
  86. package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts.map +1 -1
  87. package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts +1 -1
  88. package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts.map +1 -1
  89. package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts +2 -2
  90. package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts.map +1 -1
  91. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -1
  92. package/dist/types/src/transaction/http/DefaultHttpClient.d.ts.map +1 -1
  93. package/dist/types/src/transaction/http/FetchHttpClient.d.ts +7 -9
  94. package/dist/types/src/transaction/http/FetchHttpClient.d.ts.map +1 -1
  95. package/dist/types/src/transaction/http/HttpClient.d.ts +5 -5
  96. package/dist/types/src/transaction/http/HttpClient.d.ts.map +1 -1
  97. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts +5 -6
  98. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts.map +1 -1
  99. package/dist/types/src/transaction/http/index.d.ts.map +1 -1
  100. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  101. package/docs/primitives.md +231 -16
  102. package/docs/transaction.md +38 -37
  103. package/package.json +1 -1
  104. package/src/compat/__tests/BSM.test.ts +37 -37
  105. package/src/compat/__tests/ECIES.test.ts +71 -71
  106. package/src/compat/__tests/HD.test.ts +362 -362
  107. package/src/compat/__tests/Mnemonic.test.ts +147 -148
  108. package/src/compat/__tests/Mnemonic.vectors.ts +170 -170
  109. package/src/messages/__tests/EncryptedMessage.test.ts +16 -16
  110. package/src/primitives/Point.ts +29 -10
  111. package/src/primitives/Polynomial.ts +89 -0
  112. package/src/primitives/PrivateKey.ts +147 -1
  113. package/src/primitives/PublicKey.ts +17 -2
  114. package/src/primitives/__tests/AESGCM.test.ts +20 -20
  115. package/src/primitives/__tests/Hash.test.ts +2 -2
  116. package/src/primitives/__tests/PBKDF2.vectors.ts +93 -93
  117. package/src/primitives/__tests/PrivateKey.split.test.ts +70 -0
  118. package/src/primitives/__tests/PublicKey.test.ts +14 -1
  119. package/src/primitives/__tests/bug-31.test.ts +24 -26
  120. package/src/primitives/__tests/utils.test.ts +13 -13
  121. package/src/primitives/index.ts +2 -1
  122. package/src/primitives/utils.ts +1 -1
  123. package/src/script/__tests/Script.test.ts +1 -1
  124. package/src/script/__tests/SpendComplex.test.ts +6 -6
  125. package/src/script/__tests/script.invalid.vectors.ts +1464 -1464
  126. package/src/script/__tests/script.valid.vectors.ts +1962 -1962
  127. package/src/script/__tests/spend.valid.vectors.ts +1369 -1369
  128. package/src/script/templates/P2PKH.ts +6 -6
  129. package/src/script/templates/RPuzzle.ts +1 -1
  130. package/src/transaction/Transaction.ts +13 -7
  131. package/src/transaction/__tests/Transaction.test.ts +14 -5
  132. package/src/transaction/__tests/bump.invalid.vectors.ts +1 -1
  133. package/src/transaction/__tests/bump.valid.vectors.ts +3 -3
  134. package/src/transaction/broadcasters/ARC.ts +20 -21
  135. package/src/transaction/broadcasters/DefaultBroadcaster.ts +3 -3
  136. package/src/transaction/broadcasters/WhatsOnChainBroadcaster.ts +10 -10
  137. package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +7 -10
  138. package/src/transaction/chaintrackers/DefaultChainTracker.ts +3 -3
  139. package/src/transaction/chaintrackers/WhatsOnChain.ts +10 -12
  140. package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +13 -17
  141. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +2 -2
  142. package/src/transaction/http/DefaultHttpClient.ts +13 -13
  143. package/src/transaction/http/FetchHttpClient.ts +14 -16
  144. package/src/transaction/http/HttpClient.ts +22 -23
  145. package/src/transaction/http/NodejsHttpClient.ts +23 -25
  146. package/src/transaction/http/index.ts +6 -6
@@ -1,32 +1,32 @@
1
- import { HttpClient, HttpClientResponse } from './HttpClient.js';
2
- import { NodejsHttpClient } from './NodejsHttpClient.js';
3
- import { FetchHttpClient } from './FetchHttpClient.js';
1
+ import { HttpClient, HttpClientResponse } from './HttpClient.js'
2
+ import { NodejsHttpClient } from './NodejsHttpClient.js'
3
+ import { FetchHttpClient } from './FetchHttpClient.js'
4
4
 
5
5
  /**
6
6
  * Returns a default HttpClient implementation based on the environment that it is run on.
7
7
  * This method will attempt to use `window.fetch` if available (in browser environments).
8
8
  * If running in a Node.js environment, it falls back to using the Node.js `https` module
9
9
  */
10
- export function defaultHttpClient(): HttpClient {
10
+ export function defaultHttpClient (): HttpClient {
11
11
  const noHttpClient: HttpClient = {
12
- request(..._): Promise<HttpClientResponse> {
13
- throw new Error('No method available to perform HTTP request');
14
- },
15
- };
12
+ async request (..._): Promise<HttpClientResponse> {
13
+ throw new Error('No method available to perform HTTP request')
14
+ }
15
+ }
16
16
 
17
17
  if (typeof window !== 'undefined' && typeof window.fetch === 'function') {
18
18
  // Use fetch in a browser environment
19
- return new FetchHttpClient(window.fetch);
19
+ return new FetchHttpClient(window.fetch)
20
20
  } else if (typeof require !== 'undefined') {
21
21
  // Use Node.js https module
22
22
  // eslint-disable-next-line
23
23
  try {
24
- const https = require('https');
25
- return new NodejsHttpClient(https);
24
+ const https = require('https')
25
+ return new NodejsHttpClient(https)
26
26
  } catch (e) {
27
- return noHttpClient;
27
+ return noHttpClient
28
28
  }
29
29
  } else {
30
- return noHttpClient;
30
+ return noHttpClient
31
31
  }
32
32
  }
@@ -1,14 +1,12 @@
1
- import { HttpClient, HttpClientRequestOptions, HttpClientResponse } from './HttpClient.js';
1
+ import { HttpClient, HttpClientRequestOptions, HttpClientResponse } from './HttpClient.js'
2
2
 
3
3
  /** fetch function interface limited to options needed by ts-sdk */
4
- export interface Fetch {
5
- /**
4
+ /**
6
5
  * Makes a request to the server.
7
6
  * @param url The URL to make the request to.
8
7
  * @param options The request configuration.
9
8
  */
10
- (url: string, options: FetchOptions): Promise<Response>;
11
- }
9
+ export type Fetch = (url: string, options: FetchOptions) => Promise<Response>
12
10
 
13
11
  /**
14
12
  * An interface for configuration of the request to be passed to the fetch method
@@ -16,35 +14,35 @@ export interface Fetch {
16
14
  */
17
15
  export interface FetchOptions {
18
16
  /** A string to set request's method. */
19
- method?: string;
17
+ method?: string
20
18
  /** An object literal set request's headers. */
21
- headers?: Record<string, string>;
19
+ headers?: Record<string, string>
22
20
  /** An object or null to set request's body. */
23
- body?: string | null;
21
+ body?: string | null
24
22
  }
25
23
 
26
24
  /**
27
25
  * Adapter for Node.js Https module to be used as HttpClient
28
26
  */
29
27
  export class FetchHttpClient implements HttpClient {
30
- constructor(private fetch: Fetch) {}
28
+ constructor (private readonly fetch: Fetch) {}
31
29
 
32
30
  async request<D>(url: string, options: HttpClientRequestOptions): Promise<HttpClientResponse<D>> {
33
31
  const fetchOptions: FetchOptions = {
34
32
  method: options.method,
35
33
  headers: options.headers,
36
- body: JSON.stringify(options.data),
37
- };
34
+ body: JSON.stringify(options.data)
35
+ }
38
36
 
39
- const res = await this.fetch(url, fetchOptions);
40
- const mediaType = res.headers.get('Content-Type');
41
- const data = mediaType.startsWith('application/json') ? await res.json() : await res.text();
37
+ const res = await this.fetch(url, fetchOptions)
38
+ const mediaType = res.headers.get('Content-Type')
39
+ const data = mediaType.startsWith('application/json') ? await res.json() : await res.text()
42
40
 
43
41
  return {
44
42
  ok: res.ok,
45
43
  status: res.status,
46
44
  statusText: res.statusText,
47
- data: data as D,
48
- };
45
+ data: data as D
46
+ }
49
47
  }
50
48
  }
@@ -2,44 +2,43 @@
2
2
  * An interface for HTTP client used to make HTTP requests.
3
3
  */
4
4
  export interface HttpClient {
5
- /**
5
+ /**
6
6
  * Makes a request to the server.
7
7
  * @param url The URL to make the request to.
8
8
  * @param options The request configuration.
9
9
  */
10
- request<T = any, D = any>(url: string, options: HttpClientRequestOptions<D>): Promise<HttpClientResponse<T>>;
10
+ request: <T = any, D = any>(url: string, options: HttpClientRequestOptions<D>) => Promise<HttpClientResponse<T>>
11
11
  }
12
12
 
13
13
  /**
14
14
  * An interface for configuration of the request to be passed to the request method.
15
15
  */
16
16
  export interface HttpClientRequestOptions<Data = any> {
17
- /** A string to set request's method. */
18
- method?: string;
19
- /** An object literal set request's headers. */
20
- headers?: Record<string, string>;
21
- /** An object or null to set request's body. */
22
- data?: Data;
17
+ /** A string to set request's method. */
18
+ method?: string
19
+ /** An object literal set request's headers. */
20
+ headers?: Record<string, string>
21
+ /** An object or null to set request's body. */
22
+ data?: Data
23
23
  }
24
24
 
25
25
  /**
26
26
  * An interface for the response returned by the request method.
27
27
  */
28
28
  export type HttpClientResponse<T = any> = {
29
- data: T;
30
- /** The status code of the response. */
31
- status: number;
32
- /** The status text of the response. */
33
- statusText: string;
34
- /** A flag indicating whether the request ends with success status or not. */
35
- ok: true;
29
+ data: T
30
+ /** The status code of the response. */
31
+ status: number
32
+ /** The status text of the response. */
33
+ statusText: string
34
+ /** A flag indicating whether the request ends with success status or not. */
35
+ ok: true
36
36
  } | {
37
- data: any;
38
- /** The status code of the response. */
39
- status: number;
40
- /** The status text of the response. */
41
- statusText: string;
42
- /** A flag indicating whether the request ends with success status or not. */
43
- ok: false;
37
+ data: any
38
+ /** The status code of the response. */
39
+ status: number
40
+ /** The status text of the response. */
41
+ statusText: string
42
+ /** A flag indicating whether the request ends with success status or not. */
43
+ ok: false
44
44
  }
45
-
@@ -1,55 +1,53 @@
1
- import { HttpClient, HttpClientRequestOptions, HttpClientResponse } from './HttpClient.js';
1
+ import { HttpClient, HttpClientRequestOptions, HttpClientResponse } from './HttpClient.js'
2
2
 
3
3
  /** Node.js Https module interface limited to options needed by ts-sdk */
4
4
  export interface HttpsNodejs {
5
- request(url: string, options: HttpClientRequestOptions, callback: (res: any) => void): NodejsHttpClientRequest;
5
+ request: (url: string, options: HttpClientRequestOptions, callback: (res: any) => void) => NodejsHttpClientRequest
6
6
  }
7
7
 
8
8
  /** Nodejs result of the Node.js https.request call limited to options needed by ts-sdk */
9
9
  export interface NodejsHttpClientRequest {
10
- write(chunk: string): void;
10
+ write: (chunk: string) => void
11
11
 
12
- end(): void;
12
+ on: (event: string, callback: (data: any) => void) => void
13
13
 
14
- on(event: string, callback: (data: any) => void): void;
15
-
16
- end(): void;
14
+ end: (() => void) & (() => void)
17
15
  }
18
16
 
19
17
  /**
20
18
  * Adapter for Node.js Https module to be used as HttpClient
21
19
  */
22
20
  export class NodejsHttpClient implements HttpClient {
23
- constructor(private https: HttpsNodejs) {}
21
+ constructor (private readonly https: HttpsNodejs) {}
24
22
 
25
- async request(url: string, requestOptions: HttpClientRequestOptions): Promise<HttpClientResponse> {
23
+ async request (url: string, requestOptions: HttpClientRequestOptions): Promise<HttpClientResponse> {
26
24
  return await new Promise((resolve, reject) => {
27
25
  const req = this.https.request(url, requestOptions, (res) => {
28
- let body = '';
26
+ let body = ''
29
27
  res.on('data', (chunk: string) => {
30
- body += chunk;
31
- });
28
+ body += chunk
29
+ })
32
30
  res.on('end', () => {
33
- const ok = res.statusCode >= 200 && res.statusCode <= 299;
34
- const mediaType = res.headers['content-type'];
35
- const data = body && mediaType.startsWith('application/json') ? JSON.parse(body) : body;
31
+ const ok = res.statusCode >= 200 && res.statusCode <= 299
32
+ const mediaType = res.headers['content-type']
33
+ const data = body && mediaType.startsWith('application/json') ? JSON.parse(body) : body
36
34
  resolve({
37
35
  status: res.statusCode,
38
36
  statusText: res.statusMessage,
39
37
  ok,
40
- data,
41
- });
42
- });
43
- });
38
+ data
39
+ })
40
+ })
41
+ })
44
42
 
45
43
  req.on('error', (error) => {
46
- reject(error);
47
- });
44
+ reject(error)
45
+ })
48
46
 
49
- if (!!requestOptions.data) {
50
- req.write(JSON.stringify(requestOptions.data));
47
+ if (requestOptions.data) {
48
+ req.write(JSON.stringify(requestOptions.data))
51
49
  }
52
- req.end();
53
- });
50
+ req.end()
51
+ })
54
52
  }
55
53
  }
@@ -1,6 +1,6 @@
1
- export type { HttpClient, HttpClientResponse, HttpClientRequestOptions } from './HttpClient.js';
2
- export { defaultHttpClient } from './DefaultHttpClient.js';
3
- export { NodejsHttpClient } from './NodejsHttpClient.js';
4
- export { FetchHttpClient } from './FetchHttpClient.js';
5
- export type { Fetch, FetchOptions } from './FetchHttpClient.js';
6
- export type { HttpsNodejs, NodejsHttpClientRequest } from './NodejsHttpClient.js';
1
+ export type { HttpClient, HttpClientResponse, HttpClientRequestOptions } from './HttpClient.js'
2
+ export { defaultHttpClient } from './DefaultHttpClient.js'
3
+ export { NodejsHttpClient } from './NodejsHttpClient.js'
4
+ export { FetchHttpClient } from './FetchHttpClient.js'
5
+ export type { Fetch, FetchOptions } from './FetchHttpClient.js'
6
+ export type { HttpsNodejs, NodejsHttpClientRequest } from './NodejsHttpClient.js'