@bsv/sdk 1.1.13 → 1.1.15
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/dist/cjs/package.json +1 -1
- package/dist/cjs/src/compat/BIP39.js +272 -0
- package/dist/cjs/src/compat/BIP39.js.map +1 -0
- package/dist/cjs/src/index.js +5 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/primitives/Polynomial.js +81 -0
- package/dist/cjs/src/primitives/Polynomial.js.map +1 -0
- package/dist/cjs/src/primitives/PrivateKey.js +165 -0
- package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
- package/dist/cjs/src/primitives/index.js +5 -1
- package/dist/cjs/src/primitives/index.js.map +1 -1
- package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
- package/dist/cjs/src/script/templates/P2PKHT.js +99 -0
- package/dist/cjs/src/script/templates/P2PKHT.js.map +1 -0
- package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
- package/dist/cjs/src/totp/converters.js +14 -0
- package/dist/cjs/src/totp/converters.js.map +1 -0
- package/dist/cjs/src/totp/pike-totp.js +75 -0
- package/dist/cjs/src/totp/pike-totp.js.map +1 -0
- package/dist/cjs/src/totp/types.js +3 -0
- package/dist/cjs/src/totp/types.js.map +1 -0
- package/dist/cjs/src/transaction/broadcasters/ARC.js +4 -4
- package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -1
- package/dist/cjs/src/transaction/broadcasters/BRC22.js +25 -0
- package/dist/cjs/src/transaction/broadcasters/BRC22.js.map +1 -0
- package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
- package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +3 -3
- package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
- package/dist/cjs/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
- package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js +2 -2
- package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
- package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
- package/dist/cjs/src/transaction/http/DefaultHttpClient.js +2 -2
- package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/FetchHttpClient.js +2 -2
- package/dist/cjs/src/transaction/http/FetchHttpClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/NodejsHttpClient.js +2 -2
- package/dist/cjs/src/transaction/http/NodejsHttpClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/index.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/compat/BIP39.js +272 -0
- package/dist/esm/src/compat/BIP39.js.map +1 -0
- package/dist/esm/src/primitives/Polynomial.js +77 -0
- package/dist/esm/src/primitives/Polynomial.js.map +1 -0
- package/dist/esm/src/primitives/PrivateKey.js +143 -0
- package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
- package/dist/esm/src/primitives/index.js +2 -1
- package/dist/esm/src/primitives/index.js.map +1 -1
- package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
- package/dist/esm/src/script/templates/P2PKHT.js +96 -0
- package/dist/esm/src/script/templates/P2PKHT.js.map +1 -0
- package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
- package/dist/esm/src/totp/converters.js +9 -0
- package/dist/esm/src/totp/converters.js.map +1 -0
- package/dist/esm/src/totp/pike-totp.js +67 -0
- package/dist/esm/src/totp/pike-totp.js.map +1 -0
- package/dist/esm/src/totp/types.js +2 -0
- package/dist/esm/src/totp/types.js.map +1 -0
- package/dist/esm/src/transaction/broadcasters/ARC.js +7 -7
- package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -1
- package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
- package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
- package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +4 -4
- package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
- package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js +1 -1
- package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
- package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js +3 -3
- package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
- package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
- package/dist/esm/src/transaction/http/DefaultHttpClient.js +2 -2
- package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
- package/dist/esm/src/transaction/http/FetchHttpClient.js +2 -2
- package/dist/esm/src/transaction/http/FetchHttpClient.js.map +1 -1
- package/dist/esm/src/transaction/http/NodejsHttpClient.js +2 -2
- package/dist/esm/src/transaction/http/NodejsHttpClient.js.map +1 -1
- package/dist/esm/src/transaction/http/index.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/compat/BIP39.d.ts +132 -0
- package/dist/types/src/compat/BIP39.d.ts.map +1 -0
- package/dist/types/src/primitives/Polynomial.d.ts +32 -0
- package/dist/types/src/primitives/Polynomial.d.ts.map +1 -0
- package/dist/types/src/primitives/PrivateKey.d.ts +72 -0
- package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
- package/dist/types/src/primitives/index.d.ts +2 -1
- package/dist/types/src/primitives/index.d.ts.map +1 -1
- package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
- package/dist/types/src/script/templates/P2PKHT.d.ts +37 -0
- package/dist/types/src/script/templates/P2PKHT.d.ts.map +1 -0
- package/dist/types/src/totp/converters.d.ts +3 -0
- package/dist/types/src/totp/converters.d.ts.map +1 -0
- package/dist/types/src/totp/pike-totp.d.ts +25 -0
- package/dist/types/src/totp/pike-totp.d.ts.map +1 -0
- package/dist/types/src/totp/types.d.ts +11 -0
- package/dist/types/src/totp/types.d.ts.map +1 -0
- package/dist/types/src/transaction/broadcasters/ARC.d.ts +1 -1
- package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -1
- package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts +1 -1
- package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts.map +1 -1
- package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts +1 -1
- package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts.map +1 -1
- package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts +1 -1
- package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts.map +1 -1
- package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts +2 -2
- package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts.map +1 -1
- package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -1
- package/dist/types/src/transaction/http/DefaultHttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/FetchHttpClient.d.ts +7 -9
- package/dist/types/src/transaction/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/HttpClient.d.ts +5 -5
- package/dist/types/src/transaction/http/HttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/NodejsHttpClient.d.ts +5 -6
- package/dist/types/src/transaction/http/NodejsHttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/index.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/docs/primitives.md +231 -16
- package/docs/transaction.md +38 -37
- package/package.json +1 -1
- package/src/compat/__tests/BSM.test.ts +37 -37
- package/src/compat/__tests/ECIES.test.ts +71 -71
- package/src/compat/__tests/HD.test.ts +362 -362
- package/src/compat/__tests/Mnemonic.test.ts +147 -148
- package/src/compat/__tests/Mnemonic.vectors.ts +170 -170
- package/src/messages/__tests/EncryptedMessage.test.ts +16 -16
- package/src/primitives/Point.ts +29 -10
- package/src/primitives/Polynomial.ts +89 -0
- package/src/primitives/PrivateKey.ts +147 -1
- package/src/primitives/PublicKey.ts +17 -2
- package/src/primitives/__tests/AESGCM.test.ts +20 -20
- package/src/primitives/__tests/Hash.test.ts +2 -2
- package/src/primitives/__tests/PBKDF2.vectors.ts +93 -93
- package/src/primitives/__tests/PrivateKey.split.test.ts +70 -0
- package/src/primitives/__tests/PublicKey.test.ts +14 -1
- package/src/primitives/__tests/bug-31.test.ts +24 -26
- package/src/primitives/__tests/utils.test.ts +13 -13
- package/src/primitives/index.ts +2 -1
- package/src/script/__tests/Script.test.ts +1 -1
- package/src/script/__tests/SpendComplex.test.ts +6 -6
- package/src/script/__tests/script.invalid.vectors.ts +1464 -1464
- package/src/script/__tests/script.valid.vectors.ts +1962 -1962
- package/src/script/__tests/spend.valid.vectors.ts +1369 -1369
- package/src/script/templates/P2PKH.ts +6 -6
- package/src/script/templates/RPuzzle.ts +1 -1
- package/src/transaction/__tests/Transaction.test.ts +5 -5
- package/src/transaction/__tests/bump.invalid.vectors.ts +1 -1
- package/src/transaction/__tests/bump.valid.vectors.ts +3 -3
- package/src/transaction/broadcasters/ARC.ts +20 -21
- package/src/transaction/broadcasters/DefaultBroadcaster.ts +3 -3
- package/src/transaction/broadcasters/WhatsOnChainBroadcaster.ts +10 -10
- package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +7 -10
- package/src/transaction/chaintrackers/DefaultChainTracker.ts +3 -3
- package/src/transaction/chaintrackers/WhatsOnChain.ts +10 -12
- package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +13 -17
- package/src/transaction/fee-models/SatoshisPerKilobyte.ts +2 -2
- package/src/transaction/http/DefaultHttpClient.ts +13 -13
- package/src/transaction/http/FetchHttpClient.ts +14 -16
- package/src/transaction/http/HttpClient.ts +22 -23
- package/src/transaction/http/NodejsHttpClient.ts +23 -25
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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)
|
|
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)
|
|
10
|
+
write: (chunk: string) => void
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
on: (event: string, callback: (data: any) => void) => void
|
|
13
13
|
|
|
14
|
-
|
|
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 (
|
|
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'
|