@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,33 +1,31 @@
|
|
|
1
|
-
//import { PrivateKey, PublicKey, Curve, Hash, BigNumber } from '..';
|
|
1
|
+
// import { PrivateKey, PublicKey, Curve, Hash, BigNumber } from '..';
|
|
2
2
|
import PublicKey from '../../../dist/cjs/src/primitives/PublicKey'
|
|
3
|
-
//import { PrivateKey } from '..';
|
|
3
|
+
// import { PrivateKey } from '..';
|
|
4
4
|
import PrivateKey from '../../../dist/cjs/src/primitives/PrivateKey'
|
|
5
5
|
import Curve from '../../../dist/cjs/src/primitives/Curve'
|
|
6
6
|
import BigNumber from '../../../dist/cjs/src/primitives/BigNumber'
|
|
7
7
|
|
|
8
|
-
describe(
|
|
8
|
+
describe('bug-31 tests', () => {
|
|
9
|
+
test('0', () => {
|
|
10
|
+
const c = new Curve()
|
|
11
|
+
const G = c.g
|
|
12
|
+
// const bn = new BigNumber(c.n + 12)
|
|
13
|
+
const bn = c.n.addn(12)
|
|
14
|
+
const sn = new BigNumber(12)
|
|
15
|
+
{
|
|
16
|
+
expect(() => new PrivateKey(bn.toHex(), 'hex', 'be', 'error')).toThrow('Input is out of field')
|
|
17
|
+
}
|
|
18
|
+
const o = PrivateKey.fromString(bn.toHex(), 'hex')
|
|
19
|
+
const os = PrivateKey.fromString(sn.toHex(), 'hex')
|
|
20
|
+
expect(o.cmp(os)).toBe(0)
|
|
21
|
+
const os2 = new PrivateKey(bn.toHex(), 'hex', 'be', 'nocheck')
|
|
22
|
+
expect(o.cmp(os2)).not.toBe(0)
|
|
9
23
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const bn = c.n.addn(12)
|
|
15
|
-
const sn = new BigNumber(12)
|
|
16
|
-
{
|
|
17
|
-
expect(() => new PrivateKey(bn.toHex(), 'hex', 'be', 'error')).toThrow("Input is out of field")
|
|
18
|
-
}
|
|
19
|
-
const o = PrivateKey.fromString(bn.toHex(), 'hex')
|
|
20
|
-
const os = PrivateKey.fromString(sn.toHex(), 'hex')
|
|
21
|
-
expect(o.cmp(os)).toBe(0)
|
|
22
|
-
const os2 = new PrivateKey(bn.toHex(), 'hex', 'be', 'nocheck')
|
|
23
|
-
expect(o.cmp(os2)).not.toBe(0)
|
|
24
|
+
const oWif = o.toWif()
|
|
25
|
+
expect(oWif).toBe('KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU79MFFcB1G')
|
|
26
|
+
const osWif = os.toWif()
|
|
27
|
+
expect(osWif).toBe('KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU79MFFcB1G')
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
expect(osWif).toBe('KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU79MFFcB1G')
|
|
29
|
-
|
|
30
|
-
expect(() => os2.toWif()).toThrow("Value is out of field")
|
|
31
|
-
|
|
32
|
-
})
|
|
33
|
-
})
|
|
29
|
+
expect(() => os2.toWif()).toThrow('Value is out of field')
|
|
30
|
+
})
|
|
31
|
+
})
|
|
@@ -24,13 +24,13 @@ describe('utils', () => {
|
|
|
24
24
|
expect(encode([0, 1, 2, 3], 'hex')).toBe('00010203')
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
describe(
|
|
27
|
+
describe('base58 to binary', () => {
|
|
28
28
|
it('Converts as expected', () => {
|
|
29
|
-
const actual = fromBase58(
|
|
29
|
+
const actual = fromBase58('6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV')
|
|
30
30
|
expect(toHex(actual)).toEqual('02c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cfeb05f9d2')
|
|
31
31
|
})
|
|
32
32
|
it('Converts as expected with leading 1s', () => {
|
|
33
|
-
const actual = fromBase58(
|
|
33
|
+
const actual = fromBase58('111z')
|
|
34
34
|
expect(toHex(actual)).toEqual('00000039')
|
|
35
35
|
})
|
|
36
36
|
it('Throws when called with undefined base58 string', () => {
|
|
@@ -40,16 +40,16 @@ describe('utils', () => {
|
|
|
40
40
|
expect(() => fromBase58('0L')).toThrow(new Error('Invalid base58 character “0”'))
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
|
-
describe(
|
|
43
|
+
describe('binary to base58 string', () => {
|
|
44
44
|
it('Converts to base58 as expected', () => {
|
|
45
45
|
const actual = toBase58(
|
|
46
|
-
toArray(
|
|
46
|
+
toArray('02c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cfeb05f9d2', 'hex')
|
|
47
47
|
)
|
|
48
|
-
expect(actual).toEqual(
|
|
48
|
+
expect(actual).toEqual('6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV')
|
|
49
49
|
})
|
|
50
50
|
it('Converts to base58 as expected with 1s', () => {
|
|
51
51
|
const actual = toBase58([0, 0, 0, 4])
|
|
52
|
-
expect(actual).toEqual(
|
|
52
|
+
expect(actual).toEqual('1115')
|
|
53
53
|
})
|
|
54
54
|
})
|
|
55
55
|
describe('base58check encoding and decoding', () => {
|
|
@@ -63,7 +63,7 @@ describe('utils', () => {
|
|
|
63
63
|
encoded = toBase58Check(data)
|
|
64
64
|
expect(encoded).toBe('14cxpo3MBCYYWCgF74SWTdcmxipnGUsPw3')
|
|
65
65
|
expect(fromBase58Check(encoded)).toEqual({ prefix: [0], data })
|
|
66
|
-
})
|
|
66
|
+
})
|
|
67
67
|
|
|
68
68
|
it('should correctly encode and decode data with custom prefix', () => {
|
|
69
69
|
const prefix = [0x80]
|
|
@@ -76,7 +76,7 @@ describe('utils', () => {
|
|
|
76
76
|
encoded = toBase58Check(data, prefix)
|
|
77
77
|
expect(encoded).toBe('5JG9hT3beGTJuUAmCQEmNaxAuMacCTfXuw1R3FCXig23RQHMr4K')
|
|
78
78
|
expect(fromBase58Check(encoded)).toEqual({ prefix, data })
|
|
79
|
-
})
|
|
79
|
+
})
|
|
80
80
|
|
|
81
81
|
it('should correctly handle encoding and decoding with different encoding formats', () => {
|
|
82
82
|
const prefix = [0x80]
|
|
@@ -92,12 +92,12 @@ describe('utils', () => {
|
|
|
92
92
|
encoded = toBase58Check(data, prefix)
|
|
93
93
|
expect(encoded).toBe('KyBsPXxTuVD82av65KZkrGrWi5qLMah5SdNq6uftawDbgKa2wv6S')
|
|
94
94
|
expect(fromBase58Check(encoded, 'hex')).toEqual({ prefix: '80', data: dataHex })
|
|
95
|
-
})
|
|
95
|
+
})
|
|
96
96
|
|
|
97
97
|
it('should correctly encode and decode Bitcoin addresses', () => {
|
|
98
98
|
const dataHex = '086eaa677895f92d4a6c5ef740c168932b5e3f44'
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
const data = toArray(dataHex, 'hex')
|
|
100
|
+
const encoded = toBase58Check(data)
|
|
101
101
|
expect(encoded).toBe('1mayif3H2JDC62S4N3rLNtBNRAiUUP99k')
|
|
102
102
|
expect(fromBase58Check(encoded, 'hex')).toEqual({ prefix: '00', data: dataHex })
|
|
103
103
|
|
|
@@ -105,4 +105,4 @@ describe('utils', () => {
|
|
|
105
105
|
expect(fromBase58Check(address, 'hex')).toEqual({ prefix: '00', data: dataHex })
|
|
106
106
|
})
|
|
107
107
|
})
|
|
108
|
-
})
|
|
108
|
+
})
|
package/src/primitives/index.ts
CHANGED
|
@@ -3,10 +3,11 @@ export { default as Curve } from './Curve.js'
|
|
|
3
3
|
export { default as Point } from './Point.js'
|
|
4
4
|
export { default as PublicKey } from './PublicKey.js'
|
|
5
5
|
export { default as Signature } from './Signature.js'
|
|
6
|
-
export { default as PrivateKey } from './PrivateKey.js'
|
|
6
|
+
export { default as PrivateKey, KeyShares } from './PrivateKey.js'
|
|
7
7
|
export { default as SymmetricKey } from './SymmetricKey.js'
|
|
8
8
|
export * as ECDSA from './ECDSA.js'
|
|
9
9
|
export * as Utils from './utils.js'
|
|
10
10
|
export * as Hash from './Hash.js'
|
|
11
11
|
export { default as Random } from './Random.js'
|
|
12
12
|
export { default as TransactionSignature } from './TransactionSignature.js'
|
|
13
|
+
export { default as Polynomial, PointInFiniteField } from './Polynomial.js'
|
|
@@ -48,7 +48,7 @@ describe('Script', () => {
|
|
|
48
48
|
it('should error when attempting to parse this strange Base58Check encoded string', () => {
|
|
49
49
|
const priv = PrivateKey.fromRandom()
|
|
50
50
|
const address = priv.toAddress([0x88])
|
|
51
|
-
function attemptToDeriveAddress() {
|
|
51
|
+
function attemptToDeriveAddress () {
|
|
52
52
|
const script = new P2PKH().lock(address).toASM()
|
|
53
53
|
return script
|
|
54
54
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Script from
|
|
2
|
-
import Spend from
|
|
3
|
-
import Transaction from
|
|
1
|
+
import Script from '../../../dist/cjs/src/script/Script'
|
|
2
|
+
import Spend from '../../../dist/cjs/src/script/Spend'
|
|
3
|
+
import Transaction from '../../../dist/cjs/src/transaction/Transaction'
|
|
4
4
|
|
|
5
5
|
describe('SpendComplex', () => {
|
|
6
6
|
it('complex unlock script validation', () => {
|
|
@@ -17,9 +17,9 @@ describe('SpendComplex', () => {
|
|
|
17
17
|
})
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
function verifyTruthy<T>(v: T | undefined): T { if (v == null) throw new Error('must have value'); return v }
|
|
20
|
+
function verifyTruthy<T> (v: T | undefined): T { if (v == null) throw new Error('must have value'); return v }
|
|
21
21
|
|
|
22
|
-
export function validateUnlockScript(spendingRawTx: string, vin: number, lockingScript: string, amount: number): boolean {
|
|
22
|
+
export function validateUnlockScript (spendingRawTx: string, vin: number, lockingScript: string, amount: number): boolean {
|
|
23
23
|
const spendingTx = Transaction.fromHex(spendingRawTx)
|
|
24
24
|
const ls = Script.fromHex(lockingScript)
|
|
25
25
|
|
|
@@ -43,4 +43,4 @@ export function validateUnlockScript(spendingRawTx: string, vin: number, locking
|
|
|
43
43
|
|
|
44
44
|
const valid = spend.validate()
|
|
45
45
|
return valid
|
|
46
|
-
}
|
|
46
|
+
}
|