@bsv/sdk 2.0.7 → 2.0.9

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 (89) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/primitives/index.js.map +1 -1
  3. package/dist/cjs/src/script/templates/P2PKH.js +9 -43
  4. package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
  5. package/dist/cjs/src/script/templates/PushDrop.js +10 -40
  6. package/dist/cjs/src/script/templates/PushDrop.js.map +1 -1
  7. package/dist/cjs/src/script/templates/SignatureUtils.js +77 -0
  8. package/dist/cjs/src/script/templates/SignatureUtils.js.map +1 -0
  9. package/dist/cjs/src/transaction/Transaction.js +45 -0
  10. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  11. package/dist/cjs/src/transaction/http/BinaryFetchClient.js +2 -28
  12. package/dist/cjs/src/transaction/http/BinaryFetchClient.js.map +1 -1
  13. package/dist/cjs/src/transaction/http/NodejsHttpClient.js +2 -28
  14. package/dist/cjs/src/transaction/http/NodejsHttpClient.js.map +1 -1
  15. package/dist/cjs/src/transaction/http/NodejsHttpRequestUtils.js +43 -0
  16. package/dist/cjs/src/transaction/http/NodejsHttpRequestUtils.js.map +1 -0
  17. package/dist/cjs/src/wallet/substrates/InvokableWalletBase.js +98 -0
  18. package/dist/cjs/src/wallet/substrates/InvokableWalletBase.js.map +1 -0
  19. package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js +3 -85
  20. package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
  21. package/dist/cjs/src/wallet/substrates/XDM.js +3 -85
  22. package/dist/cjs/src/wallet/substrates/XDM.js.map +1 -1
  23. package/dist/cjs/src/wallet/substrates/index.js +3 -1
  24. package/dist/cjs/src/wallet/substrates/index.js.map +1 -1
  25. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  26. package/dist/esm/src/primitives/index.js.map +1 -1
  27. package/dist/esm/src/script/templates/P2PKH.js +10 -46
  28. package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
  29. package/dist/esm/src/script/templates/PushDrop.js +10 -42
  30. package/dist/esm/src/script/templates/PushDrop.js.map +1 -1
  31. package/dist/esm/src/script/templates/SignatureUtils.js +69 -0
  32. package/dist/esm/src/script/templates/SignatureUtils.js.map +1 -0
  33. package/dist/esm/src/transaction/Transaction.js +45 -0
  34. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  35. package/dist/esm/src/transaction/http/BinaryFetchClient.js +2 -28
  36. package/dist/esm/src/transaction/http/BinaryFetchClient.js.map +1 -1
  37. package/dist/esm/src/transaction/http/NodejsHttpClient.js +2 -28
  38. package/dist/esm/src/transaction/http/NodejsHttpClient.js.map +1 -1
  39. package/dist/esm/src/transaction/http/NodejsHttpRequestUtils.js +40 -0
  40. package/dist/esm/src/transaction/http/NodejsHttpRequestUtils.js.map +1 -0
  41. package/dist/esm/src/wallet/substrates/InvokableWalletBase.js +94 -0
  42. package/dist/esm/src/wallet/substrates/InvokableWalletBase.js.map +1 -0
  43. package/dist/esm/src/wallet/substrates/ReactNativeWebView.js +3 -85
  44. package/dist/esm/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
  45. package/dist/esm/src/wallet/substrates/XDM.js +3 -85
  46. package/dist/esm/src/wallet/substrates/XDM.js.map +1 -1
  47. package/dist/esm/src/wallet/substrates/index.js +1 -0
  48. package/dist/esm/src/wallet/substrates/index.js.map +1 -1
  49. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  50. package/dist/types/src/primitives/index.d.ts +1 -1
  51. package/dist/types/src/primitives/index.d.ts.map +1 -1
  52. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
  53. package/dist/types/src/script/templates/PushDrop.d.ts.map +1 -1
  54. package/dist/types/src/script/templates/SignatureUtils.d.ts +32 -0
  55. package/dist/types/src/script/templates/SignatureUtils.d.ts.map +1 -0
  56. package/dist/types/src/transaction/Transaction.d.ts +10 -0
  57. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  58. package/dist/types/src/transaction/http/BinaryFetchClient.d.ts +1 -1
  59. package/dist/types/src/transaction/http/BinaryFetchClient.d.ts.map +1 -1
  60. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts +1 -1
  61. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts.map +1 -1
  62. package/dist/types/src/transaction/http/NodejsHttpRequestUtils.d.ts +22 -0
  63. package/dist/types/src/transaction/http/NodejsHttpRequestUtils.d.ts.map +1 -0
  64. package/dist/types/src/wallet/substrates/InvokableWalletBase.d.ts +41 -0
  65. package/dist/types/src/wallet/substrates/InvokableWalletBase.d.ts.map +1 -0
  66. package/dist/types/src/wallet/substrates/ReactNativeWebView.d.ts +2 -403
  67. package/dist/types/src/wallet/substrates/ReactNativeWebView.d.ts.map +1 -1
  68. package/dist/types/src/wallet/substrates/XDM.d.ts +2 -403
  69. package/dist/types/src/wallet/substrates/XDM.d.ts.map +1 -1
  70. package/dist/types/src/wallet/substrates/index.d.ts +1 -0
  71. package/dist/types/src/wallet/substrates/index.d.ts.map +1 -1
  72. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  73. package/dist/umd/bundle.js +3 -3
  74. package/dist/umd/bundle.js.map +1 -1
  75. package/docs/reference/transaction.md +24 -1
  76. package/package.json +1 -1
  77. package/src/primitives/index.ts +1 -1
  78. package/src/script/templates/P2PKH.ts +10 -59
  79. package/src/script/templates/PushDrop.ts +11 -54
  80. package/src/script/templates/SignatureUtils.ts +111 -0
  81. package/src/transaction/Transaction.ts +47 -0
  82. package/src/transaction/__tests/Transaction.test.ts +179 -9
  83. package/src/transaction/http/BinaryFetchClient.ts +8 -32
  84. package/src/transaction/http/NodejsHttpClient.ts +8 -32
  85. package/src/transaction/http/NodejsHttpRequestUtils.ts +68 -0
  86. package/src/wallet/substrates/InvokableWalletBase.ts +176 -0
  87. package/src/wallet/substrates/ReactNativeWebView.ts +3 -491
  88. package/src/wallet/substrates/XDM.ts +3 -491
  89. package/src/wallet/substrates/index.ts +1 -0
@@ -3,6 +3,7 @@ import {
3
3
  HttpClientRequestOptions,
4
4
  HttpClientResponse
5
5
  } from './HttpClient.js'
6
+ import { HttpsModuleLike, executeNodejsRequest } from './NodejsHttpRequestUtils.js'
6
7
 
7
8
  /** Node Https module interface limited to options needed by ts-sdk */
8
9
  export interface BinaryHttpsNodejs {
@@ -19,7 +20,7 @@ export interface BinaryNodejsHttpClientRequest {
19
20
 
20
21
  on: (event: string, callback: (data: any) => void) => void
21
22
 
22
- end: (() => void) & (() => void)
23
+ end: () => void
23
24
  }
24
25
 
25
26
  /**
@@ -32,37 +33,12 @@ export class BinaryNodejsHttpClient implements HttpClient {
32
33
  url: string,
33
34
  requestOptions: HttpClientRequestOptions
34
35
  ): Promise<HttpClientResponse> {
35
- return await new Promise((resolve, reject) => {
36
- const req = this.https.request(url, requestOptions, (res) => {
37
- let body = ''
38
- res.on('data', (chunk: string) => {
39
- body += chunk
40
- })
41
- res.on('end', () => {
42
- const ok = res.statusCode >= 200 && res.statusCode <= 299
43
- const mediaType = res.headers['content-type']
44
- const data =
45
- body !== '' && typeof mediaType === 'string' && mediaType.startsWith('application/json')
46
- ? JSON.parse(body)
47
- : body
48
- resolve({
49
- status: res.statusCode,
50
- statusText: res.statusMessage,
51
- ok,
52
- data
53
- })
54
- })
55
- })
56
-
57
- req.on('error', (error: Error) => {
58
- reject(error)
59
- })
60
-
61
- if (requestOptions.data !== null && requestOptions.data !== undefined) {
62
- req.write(Buffer.from(requestOptions.data))
63
- }
64
- req.end()
65
- })
36
+ return await executeNodejsRequest(
37
+ this.https as unknown as HttpsModuleLike,
38
+ url,
39
+ requestOptions,
40
+ (data) => Buffer.from(data)
41
+ )
66
42
  }
67
43
  }
68
44
 
@@ -3,6 +3,7 @@ import {
3
3
  HttpClientRequestOptions,
4
4
  HttpClientResponse
5
5
  } from './HttpClient.js'
6
+ import { HttpsModuleLike, executeNodejsRequest } from './NodejsHttpRequestUtils.js'
6
7
 
7
8
  /** Node Https module interface limited to options needed by ts-sdk */
8
9
  export interface HttpsNodejs {
@@ -19,7 +20,7 @@ export interface NodejsHttpClientRequest {
19
20
 
20
21
  on: (event: string, callback: (data: any) => void) => void
21
22
 
22
- end: (() => void) & (() => void)
23
+ end: () => void
23
24
  }
24
25
 
25
26
  /**
@@ -32,36 +33,11 @@ export class NodejsHttpClient implements HttpClient {
32
33
  url: string,
33
34
  requestOptions: HttpClientRequestOptions
34
35
  ): Promise<HttpClientResponse> {
35
- return await new Promise((resolve, reject) => {
36
- const req = this.https.request(url, requestOptions, (res) => {
37
- let body = ''
38
- res.on('data', (chunk: string) => {
39
- body += chunk
40
- })
41
- res.on('end', () => {
42
- const ok = res.statusCode >= 200 && res.statusCode <= 299
43
- const mediaType = res.headers['content-type']
44
- const data =
45
- body !== '' && typeof mediaType === 'string' && mediaType.startsWith('application/json')
46
- ? JSON.parse(body)
47
- : body
48
- resolve({
49
- status: res.statusCode,
50
- statusText: res.statusMessage,
51
- ok,
52
- data
53
- })
54
- })
55
- })
56
-
57
- req.on('error', (error: Error) => {
58
- reject(error)
59
- })
60
-
61
- if (requestOptions.data !== null && requestOptions.data !== undefined) {
62
- req.write(JSON.stringify(requestOptions.data))
63
- }
64
- req.end()
65
- })
36
+ return await executeNodejsRequest(
37
+ this.https as unknown as HttpsModuleLike,
38
+ url,
39
+ requestOptions,
40
+ (data) => JSON.stringify(data)
41
+ )
66
42
  }
67
43
  }
@@ -0,0 +1,68 @@
1
+ import {
2
+ HttpClientRequestOptions,
3
+ HttpClientResponse
4
+ } from './HttpClient.js'
5
+
6
+ /** Common interface for Node.js https module request objects */
7
+ export interface NodejsRequestLike {
8
+ write: (chunk: any) => void
9
+ on: (event: string, callback: (data: any) => void) => void
10
+ end: () => void
11
+ }
12
+
13
+ /** Common interface for Node.js https modules */
14
+ export interface HttpsModuleLike {
15
+ request: (
16
+ url: string,
17
+ options: HttpClientRequestOptions,
18
+ callback: (res: any) => void
19
+ ) => NodejsRequestLike
20
+ }
21
+
22
+ /**
23
+ * Shared implementation for handling Node.js HTTP requests.
24
+ * Used by both NodejsHttpClient and BinaryNodejsHttpClient.
25
+ *
26
+ * @param https The Node.js https module (or compatible)
27
+ * @param url The URL to make the request to
28
+ * @param requestOptions The request configuration
29
+ * @param serializeData Function to serialize the request data for writing
30
+ */
31
+ export function executeNodejsRequest(
32
+ https: HttpsModuleLike,
33
+ url: string,
34
+ requestOptions: HttpClientRequestOptions,
35
+ serializeData: (data: any) => any
36
+ ): Promise<HttpClientResponse> {
37
+ return new Promise((resolve, reject) => {
38
+ const req = https.request(url, requestOptions, (res) => {
39
+ let body = ''
40
+ res.on('data', (chunk: string) => {
41
+ body += chunk
42
+ })
43
+ res.on('end', () => {
44
+ const ok = res.statusCode >= 200 && res.statusCode <= 299
45
+ const mediaType = res.headers['content-type']
46
+ const data =
47
+ body !== '' && typeof mediaType === 'string' && mediaType.startsWith('application/json')
48
+ ? JSON.parse(body)
49
+ : body
50
+ resolve({
51
+ status: res.statusCode,
52
+ statusText: res.statusMessage,
53
+ ok,
54
+ data
55
+ })
56
+ })
57
+ })
58
+
59
+ req.on('error', (error: Error) => {
60
+ reject(error)
61
+ })
62
+
63
+ if (requestOptions.data !== null && requestOptions.data !== undefined) {
64
+ req.write(serializeData(requestOptions.data))
65
+ }
66
+ req.end()
67
+ })
68
+ }
@@ -0,0 +1,176 @@
1
+ import {
2
+ WalletInterface,
3
+ CreateActionArgs,
4
+ CreateActionResult,
5
+ SignActionArgs,
6
+ SignActionResult,
7
+ AbortActionArgs,
8
+ AbortActionResult,
9
+ ListActionsArgs,
10
+ ListActionsResult,
11
+ InternalizeActionArgs,
12
+ InternalizeActionResult,
13
+ ListOutputsArgs,
14
+ ListOutputsResult,
15
+ RelinquishOutputArgs,
16
+ RelinquishOutputResult,
17
+ GetPublicKeyArgs,
18
+ GetPublicKeyResult,
19
+ RevealCounterpartyKeyLinkageArgs,
20
+ RevealCounterpartyKeyLinkageResult,
21
+ RevealSpecificKeyLinkageArgs,
22
+ RevealSpecificKeyLinkageResult,
23
+ WalletEncryptArgs,
24
+ WalletEncryptResult,
25
+ WalletDecryptArgs,
26
+ WalletDecryptResult,
27
+ CreateHmacArgs,
28
+ CreateHmacResult,
29
+ VerifyHmacArgs,
30
+ VerifyHmacResult,
31
+ CreateSignatureArgs,
32
+ CreateSignatureResult,
33
+ VerifySignatureArgs,
34
+ VerifySignatureResult,
35
+ AcquireCertificateArgs,
36
+ AcquireCertificateResult,
37
+ ListCertificatesArgs,
38
+ ListCertificatesResult,
39
+ ProveCertificateArgs,
40
+ ProveCertificateResult,
41
+ RelinquishCertificateArgs,
42
+ RelinquishCertificateResult,
43
+ DiscoverByIdentityKeyArgs,
44
+ DiscoverCertificatesResult,
45
+ DiscoverByAttributesArgs,
46
+ AuthenticatedResult,
47
+ GetHeightResult,
48
+ GetHeaderArgs,
49
+ GetHeaderResult,
50
+ GetNetworkResult,
51
+ GetVersionResult
52
+ } from '../Wallet.interfaces.js'
53
+ import { CallType } from './WalletWireCalls.js'
54
+
55
+ /**
56
+ * Abstract base class for WalletInterface substrates that delegate all
57
+ * wallet method calls through an `invoke` transport mechanism.
58
+ *
59
+ * Subclasses only need to implement the `invoke` method to provide
60
+ * the specific transport (e.g. XDM postMessage, ReactNative bridge).
61
+ */
62
+ export abstract class InvokableWalletBase implements WalletInterface {
63
+ abstract invoke(call: CallType, args: any): Promise<any>
64
+
65
+ async createAction(args: CreateActionArgs): Promise<CreateActionResult> {
66
+ return await this.invoke('createAction', args)
67
+ }
68
+
69
+ async signAction(args: SignActionArgs): Promise<SignActionResult> {
70
+ return await this.invoke('signAction', args)
71
+ }
72
+
73
+ async abortAction(args: AbortActionArgs): Promise<AbortActionResult> {
74
+ return await this.invoke('abortAction', args)
75
+ }
76
+
77
+ async listActions(args: ListActionsArgs): Promise<ListActionsResult> {
78
+ return await this.invoke('listActions', args)
79
+ }
80
+
81
+ async internalizeAction(args: InternalizeActionArgs): Promise<InternalizeActionResult> {
82
+ return await this.invoke('internalizeAction', args)
83
+ }
84
+
85
+ async listOutputs(args: ListOutputsArgs): Promise<ListOutputsResult> {
86
+ return await this.invoke('listOutputs', args)
87
+ }
88
+
89
+ async relinquishOutput(args: RelinquishOutputArgs): Promise<RelinquishOutputResult> {
90
+ return await this.invoke('relinquishOutput', args)
91
+ }
92
+
93
+ async getPublicKey(args: GetPublicKeyArgs): Promise<GetPublicKeyResult> {
94
+ return await this.invoke('getPublicKey', args)
95
+ }
96
+
97
+ async revealCounterpartyKeyLinkage(args: RevealCounterpartyKeyLinkageArgs): Promise<RevealCounterpartyKeyLinkageResult> {
98
+ return await this.invoke('revealCounterpartyKeyLinkage', args)
99
+ }
100
+
101
+ async revealSpecificKeyLinkage(args: RevealSpecificKeyLinkageArgs): Promise<RevealSpecificKeyLinkageResult> {
102
+ return await this.invoke('revealSpecificKeyLinkage', args)
103
+ }
104
+
105
+ async encrypt(args: WalletEncryptArgs): Promise<WalletEncryptResult> {
106
+ return await this.invoke('encrypt', args)
107
+ }
108
+
109
+ async decrypt(args: WalletDecryptArgs): Promise<WalletDecryptResult> {
110
+ return await this.invoke('decrypt', args)
111
+ }
112
+
113
+ async createHmac(args: CreateHmacArgs): Promise<CreateHmacResult> {
114
+ return await this.invoke('createHmac', args)
115
+ }
116
+
117
+ async verifyHmac(args: VerifyHmacArgs): Promise<VerifyHmacResult> {
118
+ return await this.invoke('verifyHmac', args)
119
+ }
120
+
121
+ async createSignature(args: CreateSignatureArgs): Promise<CreateSignatureResult> {
122
+ return await this.invoke('createSignature', args)
123
+ }
124
+
125
+ async verifySignature(args: VerifySignatureArgs): Promise<VerifySignatureResult> {
126
+ return await this.invoke('verifySignature', args)
127
+ }
128
+
129
+ async acquireCertificate(args: AcquireCertificateArgs): Promise<AcquireCertificateResult> {
130
+ return await this.invoke('acquireCertificate', args)
131
+ }
132
+
133
+ async listCertificates(args: ListCertificatesArgs): Promise<ListCertificatesResult> {
134
+ return await this.invoke('listCertificates', args)
135
+ }
136
+
137
+ async proveCertificate(args: ProveCertificateArgs): Promise<ProveCertificateResult> {
138
+ return await this.invoke('proveCertificate', args)
139
+ }
140
+
141
+ async relinquishCertificate(args: RelinquishCertificateArgs): Promise<RelinquishCertificateResult> {
142
+ return await this.invoke('relinquishCertificate', args)
143
+ }
144
+
145
+ async discoverByIdentityKey(args: DiscoverByIdentityKeyArgs): Promise<DiscoverCertificatesResult> {
146
+ return await this.invoke('discoverByIdentityKey', args)
147
+ }
148
+
149
+ async discoverByAttributes(args: DiscoverByAttributesArgs): Promise<DiscoverCertificatesResult> {
150
+ return await this.invoke('discoverByAttributes', args)
151
+ }
152
+
153
+ async isAuthenticated(args: {}): Promise<AuthenticatedResult> {
154
+ return await this.invoke('isAuthenticated', args)
155
+ }
156
+
157
+ async waitForAuthentication(args: {}): Promise<AuthenticatedResult> {
158
+ return await this.invoke('waitForAuthentication', args)
159
+ }
160
+
161
+ async getHeight(args: {}): Promise<GetHeightResult> {
162
+ return await this.invoke('getHeight', args)
163
+ }
164
+
165
+ async getHeaderForHeight(args: GetHeaderArgs): Promise<GetHeaderResult> {
166
+ return await this.invoke('getHeaderForHeight', args)
167
+ }
168
+
169
+ async getNetwork(args: {}): Promise<GetNetworkResult> {
170
+ return await this.invoke('getNetwork', args)
171
+ }
172
+
173
+ async getVersion(args: {}): Promise<GetVersionResult> {
174
+ return await this.invoke('getVersion', args)
175
+ }
176
+ }