@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
package/docs/transaction.md
CHANGED
|
@@ -6,14 +6,14 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
6
6
|
|
|
7
7
|
| | |
|
|
8
8
|
| --- | --- |
|
|
9
|
-
| [ArcConfig](#interface-arcconfig) | [
|
|
10
|
-
| [BroadcastFailure](#interface-broadcastfailure) | [
|
|
11
|
-
| [BroadcastResponse](#interface-broadcastresponse) | [
|
|
12
|
-
| [Broadcaster](#interface-broadcaster) | [
|
|
13
|
-
| [ChainTracker](#interface-chaintracker) | [
|
|
14
|
-
| [FeeModel](#interface-feemodel) | [
|
|
15
|
-
| [Fetch](#interface-fetch) | [TransactionOutput](#interface-transactionoutput) |
|
|
9
|
+
| [ArcConfig](#interface-arcconfig) | [HttpClientRequestOptions](#interface-httpclientrequestoptions) |
|
|
10
|
+
| [BroadcastFailure](#interface-broadcastfailure) | [HttpsNodejs](#interface-httpsnodejs) |
|
|
11
|
+
| [BroadcastResponse](#interface-broadcastresponse) | [MerklePathLeaf](#interface-merklepathleaf) |
|
|
12
|
+
| [Broadcaster](#interface-broadcaster) | [NodejsHttpClientRequest](#interface-nodejshttpclientrequest) |
|
|
13
|
+
| [ChainTracker](#interface-chaintracker) | [TransactionInput](#interface-transactioninput) |
|
|
14
|
+
| [FeeModel](#interface-feemodel) | [TransactionOutput](#interface-transactionoutput) |
|
|
16
15
|
| [FetchOptions](#interface-fetchoptions) | [WhatsOnChainConfig](#interface-whatsonchainconfig) |
|
|
16
|
+
| [HttpClient](#interface-httpclient) | |
|
|
17
17
|
|
|
18
18
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
19
19
|
|
|
@@ -195,7 +195,7 @@ An interface for HTTP client used to make HTTP requests.
|
|
|
195
195
|
|
|
196
196
|
```ts
|
|
197
197
|
export interface HttpClient {
|
|
198
|
-
request<T = any, D = any>(url: string, options: HttpClientRequestOptions<D>)
|
|
198
|
+
request: <T = any, D = any>(url: string, options: HttpClientRequestOptions<D>) => Promise<HttpClientResponse<T>>;
|
|
199
199
|
}
|
|
200
200
|
```
|
|
201
201
|
|
|
@@ -203,21 +203,14 @@ export interface HttpClient {
|
|
|
203
203
|
|
|
204
204
|
<summary>Interface HttpClient Details</summary>
|
|
205
205
|
|
|
206
|
-
####
|
|
206
|
+
#### Property request
|
|
207
207
|
|
|
208
208
|
Makes a request to the server.
|
|
209
209
|
|
|
210
210
|
```ts
|
|
211
|
-
request<T = any, D = any>(url: string, options: HttpClientRequestOptions<D>)
|
|
211
|
+
request: <T = any, D = any>(url: string, options: HttpClientRequestOptions<D>) => Promise<HttpClientResponse<T>>
|
|
212
212
|
```
|
|
213
213
|
|
|
214
|
-
Argument Details
|
|
215
|
-
|
|
216
|
-
+ **url**
|
|
217
|
-
+ The URL to make the request to.
|
|
218
|
-
+ **options**
|
|
219
|
-
+ The request configuration.
|
|
220
|
-
|
|
221
214
|
</details>
|
|
222
215
|
|
|
223
216
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
@@ -274,7 +267,7 @@ Node.js Https module interface limited to options needed by ts-sdk
|
|
|
274
267
|
|
|
275
268
|
```ts
|
|
276
269
|
export interface HttpsNodejs {
|
|
277
|
-
request(url: string, options: HttpClientRequestOptions, callback: (res: any) => void)
|
|
270
|
+
request: (url: string, options: HttpClientRequestOptions, callback: (res: any) => void) => NodejsHttpClientRequest;
|
|
278
271
|
}
|
|
279
272
|
```
|
|
280
273
|
|
|
@@ -287,23 +280,9 @@ Nodejs result of the Node.js https.request call limited to options needed by ts-
|
|
|
287
280
|
|
|
288
281
|
```ts
|
|
289
282
|
export interface NodejsHttpClientRequest {
|
|
290
|
-
write(chunk: string)
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
end(): void;
|
|
294
|
-
}
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
298
|
-
|
|
299
|
-
---
|
|
300
|
-
### Interface: Fetch
|
|
301
|
-
|
|
302
|
-
fetch function interface limited to options needed by ts-sdk
|
|
303
|
-
|
|
304
|
-
```ts
|
|
305
|
-
export interface Fetch {
|
|
306
|
-
(url: string, options: FetchOptions): Promise<Response>;
|
|
283
|
+
write: (chunk: string) => void;
|
|
284
|
+
on: (event: string, callback: (data: any) => void) => void;
|
|
285
|
+
end: (() => void) & (() => void);
|
|
307
286
|
}
|
|
308
287
|
```
|
|
309
288
|
|
|
@@ -723,7 +702,7 @@ Adapter for Node.js Https module to be used as HttpClient
|
|
|
723
702
|
|
|
724
703
|
```ts
|
|
725
704
|
export class NodejsHttpClient implements HttpClient {
|
|
726
|
-
constructor(private https: HttpsNodejs)
|
|
705
|
+
constructor(private readonly https: HttpsNodejs)
|
|
727
706
|
async request(url: string, requestOptions: HttpClientRequestOptions): Promise<HttpClientResponse>
|
|
728
707
|
}
|
|
729
708
|
```
|
|
@@ -737,7 +716,7 @@ Adapter for Node.js Https module to be used as HttpClient
|
|
|
737
716
|
|
|
738
717
|
```ts
|
|
739
718
|
export class FetchHttpClient implements HttpClient {
|
|
740
|
-
constructor(private fetch: Fetch)
|
|
719
|
+
constructor(private readonly fetch: Fetch)
|
|
741
720
|
async request<D>(url: string, options: HttpClientRequestOptions): Promise<HttpClientResponse<D>>
|
|
742
721
|
}
|
|
743
722
|
```
|
|
@@ -1397,6 +1376,15 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
1397
1376
|
---
|
|
1398
1377
|
## Types
|
|
1399
1378
|
|
|
1379
|
+
| |
|
|
1380
|
+
| --- |
|
|
1381
|
+
| [Fetch](#type-fetch) |
|
|
1382
|
+
| [HttpClientResponse](#type-httpclientresponse) |
|
|
1383
|
+
|
|
1384
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1385
|
+
|
|
1386
|
+
---
|
|
1387
|
+
|
|
1400
1388
|
### Type: HttpClientResponse
|
|
1401
1389
|
|
|
1402
1390
|
An interface for the response returned by the request method.
|
|
@@ -1417,6 +1405,19 @@ export type HttpClientResponse<T = any> = {
|
|
|
1417
1405
|
|
|
1418
1406
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1419
1407
|
|
|
1408
|
+
---
|
|
1409
|
+
### Type: Fetch
|
|
1410
|
+
|
|
1411
|
+
fetch function interface limited to options needed by ts-sdk
|
|
1412
|
+
|
|
1413
|
+
Makes a request to the server.
|
|
1414
|
+
|
|
1415
|
+
```ts
|
|
1416
|
+
export type Fetch = (url: string, options: FetchOptions) => Promise<Response>
|
|
1417
|
+
```
|
|
1418
|
+
|
|
1419
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1420
|
+
|
|
1420
1421
|
---
|
|
1421
1422
|
## Variables
|
|
1422
1423
|
|
package/package.json
CHANGED
|
@@ -6,44 +6,44 @@ import Signature from '../../../dist/cjs/src/primitives/Signature'
|
|
|
6
6
|
import BigNumber from '../../../dist/cjs/src/primitives/BigNumber'
|
|
7
7
|
|
|
8
8
|
describe('BSM', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
9
|
+
describe('magicHash', () => {
|
|
10
|
+
it('should return a hash', () => {
|
|
11
|
+
const buf = toArray('001122', 'hex')
|
|
12
|
+
const hashBuf = magicHash(buf)
|
|
13
|
+
expect(hashBuf.length).toEqual(32)
|
|
15
14
|
})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
})
|
|
16
|
+
describe('sign', () => {
|
|
17
|
+
const messageBuf = toArray('this is my message', 'utf8')
|
|
18
|
+
const privateKey = new PrivateKey(42)
|
|
19
|
+
it('should return a signature', () => {
|
|
20
|
+
const sig = sign(messageBuf, privateKey).toDER()
|
|
21
|
+
expect(sig.length).toEqual(70)
|
|
23
22
|
})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
})
|
|
24
|
+
describe('verify', () => {
|
|
25
|
+
const messageBuf = toArray('this is my message', 'utf8')
|
|
26
|
+
const privateKey = new PrivateKey(42)
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
})
|
|
32
|
-
it('Should verify a signed message in base64', () => {
|
|
33
|
-
const message = toArray("Texas", 'utf8')
|
|
34
|
-
const signature = Signature.fromCompact('IAV89EkfHSzAIA8cEWbbKHUYzJqcShkpWaXGJ5+mf4+YIlf3XNlr0bj9X60sNe1A7+x9qyk+zmXropMDY4370n8=', 'base64')
|
|
35
|
-
const publicKey = PublicKey.fromString('03d4d1a6c5d8c03b0e671bc1891b69afaecb40c0686188fe9019f93581b43e8334')
|
|
36
|
-
expect(verify(message, signature, publicKey)).toBe(true)
|
|
37
|
-
})
|
|
38
|
-
it('Should be able to calculate the recovery number for a signature and public key', () => {
|
|
39
|
-
const message = toArray("Texas", 'utf8')
|
|
40
|
-
const signature = Signature.fromCompact('IAV89EkfHSzAIA8cEWbbKHUYzJqcShkpWaXGJ5+mf4+YIlf3XNlr0bj9X60sNe1A7+x9qyk+zmXropMDY4370n8=', 'base64')
|
|
41
|
-
const publicKey = PublicKey.fromString('03d4d1a6c5d8c03b0e671bc1891b69afaecb40c0686188fe9019f93581b43e8334')
|
|
42
|
-
const msgHash = new BigNumber(magicHash(message))
|
|
43
|
-
const recovery = signature.CalculateRecoveryFactor(publicKey, msgHash)
|
|
44
|
-
expect(recovery).toBe(1)
|
|
45
|
-
const recoveredPubkey = signature.RecoverPublicKey(recovery, msgHash) as PublicKey
|
|
46
|
-
expect(recoveredPubkey.toDER()).toEqual(publicKey.toDER())
|
|
47
|
-
})
|
|
28
|
+
it('should verify a signed message', () => {
|
|
29
|
+
const sig = sign(messageBuf, privateKey)
|
|
30
|
+
expect(verify(messageBuf, sig, privateKey.toPublicKey())).toEqual(true)
|
|
48
31
|
})
|
|
49
|
-
|
|
32
|
+
it('Should verify a signed message in base64', () => {
|
|
33
|
+
const message = toArray('Texas', 'utf8')
|
|
34
|
+
const signature = Signature.fromCompact('IAV89EkfHSzAIA8cEWbbKHUYzJqcShkpWaXGJ5+mf4+YIlf3XNlr0bj9X60sNe1A7+x9qyk+zmXropMDY4370n8=', 'base64')
|
|
35
|
+
const publicKey = PublicKey.fromString('03d4d1a6c5d8c03b0e671bc1891b69afaecb40c0686188fe9019f93581b43e8334')
|
|
36
|
+
expect(verify(message, signature, publicKey)).toBe(true)
|
|
37
|
+
})
|
|
38
|
+
it('Should be able to calculate the recovery number for a signature and public key', () => {
|
|
39
|
+
const message = toArray('Texas', 'utf8')
|
|
40
|
+
const signature = Signature.fromCompact('IAV89EkfHSzAIA8cEWbbKHUYzJqcShkpWaXGJ5+mf4+YIlf3XNlr0bj9X60sNe1A7+x9qyk+zmXropMDY4370n8=', 'base64')
|
|
41
|
+
const publicKey = PublicKey.fromString('03d4d1a6c5d8c03b0e671bc1891b69afaecb40c0686188fe9019f93581b43e8334')
|
|
42
|
+
const msgHash = new BigNumber(magicHash(message))
|
|
43
|
+
const recovery = signature.CalculateRecoveryFactor(publicKey, msgHash)
|
|
44
|
+
expect(recovery).toBe(1)
|
|
45
|
+
const recoveredPubkey = signature.RecoverPublicKey(recovery, msgHash) as PublicKey
|
|
46
|
+
expect(recoveredPubkey.toDER()).toEqual(publicKey.toDER())
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
})
|
|
@@ -4,87 +4,87 @@ import PrivateKey from '../../../dist/cjs/src/primitives/PrivateKey'
|
|
|
4
4
|
import { toArray, toHex, encode, toBase64 } from '../../../dist/cjs/src/primitives/utils'
|
|
5
5
|
|
|
6
6
|
describe('#ECIES', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
it('should make a new ECIES object', () => {
|
|
8
|
+
expect(ECIES).toBeDefined()
|
|
9
|
+
})
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const fromkey = new PrivateKey(42)
|
|
12
|
+
const tokey = new PrivateKey(88)
|
|
13
|
+
const messageBuf = Hash.sha256(toArray('my message is the hash of this string', 'utf8'))
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
describe('@bitcoreEncrypt', () => {
|
|
16
|
+
it('should return a buffer', () => {
|
|
17
|
+
const encBuf = ECIES.bitcoreEncrypt(messageBuf, tokey.toPublicKey(), fromkey)
|
|
18
|
+
expect(Array.isArray(encBuf)).toEqual(true)
|
|
19
|
+
})
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
})
|
|
21
|
+
it('should return a buffer if fromkey is not present', () => {
|
|
22
|
+
const encBuf = ECIES.bitcoreEncrypt(messageBuf, tokey.toPublicKey())
|
|
23
|
+
expect(Array.isArray(encBuf)).toEqual(true)
|
|
25
24
|
})
|
|
25
|
+
})
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
describe('@bitcoreDecrypt', () => {
|
|
28
|
+
it('should decrypt that which was encrypted', () => {
|
|
29
|
+
const encBuf = ECIES.bitcoreEncrypt(messageBuf, tokey.toPublicKey(), fromkey)
|
|
30
|
+
const messageBuf2 = ECIES.bitcoreDecrypt(encBuf, tokey)
|
|
31
|
+
expect(toHex(messageBuf2)).toEqual(toHex(messageBuf))
|
|
32
|
+
})
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
34
|
+
it('should decrypt that which was encrypted if fromPrivateKey was randomly generated', () => {
|
|
35
|
+
const encBuf = ECIES.bitcoreEncrypt(messageBuf, tokey.toPublicKey())
|
|
36
|
+
const messageBuf2 = ECIES.bitcoreDecrypt(encBuf, tokey)
|
|
37
|
+
expect(messageBuf2).toEqual(messageBuf)
|
|
39
38
|
})
|
|
39
|
+
})
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
describe('Electrum ECIES', () => {
|
|
42
|
+
// const alicePrivateKey = PrivateKey.fromString('L1Ejc5dAigm5XrM3mNptMEsNnHzS7s51YxU7J61ewGshZTKkbmzJ')
|
|
43
|
+
// const bobPrivateKey = PrivateKey.fromString('KxfxrUXSMjJQcb3JgnaaA6MqsrKQ1nBSxvhuigdKRyFiEm6BZDgG')
|
|
44
|
+
const alicePrivateKey = PrivateKey.fromString('77e06abc52bf065cb5164c5deca839d0276911991a2730be4d8d0a0307de7ceb', 16)
|
|
45
|
+
const bobPrivateKey = PrivateKey.fromString('2b57c7c5e408ce927eef5e2efb49cfdadde77961d342daa72284bb3d6590862d', 16)
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
it('should do these test vectors correctly', () => {
|
|
48
|
+
const message = toArray('this is my test message', 'utf8')
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
50
|
+
expect(ECIES.electrumDecrypt(
|
|
51
|
+
toArray(
|
|
52
|
+
'QklFMQOGFyMXLo9Qv047K3BYJhmnJgt58EC8skYP/R2QU/U0yXXHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbiaH4FsxKIOOvzolIFVAS0FplUmib2HnlAM1yP/iiPsU=',
|
|
53
|
+
'base64'
|
|
54
|
+
),
|
|
55
|
+
alicePrivateKey
|
|
56
|
+
))
|
|
57
|
+
.toEqual(message)
|
|
58
|
+
expect(ECIES.electrumDecrypt(
|
|
59
|
+
toArray(
|
|
60
|
+
'QklFMQM55QTWSSsILaluEejwOXlrBs1IVcEB4kkqbxDz4Fap53XHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbvZJHgyAzxA6SoujduvJXv+A9ri3po9veilrmc8p6dwo=',
|
|
61
|
+
'base64'
|
|
62
|
+
),
|
|
63
|
+
bobPrivateKey
|
|
64
|
+
))
|
|
65
|
+
.toEqual(message)
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
67
|
+
expect(toBase64(
|
|
68
|
+
ECIES.electrumEncrypt(message, bobPrivateKey.toPublicKey(), alicePrivateKey)
|
|
69
|
+
))
|
|
70
|
+
.toEqual(
|
|
71
|
+
'QklFMQM55QTWSSsILaluEejwOXlrBs1IVcEB4kkqbxDz4Fap53XHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbvZJHgyAzxA6SoujduvJXv+A9ri3po9veilrmc8p6dwo='
|
|
72
|
+
)
|
|
73
|
+
expect(toBase64(ECIES.electrumEncrypt(message, alicePrivateKey.toPublicKey(), bobPrivateKey)))
|
|
74
|
+
.toEqual(
|
|
75
|
+
'QklFMQOGFyMXLo9Qv047K3BYJhmnJgt58EC8skYP/R2QU/U0yXXHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbiaH4FsxKIOOvzolIFVAS0FplUmib2HnlAM1yP/iiPsU='
|
|
76
|
+
)
|
|
77
|
+
})
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
})
|
|
79
|
+
it('should encrypt and decrypt symmetrically with matching strings in ECDH noKey mode', () => {
|
|
80
|
+
const message = toArray('this is my ECDH test message', 'utf8')
|
|
81
|
+
const ecdhMessageEncryptedBob = ECIES.electrumEncrypt(message, bobPrivateKey.toPublicKey(), alicePrivateKey, true)
|
|
82
|
+
const ecdhMessageEncryptedAlice = ECIES.electrumEncrypt(message, alicePrivateKey.toPublicKey(), bobPrivateKey, true)
|
|
83
|
+
expect(ecdhMessageEncryptedBob).toEqual(ecdhMessageEncryptedAlice)
|
|
84
|
+
expect(ECIES.electrumDecrypt(ecdhMessageEncryptedAlice, bobPrivateKey, alicePrivateKey.toPublicKey()))
|
|
85
|
+
.toEqual(toArray('this is my ECDH test message', 'utf8'))
|
|
86
|
+
expect(ECIES.electrumDecrypt(ecdhMessageEncryptedBob, alicePrivateKey, bobPrivateKey.toPublicKey()))
|
|
87
|
+
.toEqual(toArray('this is my ECDH test message', 'utf8'))
|
|
89
88
|
})
|
|
90
|
-
})
|
|
89
|
+
})
|
|
90
|
+
})
|