@coinbase/cdp-core 0.0.118 → 0.0.120
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/esm/index.web10.js +52 -51
- package/dist/esm/index.web107.js +3 -3
- package/dist/esm/index.web110.js +2 -2
- package/dist/esm/index.web114.js +3 -3
- package/dist/esm/index.web127.js +13 -373
- package/dist/esm/index.web128.js +22 -28
- package/dist/esm/index.web129.js +50 -28
- package/dist/esm/index.web130.js +373 -13
- package/dist/esm/index.web131.js +28 -22
- package/dist/esm/index.web132.js +28 -50
- package/dist/esm/index.web133.js +1 -1
- package/dist/esm/index.web134.js +1 -1
- package/dist/esm/index.web138.js +1 -1
- package/dist/esm/index.web139.js +1 -1
- package/dist/esm/index.web142.js +13 -2
- package/dist/esm/index.web143.js +12 -2
- package/dist/esm/index.web144.js +54 -14
- package/dist/esm/index.web145.js +10 -28
- package/dist/esm/index.web146.js +2 -8
- package/dist/esm/index.web147.js +45 -4
- package/dist/esm/index.web148.js +13 -28
- package/dist/esm/index.web149.js +4 -8
- package/dist/esm/index.web150.js +2 -8
- package/dist/esm/index.web151.js +2 -81
- package/dist/esm/index.web152.js +4 -18
- package/dist/esm/index.web153.js +28 -3
- package/dist/esm/index.web154.js +7 -15
- package/dist/esm/index.web155.js +3 -4
- package/dist/esm/index.web156.js +19 -5
- package/dist/esm/index.web157.js +8 -19
- package/dist/esm/index.web158.js +7 -61
- package/dist/esm/index.web159.js +79 -16
- package/dist/esm/index.web160.js +24 -19
- package/dist/esm/index.web161.js +3 -8
- package/dist/esm/index.web162.js +6 -33
- package/dist/esm/index.web163.js +4 -7
- package/dist/esm/index.web164.js +14 -20
- package/dist/esm/index.web165.js +18 -53
- package/dist/esm/index.web166.js +61 -10
- package/dist/esm/index.web167.js +18 -2
- package/dist/esm/index.web168.js +23 -44
- package/dist/esm/index.web169.js +8 -13
- package/dist/esm/index.web170.js +41 -11
- package/dist/esm/index.web171.js +7 -11
- package/dist/esm/index.web172.js +20 -4
- package/dist/esm/index.web191.js +1 -1
- package/dist/esm/index.web193.js +1 -1
- package/dist/esm/index.web194.js +2 -2
- package/dist/esm/index.web202.js +2 -2
- package/dist/esm/index.web21.js +16 -5
- package/dist/esm/index.web219.js +102 -19
- package/dist/esm/index.web220.js +79 -10
- package/dist/esm/index.web221.js +79 -20
- package/dist/esm/index.web222.js +20 -93
- package/dist/esm/index.web223.js +9 -20
- package/dist/esm/index.web224.js +16 -114
- package/dist/esm/index.web225.js +89 -99
- package/dist/esm/index.web226.js +20 -78
- package/dist/esm/index.web227.js +118 -79
- package/dist/esm/index.web228.js +2 -109
- package/dist/esm/index.web229.js +109 -2
- package/dist/esm/index.web230.js +2 -2
- package/dist/esm/index.web237.js +1 -1
- package/dist/esm/index.web242.js +1 -1
- package/dist/esm/index.web244.js +1 -1
- package/dist/esm/index.web247.js +1 -1
- package/dist/esm/index.web248.js +1 -1
- package/dist/esm/index.web250.js +78 -14
- package/dist/esm/index.web251.js +14 -78
- package/dist/esm/index.web64.js +24 -22
- package/dist/esm/index.web65.js +13 -17
- package/dist/esm/index.web85.js +85 -64
- package/dist/esm/index.web9.js +1 -1
- package/dist/native/index.native109.js +3 -3
- package/dist/native/index.native11.js +1 -1
- package/dist/native/index.native116.js +2 -2
- package/dist/native/index.native12.js +51 -50
- package/dist/native/index.native128.js +12 -12
- package/dist/native/index.native133.js +104 -27
- package/dist/native/index.native134.js +16 -28
- package/dist/native/index.native135.js +21 -15
- package/dist/native/index.native136.js +49 -21
- package/dist/native/index.native137.js +28 -50
- package/dist/native/index.native138.js +27 -104
- package/dist/native/index.native141.js +1 -1
- package/dist/native/index.native142.js +1 -1
- package/dist/native/index.native144.js +1 -1
- package/dist/native/index.native145.js +2 -2
- package/dist/native/index.native146.js +5 -55
- package/dist/native/index.native147.js +47 -10
- package/dist/native/index.native148.js +36 -2
- package/dist/native/index.native149.js +66 -43
- package/dist/native/index.native150.js +54 -13
- package/dist/native/index.native151.js +11 -5
- package/dist/native/index.native152.js +2 -48
- package/dist/native/index.native153.js +44 -35
- package/dist/native/index.native154.js +12 -66
- package/dist/native/index.native155.js +13 -13
- package/dist/native/index.native156.js +54 -26
- package/dist/native/index.native157.js +6 -7
- package/dist/native/index.native158.js +21 -3
- package/dist/native/index.native159.js +16 -26
- package/dist/native/index.native160.js +45 -8
- package/dist/native/index.native161.js +3 -7
- package/dist/native/index.native162.js +3 -79
- package/dist/native/index.native163.js +32 -25
- package/dist/native/index.native164.js +12 -3
- package/dist/native/index.native165.js +4 -14
- package/dist/native/index.native166.js +28 -4
- package/dist/native/index.native167.js +6 -13
- package/dist/native/index.native168.js +31 -18
- package/dist/native/index.native169.js +9 -57
- package/dist/native/index.native170.js +55 -17
- package/dist/native/index.native171.js +41 -22
- package/dist/native/index.native172.js +127 -8
- package/dist/native/index.native173.js +102 -39
- package/dist/native/index.native174.js +6 -7
- package/dist/native/index.native175.js +3 -21
- package/dist/native/index.native176.js +79 -2
- package/dist/native/index.native177.js +2 -2
- package/dist/native/index.native178.js +2 -14
- package/dist/native/index.native179.js +33 -51
- package/dist/native/index.native180.js +6 -6
- package/dist/native/index.native181.js +32 -19
- package/dist/native/index.native182.js +14 -17
- package/dist/native/index.native183.js +30 -41
- package/dist/native/index.native184.js +18 -3
- package/dist/native/index.native185.js +8 -3
- package/dist/native/index.native186.js +9 -33
- package/dist/native/index.native187.js +11 -12
- package/dist/native/index.native188.js +13 -4
- package/dist/native/index.native189.js +5 -28
- package/dist/native/index.native190.js +5 -7
- package/dist/native/index.native191.js +10 -32
- package/dist/native/index.native192.js +2 -13
- package/dist/native/index.native193.js +2 -56
- package/dist/native/index.native194.js +13 -42
- package/dist/native/index.native195.js +26 -126
- package/dist/native/index.native196.js +7 -104
- package/dist/native/index.native197.js +3 -6
- package/dist/native/index.native198.js +28 -3
- package/dist/native/index.native199.js +8 -78
- package/dist/native/index.native2.js +2 -2
- package/dist/native/index.native200.js +8 -2
- package/dist/native/index.native201.js +80 -2
- package/dist/native/index.native202.js +25 -35
- package/dist/native/index.native203.js +3 -6
- package/dist/native/index.native204.js +14 -34
- package/dist/native/index.native205.js +4 -14
- package/dist/native/index.native206.js +13 -34
- package/dist/native/index.native207.js +18 -17
- package/dist/native/index.native208.js +60 -8
- package/dist/native/index.native209.js +17 -10
- package/dist/native/index.native210.js +23 -11
- package/dist/native/index.native211.js +8 -13
- package/dist/native/index.native212.js +41 -5
- package/dist/native/index.native213.js +8 -5
- package/dist/native/index.native214.js +20 -10
- package/dist/native/index.native221.js +2 -2
- package/dist/native/index.native222.js +3 -3
- package/dist/native/index.native224.js +3 -3
- package/dist/native/index.native225.js +1 -1
- package/dist/native/index.native226.js +3 -3
- package/dist/native/index.native227.js +38 -7
- package/dist/native/index.native229.js +67 -358
- package/dist/native/index.native23.js +16 -5
- package/dist/native/index.native230.js +34 -852
- package/dist/native/index.native231.js +14 -38
- package/dist/native/index.native232.js +8 -2
- package/dist/native/index.native233.js +2 -70
- package/dist/native/index.native234.js +355 -29
- package/dist/native/index.native235.js +852 -14
- package/dist/native/index.native236.js +14 -40
- package/dist/native/index.native237.js +2 -21
- package/dist/native/index.native238.js +20 -2
- package/dist/native/index.native239.js +31 -18
- package/dist/native/index.native240.js +6 -32
- package/dist/native/index.native241.js +3 -6
- package/dist/native/index.native242.js +45 -16
- package/dist/native/index.native243.js +2 -28
- package/dist/native/index.native244.js +2 -8
- package/dist/native/index.native245.js +2 -11
- package/dist/native/index.native246.js +16 -11
- package/dist/native/index.native247.js +28 -10
- package/dist/native/index.native248.js +8 -17
- package/dist/native/index.native249.js +9 -79
- package/dist/native/index.native250.js +13 -2
- package/dist/native/index.native251.js +10 -2
- package/dist/native/index.native252.js +15 -2
- package/dist/native/index.native253.js +81 -2
- package/dist/native/index.native256.js +1 -1
- package/dist/native/index.native3.js +1 -1
- package/dist/native/index.native66.js +24 -22
- package/dist/native/index.native67.js +15 -19
- package/dist/native/index.native86.js +1 -1
- package/dist/native/index.native87.js +85 -64
- package/dist/native-types/actions/createBitcoinAccount.d.ts +5 -2
- package/dist/native-types/actions/getCurrentUser.d.ts +18 -1
- package/dist/native-types/actions/signBitcoinHash.d.ts +7 -5
- package/dist/native-types/core.d.ts +1 -1
- package/dist/native-types/types.d.ts +2 -2
- package/dist/native-types/version.d.ts +1 -1
- package/dist/types/actions/createBitcoinAccount.d.ts +5 -2
- package/dist/types/actions/getCurrentUser.d.ts +18 -1
- package/dist/types/actions/signBitcoinHash.d.ts +7 -5
- package/dist/types/core.d.ts +1 -1
- package/dist/types/types.d.ts +2 -2
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index.web10.js +52 -51
- package/dist/web/index.web107.js +3 -3
- package/dist/web/index.web110.js +2 -2
- package/dist/web/index.web114.js +3 -3
- package/dist/web/index.web127.js +13 -373
- package/dist/web/index.web128.js +22 -28
- package/dist/web/index.web129.js +50 -28
- package/dist/web/index.web130.js +373 -13
- package/dist/web/index.web131.js +28 -22
- package/dist/web/index.web132.js +28 -50
- package/dist/web/index.web133.js +1 -1
- package/dist/web/index.web134.js +1 -1
- package/dist/web/index.web138.js +1 -1
- package/dist/web/index.web139.js +1 -1
- package/dist/web/index.web142.js +13 -2
- package/dist/web/index.web143.js +12 -2
- package/dist/web/index.web144.js +54 -14
- package/dist/web/index.web145.js +10 -28
- package/dist/web/index.web146.js +2 -8
- package/dist/web/index.web147.js +45 -4
- package/dist/web/index.web148.js +13 -28
- package/dist/web/index.web149.js +4 -8
- package/dist/web/index.web150.js +2 -8
- package/dist/web/index.web151.js +2 -81
- package/dist/web/index.web152.js +4 -18
- package/dist/web/index.web153.js +28 -3
- package/dist/web/index.web154.js +7 -15
- package/dist/web/index.web155.js +3 -4
- package/dist/web/index.web156.js +19 -5
- package/dist/web/index.web157.js +8 -19
- package/dist/web/index.web158.js +7 -61
- package/dist/web/index.web159.js +79 -16
- package/dist/web/index.web160.js +24 -19
- package/dist/web/index.web161.js +3 -8
- package/dist/web/index.web162.js +6 -33
- package/dist/web/index.web163.js +4 -7
- package/dist/web/index.web164.js +14 -20
- package/dist/web/index.web165.js +18 -53
- package/dist/web/index.web166.js +61 -10
- package/dist/web/index.web167.js +18 -2
- package/dist/web/index.web168.js +23 -44
- package/dist/web/index.web169.js +8 -13
- package/dist/web/index.web170.js +41 -11
- package/dist/web/index.web171.js +7 -11
- package/dist/web/index.web172.js +20 -4
- package/dist/web/index.web191.js +1 -1
- package/dist/web/index.web193.js +1 -1
- package/dist/web/index.web194.js +2 -2
- package/dist/web/index.web202.js +2 -2
- package/dist/web/index.web21.js +16 -5
- package/dist/web/index.web219.js +102 -19
- package/dist/web/index.web220.js +79 -10
- package/dist/web/index.web221.js +79 -20
- package/dist/web/index.web222.js +20 -93
- package/dist/web/index.web223.js +9 -20
- package/dist/web/index.web224.js +16 -114
- package/dist/web/index.web225.js +89 -99
- package/dist/web/index.web226.js +20 -78
- package/dist/web/index.web227.js +118 -79
- package/dist/web/index.web228.js +2 -109
- package/dist/web/index.web229.js +109 -2
- package/dist/web/index.web230.js +2 -2
- package/dist/web/index.web237.js +1 -1
- package/dist/web/index.web242.js +1 -1
- package/dist/web/index.web244.js +1 -1
- package/dist/web/index.web247.js +1 -1
- package/dist/web/index.web248.js +1 -1
- package/dist/web/index.web250.js +78 -14
- package/dist/web/index.web251.js +14 -78
- package/dist/web/index.web64.js +24 -22
- package/dist/web/index.web65.js +13 -17
- package/dist/web/index.web85.js +85 -64
- package/dist/web/index.web9.js +1 -1
- package/dist/web-types/actions/createBitcoinAccount.d.ts +5 -2
- package/dist/web-types/actions/getCurrentUser.d.ts +18 -1
- package/dist/web-types/actions/signBitcoinHash.d.ts +7 -5
- package/dist/web-types/core.d.ts +1 -1
- package/dist/web-types/types.d.ts +2 -2
- package/dist/web-types/version.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,83 @@
|
|
|
1
|
-
|
|
1
|
+
import { JOSENotSupported as s } from "./index.native135.js";
|
|
2
|
+
function n(e) {
|
|
3
|
+
let a, r;
|
|
4
|
+
switch (e.kty) {
|
|
5
|
+
case "RSA": {
|
|
6
|
+
switch (e.alg) {
|
|
7
|
+
case "PS256":
|
|
8
|
+
case "PS384":
|
|
9
|
+
case "PS512":
|
|
10
|
+
a = { name: "RSA-PSS", hash: `SHA-${e.alg.slice(-3)}` }, r = e.d ? ["sign"] : ["verify"];
|
|
11
|
+
break;
|
|
12
|
+
case "RS256":
|
|
13
|
+
case "RS384":
|
|
14
|
+
case "RS512":
|
|
15
|
+
a = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${e.alg.slice(-3)}` }, r = e.d ? ["sign"] : ["verify"];
|
|
16
|
+
break;
|
|
17
|
+
case "RSA-OAEP":
|
|
18
|
+
case "RSA-OAEP-256":
|
|
19
|
+
case "RSA-OAEP-384":
|
|
20
|
+
case "RSA-OAEP-512":
|
|
21
|
+
a = {
|
|
22
|
+
name: "RSA-OAEP",
|
|
23
|
+
hash: `SHA-${parseInt(e.alg.slice(-3), 10) || 1}`
|
|
24
|
+
}, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
throw new s('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
case "EC": {
|
|
32
|
+
switch (e.alg) {
|
|
33
|
+
case "ES256":
|
|
34
|
+
a = { name: "ECDSA", namedCurve: "P-256" }, r = e.d ? ["sign"] : ["verify"];
|
|
35
|
+
break;
|
|
36
|
+
case "ES384":
|
|
37
|
+
a = { name: "ECDSA", namedCurve: "P-384" }, r = e.d ? ["sign"] : ["verify"];
|
|
38
|
+
break;
|
|
39
|
+
case "ES512":
|
|
40
|
+
a = { name: "ECDSA", namedCurve: "P-521" }, r = e.d ? ["sign"] : ["verify"];
|
|
41
|
+
break;
|
|
42
|
+
case "ECDH-ES":
|
|
43
|
+
case "ECDH-ES+A128KW":
|
|
44
|
+
case "ECDH-ES+A192KW":
|
|
45
|
+
case "ECDH-ES+A256KW":
|
|
46
|
+
a = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
throw new s('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case "OKP": {
|
|
54
|
+
switch (e.alg) {
|
|
55
|
+
case "Ed25519":
|
|
56
|
+
case "EdDSA":
|
|
57
|
+
a = { name: "Ed25519" }, r = e.d ? ["sign"] : ["verify"];
|
|
58
|
+
break;
|
|
59
|
+
case "ECDH-ES":
|
|
60
|
+
case "ECDH-ES+A128KW":
|
|
61
|
+
case "ECDH-ES+A192KW":
|
|
62
|
+
case "ECDH-ES+A256KW":
|
|
63
|
+
a = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
throw new s('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
default:
|
|
71
|
+
throw new s('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
72
|
+
}
|
|
73
|
+
return { algorithm: a, keyUsages: r };
|
|
74
|
+
}
|
|
75
|
+
const i = async (e) => {
|
|
76
|
+
if (!e.alg)
|
|
77
|
+
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
78
|
+
const { algorithm: a, keyUsages: r } = n(e), t = { ...e };
|
|
79
|
+
return delete t.alg, delete t.use, crypto.subtle.importKey("jwk", t, a, e.ext ?? !e.d, e.key_ops ?? r);
|
|
80
|
+
};
|
|
2
81
|
export {
|
|
3
|
-
|
|
82
|
+
i as default
|
|
4
83
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { __require as r } from "./index.
|
|
1
|
+
import { __require as r } from "./index.native232.js";
|
|
2
2
|
r();
|
|
@@ -1,37 +1,39 @@
|
|
|
1
|
-
import { createEndUserBtcAccount as
|
|
2
|
-
import { Analytics as
|
|
1
|
+
import { createEndUserBtcAccount as h } from "@coinbase/cdp-api-client";
|
|
2
|
+
import { Analytics as p } from "./index.native2.js";
|
|
3
3
|
import "./index.native3.js";
|
|
4
4
|
import { toAuthStateUser as m } from "./index.native103.js";
|
|
5
|
-
import { InternalError as
|
|
6
|
-
import { validateUserAuthState as
|
|
7
|
-
import { getCoreAuthManager as
|
|
8
|
-
async function U(
|
|
9
|
-
|
|
10
|
-
const t =
|
|
5
|
+
import { InternalError as o } from "./index.native90.js";
|
|
6
|
+
import { validateUserAuthState as w } from "./index.native104.js";
|
|
7
|
+
import { getCoreAuthManager as b, getConfig as A } from "./index.native76.js";
|
|
8
|
+
async function U(r) {
|
|
9
|
+
p.sendActionCallEvent({ name: "create_bitcoin_account" });
|
|
10
|
+
const t = b(), { user: c, authState: s } = w(
|
|
11
11
|
t.getUser(),
|
|
12
12
|
t.getAuthState()
|
|
13
|
-
),
|
|
13
|
+
), n = await h(
|
|
14
14
|
c.userId,
|
|
15
15
|
{
|
|
16
16
|
walletSecretId: await t.getWalletSecretId(),
|
|
17
|
-
addressType:
|
|
18
|
-
network:
|
|
17
|
+
addressType: r?.addressType ?? "segwit",
|
|
18
|
+
network: r?.network ?? "bitcoin-testnet"
|
|
19
19
|
},
|
|
20
|
-
{ projectID:
|
|
21
|
-
|
|
22
|
-
),
|
|
20
|
+
{ projectID: A().projectId },
|
|
21
|
+
r?.idempotencyKey
|
|
22
|
+
), i = m(n), u = t.getAuthState() ?? s;
|
|
23
23
|
await t.setAuthState({
|
|
24
|
-
...
|
|
25
|
-
user:
|
|
24
|
+
...u,
|
|
25
|
+
user: i
|
|
26
26
|
});
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!o)
|
|
31
|
-
throw new l(
|
|
27
|
+
const d = new Set(c.btcAccountObjects?.map((a) => a.xpubHash) ?? []), e = (n.btcAccountObjects ?? []).find((a) => !d.has(a.xpubHash));
|
|
28
|
+
if (!e)
|
|
29
|
+
throw new o(
|
|
32
30
|
"Bitcoin account was not created. Check the network log for more details."
|
|
33
31
|
);
|
|
34
|
-
|
|
32
|
+
if (!e.xpub)
|
|
33
|
+
throw new o(
|
|
34
|
+
"Bitcoin account was created but the server did not return its extended public key (xpub)."
|
|
35
|
+
);
|
|
36
|
+
return { ...e, xpub: e.xpub };
|
|
35
37
|
}
|
|
36
38
|
export {
|
|
37
39
|
U as createBitcoinAccount
|
|
@@ -1,41 +1,37 @@
|
|
|
1
|
-
import { signBtcHashWithEndUserAccount as
|
|
2
|
-
import { Analytics as
|
|
1
|
+
import { signBtcHashWithEndUserAccount as c } from "@coinbase/cdp-api-client";
|
|
2
|
+
import { Analytics as s } from "./index.native2.js";
|
|
3
3
|
import "./index.native3.js";
|
|
4
|
-
import { withAuth as
|
|
5
|
-
import { getConfig as
|
|
4
|
+
import { withAuth as i } from "./index.native99.js";
|
|
5
|
+
import { getConfig as e, getCoreAuthManager as o } from "./index.native76.js";
|
|
6
6
|
import "viem";
|
|
7
|
-
import { withMfa as
|
|
7
|
+
import { withMfa as h } from "./index.native85.js";
|
|
8
8
|
import "jose";
|
|
9
9
|
import "./index.native100.js";
|
|
10
10
|
import "./index.native101.js";
|
|
11
11
|
import "@solana/web3.js";
|
|
12
12
|
import "bs58";
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
13
|
+
const E = async (t) => {
|
|
14
|
+
if (s.sendActionCallEvent({ name: "sign_bitcoin_hash" }), !/^[0-9a-fA-F]{64}$/.test(t.hash))
|
|
15
15
|
throw new Error("hash must be a 64-character hex string with no 0x prefix");
|
|
16
|
-
return
|
|
17
|
-
() =>
|
|
18
|
-
|
|
19
|
-
if (!e.btcAccountObjects?.find(
|
|
20
|
-
(s) => s.network === r && s.addressType === n
|
|
21
|
-
))
|
|
16
|
+
return e().useMock ? { signature: "3045022100" + "a".repeat(64) + "0220" + "b".repeat(64) } : h(
|
|
17
|
+
() => i(t, o(), async ({ user: r, walletSecretId: a }) => {
|
|
18
|
+
if (!r.btcAccountObjects?.find((n) => n.xpubHash === t.xpubHash))
|
|
22
19
|
throw new Error("Bitcoin account not found");
|
|
23
|
-
return { signature: (await
|
|
24
|
-
|
|
20
|
+
return { signature: (await c(
|
|
21
|
+
r.userId,
|
|
25
22
|
{
|
|
26
23
|
walletSecretId: a,
|
|
27
|
-
|
|
28
|
-
network: r,
|
|
24
|
+
xpubHash: t.xpubHash,
|
|
29
25
|
change: t.change,
|
|
30
26
|
addressIndex: t.addressIndex,
|
|
31
27
|
hash: t.hash
|
|
32
28
|
},
|
|
33
|
-
{ projectID:
|
|
29
|
+
{ projectID: e().projectId },
|
|
34
30
|
t.idempotencyKey
|
|
35
31
|
)).signature };
|
|
36
32
|
})
|
|
37
33
|
);
|
|
38
34
|
};
|
|
39
35
|
export {
|
|
40
|
-
|
|
36
|
+
E as signBitcoinHash
|
|
41
37
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSolanaKeyExportIframe as t, createEvmKeyExportIframe as m } from "./index.
|
|
1
|
+
import { createSolanaKeyExportIframe as t, createEvmKeyExportIframe as m } from "./index.native133.js";
|
|
2
2
|
import { signBitcoinHash as i } from "./index.native67.js";
|
|
3
3
|
import "@coinbase/cdp-api-client";
|
|
4
4
|
import "./index.native2.js";
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { logOutEndUser as f, refreshAccessToken as d,
|
|
2
|
-
import { Analytics as
|
|
1
|
+
import { logOutEndUser as f, refreshAccessToken as d, isRefreshTokenUnavailableError as m, isTransientTokenReadError as S, registerTemporaryWalletSecret as w, APIError as y } from "@coinbase/cdp-api-client";
|
|
2
|
+
import { Analytics as i } from "./index.native2.js";
|
|
3
3
|
import "./index.native3.js";
|
|
4
4
|
import "jose";
|
|
5
|
-
import { SignJWT as
|
|
6
|
-
import { toAuthState as
|
|
5
|
+
import { SignJWT as _ } from "./index.native109.js";
|
|
6
|
+
import { toAuthState as k } from "./index.native103.js";
|
|
7
7
|
import "viem";
|
|
8
8
|
import { getPlatformCrypto as c } from "./index.native10.js";
|
|
9
9
|
import { sortKeys as p } from "./index.native100.js";
|
|
10
|
-
import { getCoreOAuthManager as
|
|
11
|
-
const l = 60 * 1e3,
|
|
10
|
+
import { getCoreOAuthManager as T } from "./index.native76.js";
|
|
11
|
+
const l = 60 * 1e3, R = {
|
|
12
12
|
maxRetries: 3,
|
|
13
13
|
baseDelayMs: 1e3,
|
|
14
14
|
maxDelayMs: 1e4
|
|
15
15
|
};
|
|
16
|
-
function
|
|
17
|
-
const n = e * Math.pow(2,
|
|
18
|
-
return Math.min(n +
|
|
16
|
+
function g(s, e, r) {
|
|
17
|
+
const n = e * Math.pow(2, s), o = Math.random() * 0.3 * n;
|
|
18
|
+
return Math.min(n + o, r);
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
return new Promise((e) => setTimeout(e,
|
|
20
|
+
function A(s) {
|
|
21
|
+
return new Promise((e) => setTimeout(e, s));
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
if (
|
|
23
|
+
function E(s) {
|
|
24
|
+
if (s instanceof TypeError && s.message.includes("fetch"))
|
|
25
25
|
return !0;
|
|
26
|
-
if (
|
|
27
|
-
if (
|
|
26
|
+
if (s instanceof y) {
|
|
27
|
+
if (s.statusCode >= 500 && s.statusCode < 600 || s.statusCode === 408 || s.statusCode === 429)
|
|
28
28
|
return !0;
|
|
29
|
-
if (
|
|
29
|
+
if (s.statusCode === 401)
|
|
30
30
|
return !1;
|
|
31
31
|
}
|
|
32
|
-
if (
|
|
33
|
-
const e =
|
|
32
|
+
if (s instanceof Error) {
|
|
33
|
+
const e = s.message.toLowerCase();
|
|
34
34
|
if (e.includes("network") || e.includes("timeout") || e.includes("econnrefused") || e.includes("enotfound") || e.includes("socket"))
|
|
35
35
|
return !0;
|
|
36
36
|
}
|
|
37
37
|
return !1;
|
|
38
38
|
}
|
|
39
|
-
class
|
|
39
|
+
class j {
|
|
40
40
|
projectId;
|
|
41
41
|
authState = null;
|
|
42
42
|
walletSecret = null;
|
|
@@ -139,14 +139,14 @@ class v {
|
|
|
139
139
|
if (!await this.isSignedIn())
|
|
140
140
|
throw new Error("Cannot get X-Wallet-Auth header if the user is not signed in");
|
|
141
141
|
this.shouldRefreshWalletSecret() && await this.refreshWalletSecret();
|
|
142
|
-
const
|
|
143
|
-
uris: [
|
|
142
|
+
const r = `${e.requestMethod} ${e.requestHost}${e.requestPath}`, n = Math.floor(Date.now() / 1e3), o = c(), a = {
|
|
143
|
+
uris: [r]
|
|
144
144
|
};
|
|
145
145
|
if (e.requestData && Object.keys(e.requestData).length > 0) {
|
|
146
|
-
const
|
|
147
|
-
|
|
146
|
+
const t = p(e.requestData);
|
|
147
|
+
a.reqHash = await o.hash(new TextEncoder().encode(JSON.stringify(t)));
|
|
148
148
|
}
|
|
149
|
-
return await new
|
|
149
|
+
return await new _(a).setProtectedHeader({ alg: "ES256", typ: "JWT" }).setIssuedAt(n).setNotBefore(n).setJti(o.generateRandomId()).sign(this.walletSecret.keyPair.privateKey);
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* Gets the authentication state.
|
|
@@ -162,13 +162,13 @@ class v {
|
|
|
162
162
|
* @param authState - The authentication state.
|
|
163
163
|
*/
|
|
164
164
|
async setAuthState(e) {
|
|
165
|
-
this.authState = e,
|
|
165
|
+
this.authState = e, i.endUserIdentifier = e.user.userId, this.authStateChangeCallbacks.forEach((r) => r(this.authState?.user ?? null)), this.scheduleTokenRefresh();
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
168
|
* Clears the authentication state.
|
|
169
169
|
*/
|
|
170
170
|
async clearAuthState() {
|
|
171
|
-
this.authState = null, this.walletSecret = null,
|
|
171
|
+
this.authState = null, this.walletSecret = null, i.endUserIdentifier = "", this.cancelTokenRefresh(), this.authStateChangeCallbacks.forEach((e) => e(null));
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
174
|
* Ensures the AuthManager is initialized before proceeding.
|
|
@@ -186,7 +186,7 @@ class v {
|
|
|
186
186
|
*/
|
|
187
187
|
async _doInitialize() {
|
|
188
188
|
try {
|
|
189
|
-
await this.refreshAccessToken("init"), await
|
|
189
|
+
await this.refreshAccessToken("init"), await T().handleOAuthCode();
|
|
190
190
|
} catch (e) {
|
|
191
191
|
console.warn("Failed to refresh access token during initialization:", e);
|
|
192
192
|
}
|
|
@@ -210,57 +210,78 @@ class v {
|
|
|
210
210
|
* @returns The new access token.
|
|
211
211
|
*/
|
|
212
212
|
async refreshAccessToken(e = "on_demand") {
|
|
213
|
-
const { maxRetries:
|
|
214
|
-
|
|
213
|
+
const { maxRetries: r, baseDelayMs: n, maxDelayMs: o } = R;
|
|
214
|
+
i.sendSessionRefreshEvent({
|
|
215
215
|
name: "refresh_token_start",
|
|
216
216
|
trigger: e
|
|
217
217
|
});
|
|
218
|
-
for (let
|
|
218
|
+
for (let a = 0; a <= r; a++)
|
|
219
219
|
try {
|
|
220
|
-
const
|
|
220
|
+
const t = await d(this.projectId, {
|
|
221
221
|
grantType: "refresh_token"
|
|
222
|
-
}),
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
222
|
+
}), h = k(
|
|
223
|
+
t.accessToken,
|
|
224
|
+
t.validUntil,
|
|
225
|
+
t.endUser
|
|
226
226
|
);
|
|
227
|
-
await this.setAuthState(
|
|
227
|
+
await this.setAuthState(h), i.sendSessionRefreshEvent({
|
|
228
228
|
name: "refresh_token_success",
|
|
229
229
|
trigger: e,
|
|
230
|
-
attempt:
|
|
230
|
+
attempt: a
|
|
231
231
|
});
|
|
232
232
|
return;
|
|
233
|
-
} catch (
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
|
|
233
|
+
} catch (t) {
|
|
234
|
+
const h = t instanceof Error ? t.message : String(t);
|
|
235
|
+
if (m(t)) {
|
|
236
|
+
if (S(t)) {
|
|
237
|
+
i.sendSessionRefreshEvent({
|
|
238
|
+
name: "refresh_token_skipped_transient",
|
|
239
|
+
trigger: e,
|
|
240
|
+
attempt: a,
|
|
241
|
+
read_outcome: t.outcome,
|
|
242
|
+
error_message: h
|
|
243
|
+
});
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
i.sendSessionRefreshEvent({
|
|
237
247
|
name: "refresh_token_failure",
|
|
238
248
|
trigger: e,
|
|
239
|
-
attempt:
|
|
249
|
+
attempt: a,
|
|
240
250
|
error_type: "non_transient",
|
|
241
|
-
|
|
251
|
+
read_outcome: t.outcome,
|
|
252
|
+
error_message: h
|
|
242
253
|
}), await this.signOut();
|
|
243
254
|
return;
|
|
244
255
|
}
|
|
245
|
-
if (
|
|
246
|
-
|
|
256
|
+
if (!E(t)) {
|
|
257
|
+
i.sendSessionRefreshEvent({
|
|
258
|
+
name: "refresh_token_failure",
|
|
259
|
+
trigger: e,
|
|
260
|
+
attempt: a,
|
|
261
|
+
error_type: "non_transient",
|
|
262
|
+
error_message: h
|
|
263
|
+
}), await this.signOut();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (a === r) {
|
|
267
|
+
i.sendSessionRefreshEvent({
|
|
247
268
|
name: "refresh_token_exhausted",
|
|
248
269
|
trigger: e,
|
|
249
|
-
attempt:
|
|
270
|
+
attempt: a,
|
|
250
271
|
error_type: "transient",
|
|
251
|
-
error_message:
|
|
272
|
+
error_message: h
|
|
252
273
|
});
|
|
253
274
|
return;
|
|
254
275
|
}
|
|
255
|
-
|
|
276
|
+
i.sendSessionRefreshEvent({
|
|
256
277
|
name: "refresh_token_retry",
|
|
257
278
|
trigger: e,
|
|
258
|
-
attempt:
|
|
279
|
+
attempt: a,
|
|
259
280
|
error_type: "transient",
|
|
260
|
-
error_message:
|
|
281
|
+
error_message: h
|
|
261
282
|
});
|
|
262
|
-
const u =
|
|
263
|
-
await
|
|
283
|
+
const u = g(a, n, o);
|
|
284
|
+
await A(u);
|
|
264
285
|
}
|
|
265
286
|
}
|
|
266
287
|
/**
|
|
@@ -270,13 +291,13 @@ class v {
|
|
|
270
291
|
scheduleTokenRefresh() {
|
|
271
292
|
if (this.cancelTokenRefresh(), !this.authState)
|
|
272
293
|
return;
|
|
273
|
-
const
|
|
274
|
-
|
|
294
|
+
const r = this.authState.expiresAt - l - Date.now();
|
|
295
|
+
r <= 0 || (i.sendSessionRefreshEvent({
|
|
275
296
|
name: "refresh_token_scheduled",
|
|
276
|
-
time_until_refresh_ms:
|
|
297
|
+
time_until_refresh_ms: r
|
|
277
298
|
}), this.refreshTimeout = setTimeout(async () => {
|
|
278
299
|
await this.refreshAccessToken("scheduled"), this.scheduleTokenRefresh();
|
|
279
|
-
},
|
|
300
|
+
}, r));
|
|
280
301
|
}
|
|
281
302
|
/**
|
|
282
303
|
* Cancels any scheduled token refresh.
|
|
@@ -313,23 +334,23 @@ class v {
|
|
|
313
334
|
* Internal wallet secret refresh logic.
|
|
314
335
|
*/
|
|
315
336
|
async _doRefreshWalletSecret() {
|
|
316
|
-
const e = c(),
|
|
317
|
-
this.walletSecret = { walletSecretId:
|
|
337
|
+
const e = c(), r = this.walletSecret?.walletSecretId ?? e.generateRandomId(), n = this.walletSecret?.keyPair ?? await e.createKeyPair(), o = this.authState.expiresAt, a = new Date(o).toISOString();
|
|
338
|
+
this.walletSecret = { walletSecretId: r, keyPair: n, expiresAt: o };
|
|
318
339
|
try {
|
|
319
|
-
await
|
|
340
|
+
await w(
|
|
320
341
|
this.authState.user.userId,
|
|
321
342
|
{
|
|
322
|
-
walletSecretId:
|
|
343
|
+
walletSecretId: r,
|
|
323
344
|
publicKey: n.publicKeyBase64,
|
|
324
|
-
validUntil:
|
|
345
|
+
validUntil: a
|
|
325
346
|
},
|
|
326
347
|
{ projectID: this.projectId }
|
|
327
348
|
);
|
|
328
|
-
} catch (
|
|
329
|
-
throw this.walletSecret = null,
|
|
349
|
+
} catch (t) {
|
|
350
|
+
throw this.walletSecret = null, t;
|
|
330
351
|
}
|
|
331
352
|
}
|
|
332
353
|
}
|
|
333
354
|
export {
|
|
334
|
-
|
|
355
|
+
j as AuthManager
|
|
335
356
|
};
|
|
@@ -11,9 +11,12 @@ export type CreateBitcoinAccountOptions = {
|
|
|
11
11
|
idempotencyKey?: string;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* The result of creating a Bitcoin HD account.
|
|
14
|
+
* The result of creating a Bitcoin HD account. The extended public key (xpub) is always present,
|
|
15
|
+
* since the create response includes it and the caller needs it to derive child addresses.
|
|
15
16
|
*/
|
|
16
|
-
export type CreateBitcoinAccountResult = EndUserBtcAccount
|
|
17
|
+
export type CreateBitcoinAccountResult = EndUserBtcAccount & {
|
|
18
|
+
xpub: string;
|
|
19
|
+
};
|
|
17
20
|
/**
|
|
18
21
|
* Creates a Bitcoin HD (Hierarchical Deterministic) account for the current user.
|
|
19
22
|
* The account uses BIP-84 derivation (segwit) and returns an extended public key (xpub)
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { User } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for getting the current user.
|
|
4
|
+
*/
|
|
5
|
+
export type GetCurrentUserOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* When true, re-fetches the user from the API with each Bitcoin account's raw extended public
|
|
8
|
+
* key (xpub) included in `btcAccountObjects`. By default the xpubs are omitted (hash-only), so
|
|
9
|
+
* request this when you need to derive child addresses. Ignored if no user is signed in.
|
|
10
|
+
*/
|
|
11
|
+
includeBtcXpubs?: boolean;
|
|
12
|
+
};
|
|
2
13
|
/**
|
|
3
14
|
* Gets the currently signed-in user, if any.
|
|
4
15
|
*
|
|
5
16
|
* @example
|
|
6
17
|
* ```typescript lines
|
|
7
18
|
* const user = await getCurrentUser();
|
|
19
|
+
*
|
|
20
|
+
* // Include Bitcoin xpubs so addresses can be derived:
|
|
21
|
+
* const userWithXpubs = await getCurrentUser({ includeBtcXpubs: true });
|
|
8
22
|
* ```
|
|
23
|
+
* @param options - Optional settings controlling what is returned.
|
|
9
24
|
* @returns The currently signed-in user, or null if no user is signed in.
|
|
25
|
+
* @throws When `includeBtcXpubs` is true and the network request to re-fetch the user fails.
|
|
26
|
+
* The default (cached) read never throws.
|
|
10
27
|
*/
|
|
11
|
-
export declare const getCurrentUser: () => Promise<User | null>;
|
|
28
|
+
export declare const getCurrentUser: (options?: GetCurrentUserOptions) => Promise<User | null>;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SignBtcHashWithEndUserAccountBodyChange } from '@coinbase/cdp-api-client';
|
|
2
2
|
/**
|
|
3
3
|
* Options for signing a Bitcoin sighash.
|
|
4
4
|
*/
|
|
5
5
|
export type SignBitcoinHashOptions = {
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Selects which Bitcoin account to sign with, as the `xpubHash` from the account's entry in
|
|
8
|
+
* `btcAccountObjects`. Resolved server-side against the user's own accounts; an unmatched hash
|
|
9
|
+
* fails with a not-found error (there is no fallback to a default account).
|
|
10
|
+
*/
|
|
11
|
+
xpubHash: string;
|
|
10
12
|
/** BIP-32 change level: 0 for external (receive) addresses, 1 for internal (change) addresses. */
|
|
11
13
|
change: SignBtcHashWithEndUserAccountBodyChange;
|
|
12
14
|
/** BIP-32 address index — must match the index used to derive the address controlling the UTXO. */
|
|
@@ -9,7 +9,7 @@ export { verifyOAuth } from './actions/verifyOAuth.js';
|
|
|
9
9
|
export { verifySiweSignature, type VerifySiweSignatureOptions, type VerifySiweSignatureResult, } from './actions/verifySiweSignature.js';
|
|
10
10
|
export { verifyTelegramOAuth } from './actions/verifyTelegramOAuth.js';
|
|
11
11
|
export { authenticateWithJWT } from './actions/authenticateWithJWT.js';
|
|
12
|
-
export { getCurrentUser } from './actions/getCurrentUser.js';
|
|
12
|
+
export { getCurrentUser, type GetCurrentUserOptions } from './actions/getCurrentUser.js';
|
|
13
13
|
export { isSignedIn } from './actions/isSignedIn.js';
|
|
14
14
|
export { signOut } from './actions/signOut.js';
|
|
15
15
|
export { getAccessToken } from './actions/getAccessToken.js';
|
|
@@ -23,7 +23,7 @@ type MFAMethods,
|
|
|
23
23
|
type EndUserEvmAccount,
|
|
24
24
|
/** Solana account object with address and createdAt */
|
|
25
25
|
type EndUserSolanaAccount,
|
|
26
|
-
/** Bitcoin HD account object with
|
|
26
|
+
/** Bitcoin HD account object with xpubHash, network, addressType, and optional xpub */
|
|
27
27
|
type EndUserBtcAccount,
|
|
28
28
|
/** Bitcoin network for account creation */
|
|
29
29
|
type CreateEndUserBtcAccountBodyNetwork,
|
|
@@ -203,7 +203,7 @@ export type User = {
|
|
|
203
203
|
evmSmartAccountObjects?: EndUserEvmSmartAccount[];
|
|
204
204
|
/** The Solana account objects associated with the user. Users can have up to 10 Solana accounts. */
|
|
205
205
|
solanaAccountObjects?: EndUserSolanaAccount[];
|
|
206
|
-
/** The Bitcoin HD account objects associated with the user.
|
|
206
|
+
/** The Bitcoin HD account objects associated with the user. Up to 10 per user. */
|
|
207
207
|
btcAccountObjects?: EndUserBtcAccount[];
|
|
208
208
|
/** The MFA methods enrolled for the user. */
|
|
209
209
|
mfaMethods?: MFAMethods;
|
|
@@ -11,9 +11,12 @@ export type CreateBitcoinAccountOptions = {
|
|
|
11
11
|
idempotencyKey?: string;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* The result of creating a Bitcoin HD account.
|
|
14
|
+
* The result of creating a Bitcoin HD account. The extended public key (xpub) is always present,
|
|
15
|
+
* since the create response includes it and the caller needs it to derive child addresses.
|
|
15
16
|
*/
|
|
16
|
-
export type CreateBitcoinAccountResult = EndUserBtcAccount
|
|
17
|
+
export type CreateBitcoinAccountResult = EndUserBtcAccount & {
|
|
18
|
+
xpub: string;
|
|
19
|
+
};
|
|
17
20
|
/**
|
|
18
21
|
* Creates a Bitcoin HD (Hierarchical Deterministic) account for the current user.
|
|
19
22
|
* The account uses BIP-84 derivation (segwit) and returns an extended public key (xpub)
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { User } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for getting the current user.
|
|
4
|
+
*/
|
|
5
|
+
export type GetCurrentUserOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* When true, re-fetches the user from the API with each Bitcoin account's raw extended public
|
|
8
|
+
* key (xpub) included in `btcAccountObjects`. By default the xpubs are omitted (hash-only), so
|
|
9
|
+
* request this when you need to derive child addresses. Ignored if no user is signed in.
|
|
10
|
+
*/
|
|
11
|
+
includeBtcXpubs?: boolean;
|
|
12
|
+
};
|
|
2
13
|
/**
|
|
3
14
|
* Gets the currently signed-in user, if any.
|
|
4
15
|
*
|
|
5
16
|
* @example
|
|
6
17
|
* ```typescript lines
|
|
7
18
|
* const user = await getCurrentUser();
|
|
19
|
+
*
|
|
20
|
+
* // Include Bitcoin xpubs so addresses can be derived:
|
|
21
|
+
* const userWithXpubs = await getCurrentUser({ includeBtcXpubs: true });
|
|
8
22
|
* ```
|
|
23
|
+
* @param options - Optional settings controlling what is returned.
|
|
9
24
|
* @returns The currently signed-in user, or null if no user is signed in.
|
|
25
|
+
* @throws When `includeBtcXpubs` is true and the network request to re-fetch the user fails.
|
|
26
|
+
* The default (cached) read never throws.
|
|
10
27
|
*/
|
|
11
|
-
export declare const getCurrentUser: () => Promise<User | null>;
|
|
28
|
+
export declare const getCurrentUser: (options?: GetCurrentUserOptions) => Promise<User | null>;
|