@bsv/sdk 1.1.13 → 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 (136) 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/script/templates/P2PKH.js.map +1 -1
  13. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
  14. package/dist/cjs/src/transaction/broadcasters/ARC.js +4 -4
  15. package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -1
  16. package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  17. package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +3 -3
  18. package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
  19. package/dist/cjs/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
  20. package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js +2 -2
  21. package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
  22. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  23. package/dist/cjs/src/transaction/http/DefaultHttpClient.js +2 -2
  24. package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
  25. package/dist/cjs/src/transaction/http/FetchHttpClient.js +2 -2
  26. package/dist/cjs/src/transaction/http/FetchHttpClient.js.map +1 -1
  27. package/dist/cjs/src/transaction/http/NodejsHttpClient.js +2 -2
  28. package/dist/cjs/src/transaction/http/NodejsHttpClient.js.map +1 -1
  29. package/dist/cjs/src/transaction/http/index.js.map +1 -1
  30. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  31. package/dist/esm/src/primitives/Point.js +28 -8
  32. package/dist/esm/src/primitives/Point.js.map +1 -1
  33. package/dist/esm/src/primitives/Polynomial.js +77 -0
  34. package/dist/esm/src/primitives/Polynomial.js.map +1 -0
  35. package/dist/esm/src/primitives/PrivateKey.js +143 -0
  36. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  37. package/dist/esm/src/primitives/PublicKey.js +16 -2
  38. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  39. package/dist/esm/src/primitives/index.js +2 -1
  40. package/dist/esm/src/primitives/index.js.map +1 -1
  41. package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
  42. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
  43. package/dist/esm/src/transaction/broadcasters/ARC.js +7 -7
  44. package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -1
  45. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
  46. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  47. package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +4 -4
  48. package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
  49. package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js +1 -1
  50. package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
  51. package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js +3 -3
  52. package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
  53. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  54. package/dist/esm/src/transaction/http/DefaultHttpClient.js +2 -2
  55. package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
  56. package/dist/esm/src/transaction/http/FetchHttpClient.js +2 -2
  57. package/dist/esm/src/transaction/http/FetchHttpClient.js.map +1 -1
  58. package/dist/esm/src/transaction/http/NodejsHttpClient.js +2 -2
  59. package/dist/esm/src/transaction/http/NodejsHttpClient.js.map +1 -1
  60. package/dist/esm/src/transaction/http/index.js.map +1 -1
  61. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  62. package/dist/types/src/primitives/Point.d.ts +19 -1
  63. package/dist/types/src/primitives/Point.d.ts.map +1 -1
  64. package/dist/types/src/primitives/Polynomial.d.ts +32 -0
  65. package/dist/types/src/primitives/Polynomial.d.ts.map +1 -0
  66. package/dist/types/src/primitives/PrivateKey.d.ts +72 -0
  67. package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
  68. package/dist/types/src/primitives/PublicKey.d.ts +12 -1
  69. package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
  70. package/dist/types/src/primitives/index.d.ts +2 -1
  71. package/dist/types/src/primitives/index.d.ts.map +1 -1
  72. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
  73. package/dist/types/src/transaction/broadcasters/ARC.d.ts +1 -1
  74. package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -1
  75. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts +1 -1
  76. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts.map +1 -1
  77. package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts +1 -1
  78. package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts.map +1 -1
  79. package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts +1 -1
  80. package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts.map +1 -1
  81. package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts +2 -2
  82. package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts.map +1 -1
  83. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -1
  84. package/dist/types/src/transaction/http/DefaultHttpClient.d.ts.map +1 -1
  85. package/dist/types/src/transaction/http/FetchHttpClient.d.ts +7 -9
  86. package/dist/types/src/transaction/http/FetchHttpClient.d.ts.map +1 -1
  87. package/dist/types/src/transaction/http/HttpClient.d.ts +5 -5
  88. package/dist/types/src/transaction/http/HttpClient.d.ts.map +1 -1
  89. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts +5 -6
  90. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts.map +1 -1
  91. package/dist/types/src/transaction/http/index.d.ts.map +1 -1
  92. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  93. package/docs/primitives.md +231 -16
  94. package/docs/transaction.md +38 -37
  95. package/package.json +1 -1
  96. package/src/compat/__tests/BSM.test.ts +37 -37
  97. package/src/compat/__tests/ECIES.test.ts +71 -71
  98. package/src/compat/__tests/HD.test.ts +362 -362
  99. package/src/compat/__tests/Mnemonic.test.ts +147 -148
  100. package/src/compat/__tests/Mnemonic.vectors.ts +170 -170
  101. package/src/messages/__tests/EncryptedMessage.test.ts +16 -16
  102. package/src/primitives/Point.ts +29 -10
  103. package/src/primitives/Polynomial.ts +89 -0
  104. package/src/primitives/PrivateKey.ts +147 -1
  105. package/src/primitives/PublicKey.ts +17 -2
  106. package/src/primitives/__tests/AESGCM.test.ts +20 -20
  107. package/src/primitives/__tests/Hash.test.ts +2 -2
  108. package/src/primitives/__tests/PBKDF2.vectors.ts +93 -93
  109. package/src/primitives/__tests/PrivateKey.split.test.ts +70 -0
  110. package/src/primitives/__tests/PublicKey.test.ts +14 -1
  111. package/src/primitives/__tests/bug-31.test.ts +24 -26
  112. package/src/primitives/__tests/utils.test.ts +13 -13
  113. package/src/primitives/index.ts +2 -1
  114. package/src/script/__tests/Script.test.ts +1 -1
  115. package/src/script/__tests/SpendComplex.test.ts +6 -6
  116. package/src/script/__tests/script.invalid.vectors.ts +1464 -1464
  117. package/src/script/__tests/script.valid.vectors.ts +1962 -1962
  118. package/src/script/__tests/spend.valid.vectors.ts +1369 -1369
  119. package/src/script/templates/P2PKH.ts +6 -6
  120. package/src/script/templates/RPuzzle.ts +1 -1
  121. package/src/transaction/__tests/Transaction.test.ts +5 -5
  122. package/src/transaction/__tests/bump.invalid.vectors.ts +1 -1
  123. package/src/transaction/__tests/bump.valid.vectors.ts +3 -3
  124. package/src/transaction/broadcasters/ARC.ts +20 -21
  125. package/src/transaction/broadcasters/DefaultBroadcaster.ts +3 -3
  126. package/src/transaction/broadcasters/WhatsOnChainBroadcaster.ts +10 -10
  127. package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +7 -10
  128. package/src/transaction/chaintrackers/DefaultChainTracker.ts +3 -3
  129. package/src/transaction/chaintrackers/WhatsOnChain.ts +10 -12
  130. package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +13 -17
  131. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +2 -2
  132. package/src/transaction/http/DefaultHttpClient.ts +13 -13
  133. package/src/transaction/http/FetchHttpClient.ts +14 -16
  134. package/src/transaction/http/HttpClient.ts +22 -23
  135. package/src/transaction/http/NodejsHttpClient.ts +23 -25
  136. package/src/transaction/http/index.ts +6 -6
@@ -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'