@dynamic-labs-wallet/core 0.0.9 → 0.0.10

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/index.cjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/index.cjs.js ADDED
@@ -0,0 +1,252 @@
1
+ 'use strict';
2
+
3
+ var axios = require('axios');
4
+
5
+ const DYNAMIC_AUTH_PROD_BASE_API_URL = 'https://app.dynamicauth.com';
6
+ const DYNAMIC_AUTH_PREPROD_BASE_API_URL = 'https://app.dynamic-preprod.xyz';
7
+ const DYNAMIC_CLIENT_RELAY_PROD_BASE_API_URL = 'https://app-dynamicauth-com-app-6e12fc400995.relay.evervault.app';
8
+ const DYNAMIC_CLIENT_RELAY_PREPROD_BASE_API_URL = 'https://app-dynamic-preprod-xyz-app-32d15525a875.relay.evervault.app';
9
+ const MPC_RELAY_PROD_API_URL = 'mpc-relay.dynamic-prod.xyz';
10
+ const MPC_RELAY_PREPROD_API_URL = 'relay.dynamic-preprod.xyz';
11
+
12
+ var SigningAlgorithm = /*#__PURE__*/ function(SigningAlgorithm) {
13
+ SigningAlgorithm["ECDSA"] = "ECDSA";
14
+ SigningAlgorithm["ED25519"] = "ED25519";
15
+ SigningAlgorithm["BIP340"] = "BIP340";
16
+ return SigningAlgorithm;
17
+ }({});
18
+ const BITCOIN_DERIVATION_PATHS = {
19
+ LEGACY: [
20
+ 44,
21
+ 0,
22
+ 0,
23
+ 0,
24
+ 0
25
+ ],
26
+ // m/49'/0'/0'/0/0 - SegWit (P2SH-P2WPKH)
27
+ NATIVE_SEGWIT: [
28
+ 84,
29
+ 0,
30
+ 0,
31
+ 0,
32
+ 0
33
+ ],
34
+ // m/44'/0'/0'/0/0 - Legacy (P2PKH)
35
+ SEGWIT: [
36
+ 49,
37
+ 0,
38
+ 0,
39
+ 0,
40
+ 0
41
+ ]
42
+ };
43
+ const MPC_CHAIN_CONFIG = {
44
+ EVM: {
45
+ // Uses secp256k1 ECDSA
46
+ derivationPath: [
47
+ 44,
48
+ 60,
49
+ 0,
50
+ 0,
51
+ 0
52
+ ],
53
+ signingAlgorithm: "ECDSA"
54
+ },
55
+ SOL: {
56
+ // Uses Ed25519
57
+ derivationPath: [
58
+ 44,
59
+ 501,
60
+ 0,
61
+ 0,
62
+ 0
63
+ ],
64
+ signingAlgorithm: "ED25519"
65
+ },
66
+ BTC: {
67
+ // Uses secp256k1 BIP340
68
+ derivationPath: BITCOIN_DERIVATION_PATHS.NATIVE_SEGWIT,
69
+ signingAlgorithm: "BIP340"
70
+ },
71
+ COSMOS: {
72
+ // Uses Ed25519
73
+ derivationPath: [
74
+ 44,
75
+ 118,
76
+ 0,
77
+ 0,
78
+ 0
79
+ ],
80
+ signingAlgorithm: "ED25519"
81
+ },
82
+ FLOW: {
83
+ // Uses Ed25519
84
+ derivationPath: [
85
+ 44,
86
+ 539,
87
+ 0,
88
+ 0,
89
+ 0
90
+ ],
91
+ signingAlgorithm: "ED25519"
92
+ }
93
+ };
94
+ const getMPCChainConfig = (chainName)=>{
95
+ const chainConfig = MPC_CHAIN_CONFIG[chainName];
96
+ if (!chainConfig) {
97
+ throw new Error(`Chain ${chainName} not supported`);
98
+ }
99
+ return chainConfig;
100
+ };
101
+ var ThresholdSignatureScheme = /*#__PURE__*/ function(ThresholdSignatureScheme) {
102
+ ThresholdSignatureScheme["TWO_OF_TWO"] = "TWO_OF_TWO";
103
+ ThresholdSignatureScheme["TWO_OF_THREE"] = "TWO_OF_THREE";
104
+ ThresholdSignatureScheme["THREE_OF_FIVE"] = "THREE_OF_FIVE";
105
+ return ThresholdSignatureScheme;
106
+ }({});
107
+ const MPC_CONFIG = {
108
+ ["TWO_OF_TWO"]: {
109
+ numberOfParties: 2,
110
+ threshold: 2,
111
+ clientThreshold: 1,
112
+ dynamicServerThreshold: 1
113
+ },
114
+ ["TWO_OF_THREE"]: {
115
+ numberOfParties: 3,
116
+ threshold: 2,
117
+ clientThreshold: 2,
118
+ dynamicServerThreshold: 1
119
+ },
120
+ ["THREE_OF_FIVE"]: {
121
+ numberOfParties: 5,
122
+ threshold: 3,
123
+ clientThreshold: 3,
124
+ dynamicServerThreshold: 2
125
+ }
126
+ };
127
+ const getTSSConfig = (thresholdSignatureScheme)=>{
128
+ const { threshold, numberOfParties } = MPC_CONFIG[thresholdSignatureScheme];
129
+ return {
130
+ threshold,
131
+ numberOfParties
132
+ };
133
+ };
134
+ const getClientThreshold = (thresholdSignatureScheme)=>{
135
+ return MPC_CONFIG[thresholdSignatureScheme].clientThreshold;
136
+ };
137
+ const getDynamicServerThreshold = (thresholdSignatureScheme)=>{
138
+ return MPC_CONFIG[thresholdSignatureScheme].dynamicServerThreshold;
139
+ };
140
+
141
+ class BaseClient {
142
+ constructor({ environmentId, baseApiUrl, authToken, baseClientRelayApiUrl }){
143
+ const headers = {};
144
+ headers['Authorization'] = authToken ? `Bearer ${authToken}` : undefined;
145
+ this.environmentId = environmentId;
146
+ const isProd = typeof baseApiUrl === 'undefined' || DYNAMIC_AUTH_PROD_BASE_API_URL === baseApiUrl;
147
+ this.baseApiUrl = isProd ? DYNAMIC_AUTH_PROD_BASE_API_URL : baseApiUrl || DYNAMIC_AUTH_PREPROD_BASE_API_URL;
148
+ this.apiClient = axios.create({
149
+ baseURL: this.baseApiUrl,
150
+ headers
151
+ });
152
+ this.clientRelayBaseApiUrl = isProd ? DYNAMIC_CLIENT_RELAY_PROD_BASE_API_URL : baseClientRelayApiUrl || DYNAMIC_CLIENT_RELAY_PREPROD_BASE_API_URL;
153
+ this.clientRelayApiClient = axios.create({
154
+ baseURL: this.clientRelayBaseApiUrl,
155
+ headers
156
+ });
157
+ }
158
+ }
159
+
160
+ class DynamicApiClient extends BaseClient {
161
+ async createWalletAccount({ chainName, clientKeygenIds, thresholdSignatureScheme }) {
162
+ // Initilize keygen, create room, and create the wallet account on the server
163
+ const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/create`, {
164
+ chain: chainName,
165
+ clientKeygenIds,
166
+ thresholdSignatureScheme
167
+ });
168
+ return data;
169
+ }
170
+ async signMessage({ walletId, message }) {
171
+ const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/signMessage`, {
172
+ message
173
+ });
174
+ return data;
175
+ }
176
+ async refreshWalletAccountShares({ walletId }) {
177
+ const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/refresh`);
178
+ return data;
179
+ }
180
+ async reshareRemainingParty({ walletId, clientKeygenIds }) {
181
+ const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/reshare`, {
182
+ clientKeygenIds
183
+ });
184
+ return data;
185
+ }
186
+ async exportKey({ walletId, exportId }) {
187
+ const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/privateKey/export`, {
188
+ exportId
189
+ });
190
+ return data;
191
+ }
192
+ async storeEncryptedBackupByWallet({ walletId, encryptedKeyShares, passwordEncrypted }) {
193
+ const { data } = await this.clientRelayApiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/backup`, {
194
+ // TODO: decide on whether to store encryptedAccountCredentials or encryptedKeyShares as backup
195
+ encryptedAccountCredentials: encryptedKeyShares,
196
+ passwordEncrypted
197
+ });
198
+ return data;
199
+ }
200
+ async recoverEncryptedBackupByWallet({ walletId, keyShareIds }) {
201
+ const { data } = await this.clientRelayApiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/recover`, keyShareIds ? {
202
+ keyShareIds
203
+ } : undefined);
204
+ return data;
205
+ }
206
+ async getAccessToken({ oauthAccountId }) {
207
+ const { data } = await this.apiClient.get(`/api/v0/sdk/${this.environmentId}/oauthAccounts/${oauthAccountId}/accessToken`);
208
+ console.log('data', data);
209
+ return data.accessToken;
210
+ }
211
+ // TODO: return array instead considering cases where server has multiple parties
212
+ async importPrivateKey({ chainName, clientKeygenIds, thresholdSignatureScheme }) {
213
+ const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/privateKey/import`, {
214
+ chain: chainName,
215
+ clientKeygenIds,
216
+ thresholdSignatureScheme
217
+ });
218
+ return data;
219
+ }
220
+ async getUser() {
221
+ const { data } = await this.apiClient.get(`/api/v0/sdk/${this.environmentId}/users`);
222
+ return data;
223
+ }
224
+ async refreshUser() {
225
+ const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/refresh`, undefined);
226
+ return data;
227
+ }
228
+ constructor({ environmentId, authToken, baseApiUrl }){
229
+ super({
230
+ environmentId,
231
+ authToken,
232
+ baseApiUrl
233
+ });
234
+ }
235
+ }
236
+
237
+ exports.BITCOIN_DERIVATION_PATHS = BITCOIN_DERIVATION_PATHS;
238
+ exports.DYNAMIC_AUTH_PREPROD_BASE_API_URL = DYNAMIC_AUTH_PREPROD_BASE_API_URL;
239
+ exports.DYNAMIC_AUTH_PROD_BASE_API_URL = DYNAMIC_AUTH_PROD_BASE_API_URL;
240
+ exports.DYNAMIC_CLIENT_RELAY_PREPROD_BASE_API_URL = DYNAMIC_CLIENT_RELAY_PREPROD_BASE_API_URL;
241
+ exports.DYNAMIC_CLIENT_RELAY_PROD_BASE_API_URL = DYNAMIC_CLIENT_RELAY_PROD_BASE_API_URL;
242
+ exports.DynamicApiClient = DynamicApiClient;
243
+ exports.MPC_CHAIN_CONFIG = MPC_CHAIN_CONFIG;
244
+ exports.MPC_CONFIG = MPC_CONFIG;
245
+ exports.MPC_RELAY_PREPROD_API_URL = MPC_RELAY_PREPROD_API_URL;
246
+ exports.MPC_RELAY_PROD_API_URL = MPC_RELAY_PROD_API_URL;
247
+ exports.SigningAlgorithm = SigningAlgorithm;
248
+ exports.ThresholdSignatureScheme = ThresholdSignatureScheme;
249
+ exports.getClientThreshold = getClientThreshold;
250
+ exports.getDynamicServerThreshold = getDynamicServerThreshold;
251
+ exports.getMPCChainConfig = getMPCChainConfig;
252
+ exports.getTSSConfig = getTSSConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/core",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "dependencies": {
5
5
  "axios": "1.7.9"
6
6
  },
@@ -12,7 +12,8 @@
12
12
  "projectType": "library",
13
13
  "name": "core"
14
14
  },
15
- "main": "./index.esm.js",
15
+ "type": "module",
16
+ "main": "./index.cjs.js",
16
17
  "module": "./index.esm.js",
17
18
  "types": "./index.esm.d.ts",
18
19
  "exports": {
@@ -20,8 +21,8 @@
20
21
  ".": {
21
22
  "types": "./index.esm.d.ts",
22
23
  "import": "./index.esm.js",
23
- "default": "./index.esm.js"
24
+ "require": "./index.cjs.js",
25
+ "default": "./index.cjs.js"
24
26
  }
25
- },
26
- "type": "module"
27
+ }
27
28
  }