@dynamic-labs/bitcoin 1.1.0-phantom.0 → 1.1.1
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/CHANGELOG.md +152 -2
- package/_virtual/_tslib.cjs +6 -1
- package/_virtual/_tslib.js +6 -1
- package/package.json +8 -5
- package/src/BitcoinBtcKitConnector.cjs +32 -0
- package/src/BitcoinBtcKitConnector.d.ts +2 -1
- package/src/BitcoinBtcKitConnector.js +32 -0
- package/src/BitcoinLocalStorageCache.cjs +6 -0
- package/src/BitcoinLocalStorageCache.d.ts +5 -0
- package/src/BitcoinLocalStorageCache.js +6 -0
- package/src/BitcoinSatsConnectConnector.cjs +67 -2
- package/src/BitcoinSatsConnectConnector.d.ts +4 -2
- package/src/BitcoinSatsConnectConnector.js +68 -3
- package/src/BitcoinWalletConnector.cjs +76 -11
- package/src/BitcoinWalletConnector.d.ts +10 -3
- package/src/BitcoinWalletConnector.js +78 -13
- package/src/OkxConnector.cjs +14 -0
- package/src/OkxConnector.d.ts +3 -1
- package/src/OkxConnector.js +14 -0
- package/src/UnisatConnector.cjs +14 -0
- package/src/UnisatConnector.d.ts +3 -1
- package/src/UnisatConnector.js +14 -0
- package/src/const.cjs +4 -4
- package/src/const.d.ts +2 -2
- package/src/const.js +3 -3
- package/src/index.cjs +2 -0
- package/src/index.js +1 -0
- package/src/types.d.ts +31 -8
- package/src/utils/getMempoolApiUrl.cjs +9 -0
- package/src/utils/getMempoolApiUrl.d.ts +1 -0
- package/src/utils/getMempoolApiUrl.js +5 -0
- package/src/utils/index.d.ts +1 -0
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.cjs +13 -0
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.d.ts +3 -0
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.js +9 -0
- package/src/utils/psbt/createSignPsbtOptions.cjs +33 -0
- package/src/utils/psbt/createSignPsbtOptions.d.ts +3 -0
- package/src/utils/psbt/createSignPsbtOptions.js +29 -0
- package/src/utils/psbt/extractAddressFromInput.cjs +34 -0
- package/src/utils/psbt/extractAddressFromInput.d.ts +6 -0
- package/src/utils/psbt/extractAddressFromInput.js +30 -0
- package/src/utils/psbt/getSigHashType.cjs +35 -0
- package/src/utils/psbt/getSigHashType.d.ts +8 -0
- package/src/utils/psbt/getSigHashType.js +31 -0
- package/src/utils/psbt/index.d.ts +4 -0
- package/src/utils/psbt/validator/index.d.ts +1 -0
- package/src/utils/psbt/validator/validateAddress.cjs +18 -0
- package/src/utils/psbt/validator/validateAddress.d.ts +2 -0
- package/src/utils/psbt/validator/validateAddress.js +14 -0
- package/src/utils/psbt/validator/validatePsbt.cjs +40 -0
- package/src/utils/psbt/validator/validatePsbt.d.ts +11 -0
- package/src/utils/psbt/validator/validatePsbt.js +36 -0
- package/src/utils/psbt/validator/validateSigHash.cjs +15 -0
- package/src/utils/psbt/validator/validateSigHash.d.ts +2 -0
- package/src/utils/psbt/validator/validateSigHash.js +11 -0
- package/src/utils/supportsSatsConnect.cjs +2 -0
- package/src/utils/supportsSatsConnect.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,168 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
2
|
+
### [1.1.1](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0...v1.1.1) (2024-02-13)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* current wallet being clipped inside a circle ([#4470](https://github.com/dynamic-labs/DynamicAuth/issues/4470)) ([#4649](https://github.com/dynamic-labs/DynamicAuth/issues/4649)) ([43537af](https://github.com/dynamic-labs/DynamicAuth/commit/43537af0809c96bc8ae8726d9260e2c526d2921b))
|
|
8
|
+
* old iconic dependency version ([#4674](https://github.com/dynamic-labs/DynamicAuth/issues/4674)) ([04f5b03](https://github.com/dynamic-labs/DynamicAuth/commit/04f5b0387303563637ad414eda0170186aad0e44))
|
|
9
|
+
* solana turnkey connector not refreshing account after session expiration ([#4637](https://github.com/dynamic-labs/DynamicAuth/issues/4637)) ([ed0f964](https://github.com/dynamic-labs/DynamicAuth/commit/ed0f964bc1e0ab2e5069c51b9e6f3c0bc2a16df7))
|
|
10
|
+
|
|
11
|
+
## [1.1.0](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.25...v1.1.0) (2024-02-07)
|
|
12
|
+
|
|
13
|
+
Check out our changelog here: https://docs.dynamic.xyz/changelog/v1-1
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* add retry when using magic ([#4579](https://github.com/dynamic-labs/DynamicAuth/issues/4579)) ([183561c](https://github.com/dynamic-labs/DynamicAuth/commit/183561cc64f083fd1489c38a8cc8b1c4c51d2924))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* bug where deprecated fields were still being used in the SDK ([#4604](https://github.com/dynamic-labs/DynamicAuth/issues/4604)) ([4fd15fc](https://github.com/dynamic-labs/DynamicAuth/commit/4fd15fc4daa9c5b7bbc81ce05a3b046c80a6d5b4))
|
|
24
|
+
* log magic RPC error and update magic network error ([#4606](https://github.com/dynamic-labs/DynamicAuth/issues/4606)) ([2206961](https://github.com/dynamic-labs/DynamicAuth/commit/22069618a317bc40b1a17fd521eadf0956983de4))
|
|
25
|
+
* onConnect is properly called for additional connected wallets ([#4607](https://github.com/dynamic-labs/DynamicAuth/issues/4607)) ([23241f4](https://github.com/dynamic-labs/DynamicAuth/commit/23241f4d5dc91ac9ca1251710161efbfce42dc40))
|
|
26
|
+
|
|
27
|
+
## [1.1.0-alpha.25](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.24...v1.1.0-alpha.25) (2024-02-05)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* add signin with coinbase to sdk ([#4581](https://github.com/dynamic-labs/DynamicAuth/issues/4581)) ([08a31ed](https://github.com/dynamic-labs/DynamicAuth/commit/08a31ed3552c48645b398881f184440800af21ec))
|
|
33
|
+
* exposing hook for creating either one-time code or passkeys authenticators ([#4591](https://github.com/dynamic-labs/DynamicAuth/issues/4591)) ([864d755](https://github.com/dynamic-labs/DynamicAuth/commit/864d75576152a10f73f5901bc06e2d66892b63ab))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Bug Fixes
|
|
37
|
+
|
|
38
|
+
* solana wallet sign message with one-time code session ([#4588](https://github.com/dynamic-labs/DynamicAuth/issues/4588)) ([a738d10](https://github.com/dynamic-labs/DynamicAuth/commit/a738d10814dc5058158b9c0c59a399a375c69c10))
|
|
39
|
+
|
|
40
|
+
## [1.1.0-alpha.24](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.23...v1.1.0-alpha.24) (2024-02-02)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Bug Fixes
|
|
44
|
+
|
|
45
|
+
* remove isFullyConnected when unable to restore wallet ([#4575](https://github.com/dynamic-labs/DynamicAuth/issues/4575)) ([4504ff0](https://github.com/dynamic-labs/DynamicAuth/commit/4504ff03f594cd9a60055e6f52b7ea8001542bbe))
|
|
46
|
+
|
|
47
|
+
## [1.1.0-alpha.23](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.22...v1.1.0-alpha.23) (2024-02-01)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Features
|
|
51
|
+
|
|
52
|
+
* bitcoin signPsbt ([3c964de](https://github.com/dynamic-labs/DynamicAuth/commit/3c964dea8a55debaf184c5a94f0f5fabdda3c877))
|
|
53
|
+
* embedded wallet email auth flow ([#4353](https://github.com/dynamic-labs/DynamicAuth/issues/4353)) ([4875da3](https://github.com/dynamic-labs/DynamicAuth/commit/4875da32c47c27facef1b1cdbdc214566bbfd171))
|
|
54
|
+
|
|
55
|
+
## [1.1.0-alpha.22](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.21...v1.1.0-alpha.22) (2024-02-01)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Bug Fixes
|
|
59
|
+
|
|
60
|
+
* onAuthFlowClose not being called ([#4563](https://github.com/dynamic-labs/DynamicAuth/issues/4563)) ([c4b2648](https://github.com/dynamic-labs/DynamicAuth/commit/c4b264885b7dba6e204ef49bf642d25c7d287b04))
|
|
61
|
+
|
|
62
|
+
## [1.1.0-alpha.21](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.20...v1.1.0-alpha.21) (2024-02-01)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Features
|
|
66
|
+
|
|
67
|
+
* add phantom redirect handling context ([#4479](https://github.com/dynamic-labs/DynamicAuth/issues/4479)) ([e0218ee](https://github.com/dynamic-labs/DynamicAuth/commit/e0218eec1a67787f5c0e7483d542a5f773e911ef))
|
|
68
|
+
* add signPsbt method to bitcoin wallet connectors ([dfdc0fe](https://github.com/dynamic-labs/DynamicAuth/commit/dfdc0fe0e6894c1307b286e89b43a4c58a8808f3))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Bug Fixes
|
|
72
|
+
|
|
73
|
+
* relax passkey feature detection check in sdk to avoid false nega… ([#4556](https://github.com/dynamic-labs/DynamicAuth/issues/4556)) ([4554f7d](https://github.com/dynamic-labs/DynamicAuth/commit/4554f7d7c5339859481cdecca95a9c07fae4ba5c))
|
|
74
|
+
* workaround braavos undefined selectedWallet on chainChange event ([#4552](https://github.com/dynamic-labs/DynamicAuth/issues/4552)) ([aa35df0](https://github.com/dynamic-labs/DynamicAuth/commit/aa35df0e894feafa0606aa1c87bd3d3879ebc594))
|
|
75
|
+
|
|
76
|
+
## [1.1.0-alpha.20](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.19...v1.1.0-alpha.20) (2024-01-31)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
### Bug Fixes
|
|
80
|
+
|
|
81
|
+
* return all enabled chains in getSupportedNetworks instead of undefined ([#4547](https://github.com/dynamic-labs/DynamicAuth/issues/4547)) ([08e7889](https://github.com/dynamic-labs/DynamicAuth/commit/08e78896e045f24bbd96e39416a7f58006929da0))
|
|
82
|
+
* show modal for existing social account from other signin provider ([#4535](https://github.com/dynamic-labs/DynamicAuth/issues/4535)) ([282914a](https://github.com/dynamic-labs/DynamicAuth/commit/282914ac94b3ef5bd66e0b2265d9e414203a7406))
|
|
83
|
+
|
|
84
|
+
## [1.1.0-alpha.19](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.18...v1.1.0-alpha.19) (2024-01-31)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Features
|
|
88
|
+
|
|
89
|
+
* add PhantomRedirect connector ([#4467](https://github.com/dynamic-labs/DynamicAuth/issues/4467)) ([75d6c95](https://github.com/dynamic-labs/DynamicAuth/commit/75d6c95940fcec185a699c2100b3e2d21a8233d5))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### Bug Fixes
|
|
93
|
+
|
|
94
|
+
* lock starknet to 5.25.0 since 5.27.0 breaks the build ([#4541](https://github.com/dynamic-labs/DynamicAuth/issues/4541)) ([00b4799](https://github.com/dynamic-labs/DynamicAuth/commit/00b479977f768cb067480e2e565eabf45e1000a2))
|
|
95
|
+
|
|
96
|
+
## [1.1.0-alpha.18](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.17...v1.1.0-alpha.18) (2024-01-30)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
### Bug Fixes
|
|
100
|
+
|
|
101
|
+
* catch email_associated_with_different_provider from response ([#4532](https://github.com/dynamic-labs/DynamicAuth/issues/4532)) ([52be1b4](https://github.com/dynamic-labs/DynamicAuth/commit/52be1b45af46c2b70972b99d73387eb4d7161ec6))
|
|
102
|
+
|
|
103
|
+
## [1.1.0-alpha.17](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.16...v1.1.0-alpha.17) (2024-01-30)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
### Features
|
|
107
|
+
|
|
108
|
+
* add sendRawTransaction to BitcoinWalletConnector ([2e86c5a](https://github.com/dynamic-labs/DynamicAuth/commit/2e86c5a5245bd0fc29162ef1f7fe2fbd65245fe1))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
### Bug Fixes
|
|
112
|
+
|
|
113
|
+
* properly handle AccountExistsError for signInOAuth ([#4529](https://github.com/dynamic-labs/DynamicAuth/issues/4529)) ([d37fdc3](https://github.com/dynamic-labs/DynamicAuth/commit/d37fdc310fe4b70f8948fd5ed3d058342afbe08f))
|
|
114
|
+
|
|
115
|
+
## [1.1.0-alpha.16](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.15...v1.1.0-alpha.16) (2024-01-30)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### Bug Fixes
|
|
119
|
+
|
|
120
|
+
* add fallback to getWalletBookWallet for customers still passing in name, add deprecation warn ([#4518](https://github.com/dynamic-labs/DynamicAuth/issues/4518)) ([b233ea1](https://github.com/dynamic-labs/DynamicAuth/commit/b233ea1cd640d8d9d94c52ab230787f3d869151a))
|
|
121
|
+
* handle braavos network change to account which doesn not exist ([#4519](https://github.com/dynamic-labs/DynamicAuth/issues/4519)) ([486020f](https://github.com/dynamic-labs/DynamicAuth/commit/486020fb09a274388ba34c8d1b37ac3a1ff3dba6))
|
|
122
|
+
|
|
123
|
+
## [1.1.0-alpha.15](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.14...v1.1.0-alpha.15) (2024-01-28)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
### Features
|
|
127
|
+
|
|
128
|
+
* add wallet group override to wallet book ([#4488](https://github.com/dynamic-labs/DynamicAuth/issues/4488)) ([cb19ad3](https://github.com/dynamic-labs/DynamicAuth/commit/cb19ad3ea82de488752ceceeaf0e1458a388df6e))
|
|
129
|
+
* enable solana embedded wallets ([#4457](https://github.com/dynamic-labs/DynamicAuth/issues/4457)) ([b0c47f4](https://github.com/dynamic-labs/DynamicAuth/commit/b0c47f4475baa12f52076da46ef993c13bd2c243))
|
|
130
|
+
* group ArgentX wallets ([#4495](https://github.com/dynamic-labs/DynamicAuth/issues/4495)) ([b10d79a](https://github.com/dynamic-labs/DynamicAuth/commit/b10d79a668efecedca37ddb358e6adf95319650d))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
### Bug Fixes
|
|
134
|
+
|
|
135
|
+
* add support for newest backpack extension ([#4468](https://github.com/dynamic-labs/DynamicAuth/issues/4468)) ([a219f32](https://github.com/dynamic-labs/DynamicAuth/commit/a219f325be672599e50b07f6751234a7fc98286e))
|
|
136
|
+
* bump timeout for slower connections ([#4475](https://github.com/dynamic-labs/DynamicAuth/issues/4475)) ([7a07ff5](https://github.com/dynamic-labs/DynamicAuth/commit/7a07ff589eaaf3b28a94d277df3eedabbca60702))
|
|
137
|
+
* change out getWalletBookWallet for findWalletBookWallet to avoid throwing during lookup ([#4477](https://github.com/dynamic-labs/DynamicAuth/issues/4477)) ([4648040](https://github.com/dynamic-labs/DynamicAuth/commit/4648040c166e73dd2c31b0e27897713339436c2f))
|
|
138
|
+
* connect to wallet with wallet connect even if network is not supported ([#4465](https://github.com/dynamic-labs/DynamicAuth/issues/4465)) ([9dbca3e](https://github.com/dynamic-labs/DynamicAuth/commit/9dbca3eb4d4990ee4be642677c1604170b425dc3))
|
|
139
|
+
* pass id to wagmi chain override ([#4512](https://github.com/dynamic-labs/DynamicAuth/issues/4512)) ([2bf2f04](https://github.com/dynamic-labs/DynamicAuth/commit/2bf2f0487f5b1be936dd279107c11fe5d2b42666))
|
|
140
|
+
* switching wallet in extension caused connected flag to be false temporarily ([#4454](https://github.com/dynamic-labs/DynamicAuth/issues/4454)) ([3650f6e](https://github.com/dynamic-labs/DynamicAuth/commit/3650f6ec471a7c779f4d304ab94c9350dd55055b))
|
|
141
|
+
|
|
142
|
+
## [1.1.0-alpha.14](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.13...v1.1.0-alpha.14) (2024-01-23)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### Features
|
|
146
|
+
|
|
147
|
+
* add wallet-book retryable ([#4462](https://github.com/dynamic-labs/DynamicAuth/issues/4462)) ([513b1a6](https://github.com/dynamic-labs/DynamicAuth/commit/513b1a67d6c49624398ad4b0cdca4f5618c9583f))
|
|
148
|
+
|
|
149
|
+
## [1.1.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.12...v1.1.0-alpha.13) (2024-01-23)
|
|
3
150
|
|
|
4
151
|
|
|
5
152
|
### Features
|
|
6
153
|
|
|
7
154
|
* add createWalletClientFromWallet helper function ([#4416](https://github.com/dynamic-labs/DynamicAuth/issues/4416)) ([b384898](https://github.com/dynamic-labs/DynamicAuth/commit/b384898061bb3f9b38b2ed670b6650cfc1d4b429))
|
|
8
155
|
* add hardware wallets to wallet book ([#4445](https://github.com/dynamic-labs/DynamicAuth/issues/4445)) ([66c0f5b](https://github.com/dynamic-labs/DynamicAuth/commit/66c0f5b29a6a700099bb95a6f7622f6178e0bccf))
|
|
9
|
-
* add
|
|
156
|
+
* add support for Argent Web and Mobile ([#4328](https://github.com/dynamic-labs/DynamicAuth/issues/4328)) ([bce20b8](https://github.com/dynamic-labs/DynamicAuth/commit/bce20b8f35a8630f2621f53a541a1acb06a38fc0))
|
|
157
|
+
* enable ledger for glow, solflare and backpack ([#4392](https://github.com/dynamic-labs/DynamicAuth/issues/4392)) ([fa7b992](https://github.com/dynamic-labs/DynamicAuth/commit/fa7b992f87ebc43560f87b43ac56f2cd9909b306))
|
|
10
158
|
|
|
11
159
|
|
|
12
160
|
### Bug Fixes
|
|
13
161
|
|
|
14
162
|
* breaking changes script ([#4440](https://github.com/dynamic-labs/DynamicAuth/issues/4440)) ([446173d](https://github.com/dynamic-labs/DynamicAuth/commit/446173d074d652d81856c6412e304b46b1565320))
|
|
15
163
|
* broken help icon in create passkey view ([#4428](https://github.com/dynamic-labs/DynamicAuth/issues/4428)) ([e0ffc02](https://github.com/dynamic-labs/DynamicAuth/commit/e0ffc02ffea34b7ac3198ff6e1baf7f9907acddd))
|
|
164
|
+
* infinite loop when connecting with trust wallet ([#4448](https://github.com/dynamic-labs/DynamicAuth/issues/4448)) ([4e20edf](https://github.com/dynamic-labs/DynamicAuth/commit/4e20edf9abaabf20e5e9f9167b44d7f691e844f1))
|
|
165
|
+
* render wagmi elements based on react version ([#4453](https://github.com/dynamic-labs/DynamicAuth/issues/4453)) ([43c624c](https://github.com/dynamic-labs/DynamicAuth/commit/43c624ca996b0c51de1454910f19fdf908149938))
|
|
16
166
|
|
|
17
167
|
## [1.1.0-alpha.12](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.11...v1.1.0-alpha.12) (2024-01-18)
|
|
18
168
|
|
package/_virtual/_tslib.cjs
CHANGED
|
@@ -25,6 +25,11 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
25
25
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
26
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
27
|
});
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
31
|
+
var e = new Error(message);
|
|
32
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
33
|
+
};
|
|
29
34
|
|
|
30
35
|
exports.__awaiter = __awaiter;
|
package/_virtual/_tslib.js
CHANGED
|
@@ -21,6 +21,11 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
21
21
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
22
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
23
|
});
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
27
|
+
var e = new Error(message);
|
|
28
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
29
|
+
};
|
|
25
30
|
|
|
26
31
|
export { __awaiter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/bitcoin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -26,13 +26,16 @@
|
|
|
26
26
|
"./package.json": "./package.json"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@
|
|
29
|
+
"@btckit/types": "^0.0.19",
|
|
30
|
+
"@dynamic-labs/sdk-api": "0.0.363",
|
|
30
31
|
"@wallet-standard/app": "^1.0.1",
|
|
31
32
|
"@wallet-standard/base": "^1.0.1",
|
|
33
|
+
"bitcoinjs-lib": "^6.1.5",
|
|
32
34
|
"sats-connect": "^1.1.2",
|
|
33
|
-
"@dynamic-labs/utils": "1.1.
|
|
34
|
-
"@dynamic-labs/wallet-book": "1.1.
|
|
35
|
-
"@dynamic-labs/wallet-connector-core": "1.1.
|
|
35
|
+
"@dynamic-labs/utils": "1.1.1",
|
|
36
|
+
"@dynamic-labs/wallet-book": "1.1.1",
|
|
37
|
+
"@dynamic-labs/wallet-connector-core": "1.1.1",
|
|
38
|
+
"stream": "0.0.2"
|
|
36
39
|
},
|
|
37
40
|
"peerDependencies": {}
|
|
38
41
|
}
|
|
@@ -4,8 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _tslib = require('../_virtual/_tslib.cjs');
|
|
6
6
|
var satsConnect = require('sats-connect');
|
|
7
|
+
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
7
8
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
9
|
var BitcoinWalletConnector = require('./BitcoinWalletConnector.cjs');
|
|
10
|
+
var validatePsbt = require('./utils/psbt/validator/validatePsbt.cjs');
|
|
11
|
+
var bitcoinNetworkTypeToNetworks = require('./utils/psbt/bitcoinNetworkTypeToNetworks.cjs');
|
|
9
12
|
|
|
10
13
|
class BitcoinBtcKitConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
11
14
|
constructor(opts, btcKit) {
|
|
@@ -71,6 +74,35 @@ class BitcoinBtcKitConnector extends BitcoinWalletConnector.BitcoinWalletConnect
|
|
|
71
74
|
return response.result.txid;
|
|
72
75
|
});
|
|
73
76
|
}
|
|
77
|
+
signPsbt(request) {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const connectedAddress = yield this.fetchPublicAddress();
|
|
81
|
+
if (!connectedAddress || !this.btcKit) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const network = bitcoinNetworkTypeToNetworks.convertNetworkTypeForPsbt(this.currentNetwork);
|
|
85
|
+
const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64, {
|
|
86
|
+
network,
|
|
87
|
+
});
|
|
88
|
+
if ((_a = request.signature) === null || _a === void 0 ? void 0 : _a.length) {
|
|
89
|
+
validatePsbt.validatePsbt(psbtFromBase64, request.allowedSighash, request.signature);
|
|
90
|
+
}
|
|
91
|
+
const signPsbtRequestParams = {
|
|
92
|
+
allowedSighash: request.allowedSighash,
|
|
93
|
+
hex: psbtFromBase64.toHex(),
|
|
94
|
+
signAtIndex: (_b = request.signature) === null || _b === void 0 ? void 0 : _b.flatMap((sig) => sig.signingIndexes).filter(Number.isInteger),
|
|
95
|
+
};
|
|
96
|
+
const signedPsbtResponse = (yield this.btcKit.request('signPsbt', Object.assign({ broadcast: false, network }, signPsbtRequestParams)));
|
|
97
|
+
if (!signedPsbtResponse ||
|
|
98
|
+
!('result' in signedPsbtResponse) ||
|
|
99
|
+
!('hex' in signedPsbtResponse.result)) {
|
|
100
|
+
throw new Error('signPsbt - failed to sign PSBT');
|
|
101
|
+
}
|
|
102
|
+
const psbtHex = signedPsbtResponse.result.hex;
|
|
103
|
+
return { signedPsbt: bitcoinjsLib.Psbt.fromHex(psbtHex, { network }).toBase64() };
|
|
104
|
+
});
|
|
105
|
+
}
|
|
74
106
|
}
|
|
75
107
|
|
|
76
108
|
exports.BitcoinBtcKitConnector = BitcoinBtcKitConnector;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BtcKitListenFn, BtcKitRequestFn } from '@btckit/types';
|
|
2
2
|
import { BitcoinNetworkType } from 'sats-connect';
|
|
3
3
|
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from './BitcoinWalletConnector';
|
|
4
|
-
import { BitcoinTransaction } from './types';
|
|
4
|
+
import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from './types';
|
|
5
5
|
export type BtcKitProvider = {
|
|
6
6
|
request: BtcKitRequestFn;
|
|
7
7
|
listen: BtcKitListenFn;
|
|
@@ -13,4 +13,5 @@ export declare abstract class BitcoinBtcKitConnector extends BitcoinWalletConnec
|
|
|
13
13
|
fetchPublicAddress(): Promise<string | undefined>;
|
|
14
14
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
15
15
|
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
16
|
+
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
16
17
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
2
|
import { BitcoinNetworkType } from 'sats-connect';
|
|
3
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
3
4
|
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
5
|
import { BitcoinWalletConnector } from './BitcoinWalletConnector.js';
|
|
6
|
+
import { validatePsbt } from './utils/psbt/validator/validatePsbt.js';
|
|
7
|
+
import { convertNetworkTypeForPsbt } from './utils/psbt/bitcoinNetworkTypeToNetworks.js';
|
|
5
8
|
|
|
6
9
|
class BitcoinBtcKitConnector extends BitcoinWalletConnector {
|
|
7
10
|
constructor(opts, btcKit) {
|
|
@@ -67,6 +70,35 @@ class BitcoinBtcKitConnector extends BitcoinWalletConnector {
|
|
|
67
70
|
return response.result.txid;
|
|
68
71
|
});
|
|
69
72
|
}
|
|
73
|
+
signPsbt(request) {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const connectedAddress = yield this.fetchPublicAddress();
|
|
77
|
+
if (!connectedAddress || !this.btcKit) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const network = convertNetworkTypeForPsbt(this.currentNetwork);
|
|
81
|
+
const psbtFromBase64 = Psbt.fromBase64(request.unsignedPsbtBase64, {
|
|
82
|
+
network,
|
|
83
|
+
});
|
|
84
|
+
if ((_a = request.signature) === null || _a === void 0 ? void 0 : _a.length) {
|
|
85
|
+
validatePsbt(psbtFromBase64, request.allowedSighash, request.signature);
|
|
86
|
+
}
|
|
87
|
+
const signPsbtRequestParams = {
|
|
88
|
+
allowedSighash: request.allowedSighash,
|
|
89
|
+
hex: psbtFromBase64.toHex(),
|
|
90
|
+
signAtIndex: (_b = request.signature) === null || _b === void 0 ? void 0 : _b.flatMap((sig) => sig.signingIndexes).filter(Number.isInteger),
|
|
91
|
+
};
|
|
92
|
+
const signedPsbtResponse = (yield this.btcKit.request('signPsbt', Object.assign({ broadcast: false, network }, signPsbtRequestParams)));
|
|
93
|
+
if (!signedPsbtResponse ||
|
|
94
|
+
!('result' in signedPsbtResponse) ||
|
|
95
|
+
!('hex' in signedPsbtResponse.result)) {
|
|
96
|
+
throw new Error('signPsbt - failed to sign PSBT');
|
|
97
|
+
}
|
|
98
|
+
const psbtHex = signedPsbtResponse.result.hex;
|
|
99
|
+
return { signedPsbt: Psbt.fromHex(psbtHex, { network }).toBase64() };
|
|
100
|
+
});
|
|
101
|
+
}
|
|
70
102
|
}
|
|
71
103
|
|
|
72
104
|
export { BitcoinBtcKitConnector };
|
|
@@ -26,6 +26,12 @@ class BitcoinLocalStorageCache {
|
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
getConnectedAccounts() {
|
|
30
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const connectedAccounts = yield utils.getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
32
|
+
return connectedAccounts;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
29
35
|
getConnectedAccount(address) {
|
|
30
36
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
31
37
|
const connectedAccounts = yield utils.getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { WalletAdditionalAddress } from '@dynamic-labs/sdk-api';
|
|
2
2
|
import { BitcoinConnectedAccount } from './types';
|
|
3
|
+
type BitcoinConnectedAccounts = {
|
|
4
|
+
[key: string]: BitcoinConnectedAccount;
|
|
5
|
+
};
|
|
3
6
|
type BitcoinActiveAccount = {
|
|
4
7
|
address: string;
|
|
5
8
|
additionalAddresses: WalletAdditionalAddress[];
|
|
@@ -9,6 +12,7 @@ export declare class BitcoinLocalStorageCache implements IBitcoinSessionCache {
|
|
|
9
12
|
private readonly LAST_BALANCE_KEY;
|
|
10
13
|
constructor(key: string);
|
|
11
14
|
getActiveAccount(): Promise<BitcoinActiveAccount | undefined>;
|
|
15
|
+
getConnectedAccounts(): Promise<BitcoinConnectedAccounts | undefined>;
|
|
12
16
|
getConnectedAccount(address: string): Promise<BitcoinConnectedAccount | undefined>;
|
|
13
17
|
setConnectedAccount(addess: string, account: BitcoinConnectedAccount): Promise<void>;
|
|
14
18
|
clearConnectedAcccounts(): Promise<void>;
|
|
@@ -20,6 +24,7 @@ export interface IBitcoinSessionCache {
|
|
|
20
24
|
clearConnectedAcccounts(): Promise<void>;
|
|
21
25
|
getActiveAccount(): Promise<BitcoinActiveAccount | undefined>;
|
|
22
26
|
getConnectedAccount(address: string): Promise<BitcoinConnectedAccount | undefined>;
|
|
27
|
+
getConnectedAccounts(): Promise<BitcoinConnectedAccounts | undefined>;
|
|
23
28
|
setConnectedAccount(addess: string, account: BitcoinConnectedAccount): Promise<void>;
|
|
24
29
|
clearLastBalance(): Promise<void>;
|
|
25
30
|
getLastBalance(): Promise<string | undefined>;
|
|
@@ -22,6 +22,12 @@ class BitcoinLocalStorageCache {
|
|
|
22
22
|
};
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
getConnectedAccounts() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const connectedAccounts = yield getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
28
|
+
return connectedAccounts;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
25
31
|
getConnectedAccount(address) {
|
|
26
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
33
|
const connectedAccounts = yield getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
@@ -4,10 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _tslib = require('../_virtual/_tslib.cjs');
|
|
6
6
|
var satsConnect = require('sats-connect');
|
|
7
|
+
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
7
8
|
var BitcoinWalletConnector = require('./BitcoinWalletConnector.cjs');
|
|
8
9
|
var _const = require('./const.cjs');
|
|
9
10
|
require('@dynamic-labs/utils');
|
|
10
11
|
require('@dynamic-labs/wallet-connector-core');
|
|
12
|
+
var validatePsbt = require('./utils/psbt/validator/validatePsbt.cjs');
|
|
13
|
+
var getSigHashType = require('./utils/psbt/getSigHashType.cjs');
|
|
14
|
+
var bitcoinNetworkTypeToNetworks = require('./utils/psbt/bitcoinNetworkTypeToNetworks.cjs');
|
|
11
15
|
var supportsSatsConnect = require('./utils/supportsSatsConnect.cjs');
|
|
12
16
|
|
|
13
17
|
class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
@@ -92,10 +96,10 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
|
|
|
92
96
|
});
|
|
93
97
|
}
|
|
94
98
|
sendBitcoin(transaction) {
|
|
95
|
-
var _a
|
|
99
|
+
var _a;
|
|
96
100
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
97
101
|
const mainAddress = yield this.fetchPublicAddress();
|
|
98
|
-
const senderAddress = (
|
|
102
|
+
const senderAddress = (_a = (yield this.getAdditionalAddresses(mainAddress)).find((address) => address.type === 'payment')) === null || _a === void 0 ? void 0 : _a.address;
|
|
99
103
|
if (!senderAddress || !supportsSatsConnect.supportsSatsConnect(this)) {
|
|
100
104
|
return;
|
|
101
105
|
}
|
|
@@ -129,6 +133,67 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
|
|
|
129
133
|
});
|
|
130
134
|
});
|
|
131
135
|
}
|
|
136
|
+
signTransaction(params) {
|
|
137
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const { message, psbtBase64, broadcast, inputsToSign } = params;
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
satsConnect.signTransaction({
|
|
141
|
+
getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[_const.SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
144
|
+
}),
|
|
145
|
+
onCancel: () => {
|
|
146
|
+
const error = new Error();
|
|
147
|
+
error.code = '-32000'; // error code for user cancelled
|
|
148
|
+
reject(error);
|
|
149
|
+
},
|
|
150
|
+
onFinish: (response) => {
|
|
151
|
+
resolve(response);
|
|
152
|
+
},
|
|
153
|
+
payload: {
|
|
154
|
+
broadcast,
|
|
155
|
+
inputsToSign,
|
|
156
|
+
message: message || 'Sign Transaction',
|
|
157
|
+
network: {
|
|
158
|
+
type: this.currentNetwork,
|
|
159
|
+
},
|
|
160
|
+
psbtBase64,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
signPsbt(request) {
|
|
167
|
+
var _a, _b, _c, _d;
|
|
168
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
if (!((_a = request.allowedSighash) === null || _a === void 0 ? void 0 : _a.length))
|
|
170
|
+
throw new Error('allowedSighash cannot be an empty array');
|
|
171
|
+
const network = bitcoinNetworkTypeToNetworks.convertNetworkTypeForPsbt(this.currentNetwork);
|
|
172
|
+
const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64, {
|
|
173
|
+
network,
|
|
174
|
+
});
|
|
175
|
+
if ((_b = request.signature) === null || _b === void 0 ? void 0 : _b.length) {
|
|
176
|
+
validatePsbt.validatePsbt(psbtFromBase64, request.allowedSighash, request.signature);
|
|
177
|
+
}
|
|
178
|
+
const inputsToSign = ((_d = (_c = request.signature) === null || _c === void 0 ? void 0 : _c.map((sig) => {
|
|
179
|
+
var _a;
|
|
180
|
+
return ((_a = sig.signingIndexes) !== null && _a !== void 0 ? _a : []).map((inputIndex) => ({
|
|
181
|
+
address: sig.address,
|
|
182
|
+
sigHash: getSigHashType.getSigHashType(psbtFromBase64.data.inputs[inputIndex]),
|
|
183
|
+
signingIndexes: [inputIndex],
|
|
184
|
+
}));
|
|
185
|
+
})) !== null && _d !== void 0 ? _d : []).flat();
|
|
186
|
+
const signedPsbt = yield this.signTransaction({
|
|
187
|
+
broadcast: false,
|
|
188
|
+
inputsToSign,
|
|
189
|
+
psbtBase64: request.unsignedPsbtBase64,
|
|
190
|
+
});
|
|
191
|
+
if (!signedPsbt) {
|
|
192
|
+
throw new Error('Failed to sign transaction with sats-connect');
|
|
193
|
+
}
|
|
194
|
+
return { signedPsbt: signedPsbt.psbtBase64 };
|
|
195
|
+
});
|
|
196
|
+
}
|
|
132
197
|
}
|
|
133
198
|
|
|
134
199
|
exports.BitcoinSatsConnectConnector = BitcoinSatsConnectConnector;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { BitcoinNetworkType } from 'sats-connect';
|
|
1
|
+
import { BitcoinNetworkType, SignTransactionResponse } from 'sats-connect';
|
|
2
2
|
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from './BitcoinWalletConnector';
|
|
3
|
-
import { BitcoinTransaction } from './types';
|
|
3
|
+
import { BitcoinTransaction, SatsConnectSignTransactionInput, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from './types';
|
|
4
4
|
export declare abstract class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
5
5
|
currentNetwork: BitcoinNetworkType;
|
|
6
6
|
constructor(opts: BitcoinWalletConnectorOpts);
|
|
7
7
|
fetchPublicAddress(): Promise<string | undefined>;
|
|
8
8
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
9
9
|
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
10
|
+
signTransaction(params: SatsConnectSignTransactionInput): Promise<SignTransactionResponse | undefined>;
|
|
11
|
+
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
10
12
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
-
import { BitcoinNetworkType, getAddress, AddressPurpose, signMessage, sendBtcTransaction } from 'sats-connect';
|
|
2
|
+
import { BitcoinNetworkType, getAddress, AddressPurpose, signMessage, sendBtcTransaction, signTransaction } from 'sats-connect';
|
|
3
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
3
4
|
import { BitcoinWalletConnector } from './BitcoinWalletConnector.js';
|
|
4
5
|
import { SATSCONNECT_FEATURE } from './const.js';
|
|
5
6
|
import '@dynamic-labs/utils';
|
|
6
7
|
import '@dynamic-labs/wallet-connector-core';
|
|
8
|
+
import { validatePsbt } from './utils/psbt/validator/validatePsbt.js';
|
|
9
|
+
import { getSigHashType } from './utils/psbt/getSigHashType.js';
|
|
10
|
+
import { convertNetworkTypeForPsbt } from './utils/psbt/bitcoinNetworkTypeToNetworks.js';
|
|
7
11
|
import { supportsSatsConnect } from './utils/supportsSatsConnect.js';
|
|
8
12
|
|
|
9
13
|
class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
@@ -88,10 +92,10 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
|
88
92
|
});
|
|
89
93
|
}
|
|
90
94
|
sendBitcoin(transaction) {
|
|
91
|
-
var _a
|
|
95
|
+
var _a;
|
|
92
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
97
|
const mainAddress = yield this.fetchPublicAddress();
|
|
94
|
-
const senderAddress = (
|
|
98
|
+
const senderAddress = (_a = (yield this.getAdditionalAddresses(mainAddress)).find((address) => address.type === 'payment')) === null || _a === void 0 ? void 0 : _a.address;
|
|
95
99
|
if (!senderAddress || !supportsSatsConnect(this)) {
|
|
96
100
|
return;
|
|
97
101
|
}
|
|
@@ -125,6 +129,67 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
|
125
129
|
});
|
|
126
130
|
});
|
|
127
131
|
}
|
|
132
|
+
signTransaction(params) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const { message, psbtBase64, broadcast, inputsToSign } = params;
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
signTransaction({
|
|
137
|
+
getProvider: () => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
140
|
+
}),
|
|
141
|
+
onCancel: () => {
|
|
142
|
+
const error = new Error();
|
|
143
|
+
error.code = '-32000'; // error code for user cancelled
|
|
144
|
+
reject(error);
|
|
145
|
+
},
|
|
146
|
+
onFinish: (response) => {
|
|
147
|
+
resolve(response);
|
|
148
|
+
},
|
|
149
|
+
payload: {
|
|
150
|
+
broadcast,
|
|
151
|
+
inputsToSign,
|
|
152
|
+
message: message || 'Sign Transaction',
|
|
153
|
+
network: {
|
|
154
|
+
type: this.currentNetwork,
|
|
155
|
+
},
|
|
156
|
+
psbtBase64,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
signPsbt(request) {
|
|
163
|
+
var _a, _b, _c, _d;
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
if (!((_a = request.allowedSighash) === null || _a === void 0 ? void 0 : _a.length))
|
|
166
|
+
throw new Error('allowedSighash cannot be an empty array');
|
|
167
|
+
const network = convertNetworkTypeForPsbt(this.currentNetwork);
|
|
168
|
+
const psbtFromBase64 = Psbt.fromBase64(request.unsignedPsbtBase64, {
|
|
169
|
+
network,
|
|
170
|
+
});
|
|
171
|
+
if ((_b = request.signature) === null || _b === void 0 ? void 0 : _b.length) {
|
|
172
|
+
validatePsbt(psbtFromBase64, request.allowedSighash, request.signature);
|
|
173
|
+
}
|
|
174
|
+
const inputsToSign = ((_d = (_c = request.signature) === null || _c === void 0 ? void 0 : _c.map((sig) => {
|
|
175
|
+
var _a;
|
|
176
|
+
return ((_a = sig.signingIndexes) !== null && _a !== void 0 ? _a : []).map((inputIndex) => ({
|
|
177
|
+
address: sig.address,
|
|
178
|
+
sigHash: getSigHashType(psbtFromBase64.data.inputs[inputIndex]),
|
|
179
|
+
signingIndexes: [inputIndex],
|
|
180
|
+
}));
|
|
181
|
+
})) !== null && _d !== void 0 ? _d : []).flat();
|
|
182
|
+
const signedPsbt = yield this.signTransaction({
|
|
183
|
+
broadcast: false,
|
|
184
|
+
inputsToSign,
|
|
185
|
+
psbtBase64: request.unsignedPsbtBase64,
|
|
186
|
+
});
|
|
187
|
+
if (!signedPsbt) {
|
|
188
|
+
throw new Error('Failed to sign transaction with sats-connect');
|
|
189
|
+
}
|
|
190
|
+
return { signedPsbt: signedPsbt.psbtBase64 };
|
|
191
|
+
});
|
|
192
|
+
}
|
|
128
193
|
}
|
|
129
194
|
|
|
130
195
|
export { BitcoinSatsConnectConnector };
|