@dynamic-labs-wallet/evm 0.0.101 → 0.0.103
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.js +58 -19
- package/index.esm.js +60 -21
- package/package.json +2 -2
- package/src/client/client.d.ts +8 -2
- package/src/client/client.d.ts.map +1 -1
- package/src/utils.d.ts +6 -2
- package/src/utils.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -17,24 +17,37 @@ function _extends() {
|
|
|
17
17
|
|
|
18
18
|
const EVM_SIGN_MESSAGE_PREFIX = `\x19Ethereum Signed Message:\n`;
|
|
19
19
|
|
|
20
|
-
const formatEVMMessage = (message_)=>{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
const formatEVMMessage = (message_, logger)=>{
|
|
21
|
+
try {
|
|
22
|
+
const message = (()=>{
|
|
23
|
+
if (typeof message_ === 'string') return viem.stringToHex(message_);
|
|
24
|
+
if (typeof message_.raw === 'string') return message_.raw;
|
|
25
|
+
return viem.bytesToHex(message_.raw);
|
|
26
|
+
})();
|
|
27
|
+
const prefix = viem.stringToHex(`${EVM_SIGN_MESSAGE_PREFIX}${viem.size(message)}`);
|
|
28
|
+
return viem.concat([
|
|
29
|
+
prefix,
|
|
30
|
+
message
|
|
31
|
+
]);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
logger.error('[DynamicWaasWalletClient]: Error formatting EVM message:', error);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const formatTypedData = (typedData)=>{
|
|
38
|
+
return viem.hashTypedData(typedData);
|
|
31
39
|
};
|
|
32
|
-
const serializeECDSASignature = (signature)=>{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
const serializeECDSASignature = (signature, logger)=>{
|
|
41
|
+
try {
|
|
42
|
+
return viem.serializeSignature({
|
|
43
|
+
r: `0x${Buffer.from(signature.r).toString('hex')}`,
|
|
44
|
+
s: `0x${Buffer.from(signature.s).toString('hex')}`,
|
|
45
|
+
v: BigInt(signature.v)
|
|
46
|
+
});
|
|
47
|
+
} catch (error) {
|
|
48
|
+
logger.error('[DynamicWaasWalletClient]: Error serializing ECDSA signature:', error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
38
51
|
};
|
|
39
52
|
|
|
40
53
|
const checkRawPublicKeyInstance = (rawPublicKey)=>{
|
|
@@ -129,7 +142,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
129
142
|
throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
130
143
|
}
|
|
131
144
|
// Format the message for EVM signing
|
|
132
|
-
const formattedMessage = formatEVMMessage(message);
|
|
145
|
+
const formattedMessage = formatEVMMessage(message, this.logger);
|
|
133
146
|
// Sign the message using MPC
|
|
134
147
|
const signatureEcdsa = await this.sign({
|
|
135
148
|
message: formattedMessage,
|
|
@@ -139,7 +152,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
139
152
|
signedSessionId
|
|
140
153
|
});
|
|
141
154
|
// Serialize the signature
|
|
142
|
-
const serializedSignature = serializeECDSASignature(signatureEcdsa);
|
|
155
|
+
const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
|
|
143
156
|
return serializedSignature;
|
|
144
157
|
} catch (error) {
|
|
145
158
|
this.logger.error(browser.ERROR_SIGN_MESSAGE, error);
|
|
@@ -202,6 +215,32 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
202
215
|
throw error;
|
|
203
216
|
}
|
|
204
217
|
}
|
|
218
|
+
async signTypedData({ accountAddress, typedData, password = undefined, signedSessionId }) {
|
|
219
|
+
await this.verifyPassword({
|
|
220
|
+
accountAddress,
|
|
221
|
+
password,
|
|
222
|
+
walletOperation: browser.WalletOperation.SIGN_MESSAGE,
|
|
223
|
+
signedSessionId
|
|
224
|
+
});
|
|
225
|
+
try {
|
|
226
|
+
if (!accountAddress) {
|
|
227
|
+
throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
228
|
+
}
|
|
229
|
+
const formattedTypedData = formatTypedData(typedData);
|
|
230
|
+
const signatureEcdsa = await this.sign({
|
|
231
|
+
message: formattedTypedData,
|
|
232
|
+
accountAddress: accountAddress,
|
|
233
|
+
chainName: this.chainName,
|
|
234
|
+
password,
|
|
235
|
+
signedSessionId
|
|
236
|
+
});
|
|
237
|
+
const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
|
|
238
|
+
return serializedSignature;
|
|
239
|
+
} catch (error) {
|
|
240
|
+
this.logger.error(browser.ERROR_SIGN_TYPED_DATA, error);
|
|
241
|
+
throw new Error(browser.ERROR_SIGN_TYPED_DATA);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
205
244
|
deriveAccountAddress({ rawPublicKey }) {
|
|
206
245
|
const serializedUncompressed = rawPublicKey.serializeUncompressed();
|
|
207
246
|
const firstByteRemoved = serializedUncompressed.slice(1);
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EcdsaPublicKey, DynamicWalletClient, getClientKeyShareBackupInfo, ERROR_CREATE_WALLET_ACCOUNT, ERROR_KEYGEN_FAILED, WalletOperation, ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_SIGN_MESSAGE, ERROR_VERIFY_MESSAGE_SIGNATURE, MessageHash, ERROR_IMPORT_PRIVATE_KEY } from '@dynamic-labs-wallet/browser';
|
|
2
|
-
import { stringToHex, bytesToHex, size, concat, serializeSignature, createPublicClient, http, getAddress, serializeTransaction } from 'viem';
|
|
1
|
+
import { EcdsaPublicKey, DynamicWalletClient, getClientKeyShareBackupInfo, ERROR_CREATE_WALLET_ACCOUNT, ERROR_KEYGEN_FAILED, WalletOperation, ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_SIGN_MESSAGE, ERROR_VERIFY_MESSAGE_SIGNATURE, ERROR_SIGN_TYPED_DATA, MessageHash, ERROR_IMPORT_PRIVATE_KEY } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
import { stringToHex, bytesToHex, size, concat, serializeSignature, hashTypedData, createPublicClient, http, getAddress, serializeTransaction } from 'viem';
|
|
3
3
|
import { mainnet } from 'viem/chains';
|
|
4
4
|
|
|
5
5
|
function _extends() {
|
|
@@ -15,24 +15,37 @@ function _extends() {
|
|
|
15
15
|
|
|
16
16
|
const EVM_SIGN_MESSAGE_PREFIX = `\x19Ethereum Signed Message:\n`;
|
|
17
17
|
|
|
18
|
-
const formatEVMMessage = (message_)=>{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
const formatEVMMessage = (message_, logger)=>{
|
|
19
|
+
try {
|
|
20
|
+
const message = (()=>{
|
|
21
|
+
if (typeof message_ === 'string') return stringToHex(message_);
|
|
22
|
+
if (typeof message_.raw === 'string') return message_.raw;
|
|
23
|
+
return bytesToHex(message_.raw);
|
|
24
|
+
})();
|
|
25
|
+
const prefix = stringToHex(`${EVM_SIGN_MESSAGE_PREFIX}${size(message)}`);
|
|
26
|
+
return concat([
|
|
27
|
+
prefix,
|
|
28
|
+
message
|
|
29
|
+
]);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
logger.error('[DynamicWaasWalletClient]: Error formatting EVM message:', error);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const formatTypedData = (typedData)=>{
|
|
36
|
+
return hashTypedData(typedData);
|
|
29
37
|
};
|
|
30
|
-
const serializeECDSASignature = (signature)=>{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
const serializeECDSASignature = (signature, logger)=>{
|
|
39
|
+
try {
|
|
40
|
+
return serializeSignature({
|
|
41
|
+
r: `0x${Buffer.from(signature.r).toString('hex')}`,
|
|
42
|
+
s: `0x${Buffer.from(signature.s).toString('hex')}`,
|
|
43
|
+
v: BigInt(signature.v)
|
|
44
|
+
});
|
|
45
|
+
} catch (error) {
|
|
46
|
+
logger.error('[DynamicWaasWalletClient]: Error serializing ECDSA signature:', error);
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
36
49
|
};
|
|
37
50
|
|
|
38
51
|
const checkRawPublicKeyInstance = (rawPublicKey)=>{
|
|
@@ -127,7 +140,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
127
140
|
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
128
141
|
}
|
|
129
142
|
// Format the message for EVM signing
|
|
130
|
-
const formattedMessage = formatEVMMessage(message);
|
|
143
|
+
const formattedMessage = formatEVMMessage(message, this.logger);
|
|
131
144
|
// Sign the message using MPC
|
|
132
145
|
const signatureEcdsa = await this.sign({
|
|
133
146
|
message: formattedMessage,
|
|
@@ -137,7 +150,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
137
150
|
signedSessionId
|
|
138
151
|
});
|
|
139
152
|
// Serialize the signature
|
|
140
|
-
const serializedSignature = serializeECDSASignature(signatureEcdsa);
|
|
153
|
+
const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
|
|
141
154
|
return serializedSignature;
|
|
142
155
|
} catch (error) {
|
|
143
156
|
this.logger.error(ERROR_SIGN_MESSAGE, error);
|
|
@@ -200,6 +213,32 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
200
213
|
throw error;
|
|
201
214
|
}
|
|
202
215
|
}
|
|
216
|
+
async signTypedData({ accountAddress, typedData, password = undefined, signedSessionId }) {
|
|
217
|
+
await this.verifyPassword({
|
|
218
|
+
accountAddress,
|
|
219
|
+
password,
|
|
220
|
+
walletOperation: WalletOperation.SIGN_MESSAGE,
|
|
221
|
+
signedSessionId
|
|
222
|
+
});
|
|
223
|
+
try {
|
|
224
|
+
if (!accountAddress) {
|
|
225
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
226
|
+
}
|
|
227
|
+
const formattedTypedData = formatTypedData(typedData);
|
|
228
|
+
const signatureEcdsa = await this.sign({
|
|
229
|
+
message: formattedTypedData,
|
|
230
|
+
accountAddress: accountAddress,
|
|
231
|
+
chainName: this.chainName,
|
|
232
|
+
password,
|
|
233
|
+
signedSessionId
|
|
234
|
+
});
|
|
235
|
+
const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
|
|
236
|
+
return serializedSignature;
|
|
237
|
+
} catch (error) {
|
|
238
|
+
this.logger.error(ERROR_SIGN_TYPED_DATA, error);
|
|
239
|
+
throw new Error(ERROR_SIGN_TYPED_DATA);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
203
242
|
deriveAccountAddress({ rawPublicKey }) {
|
|
204
243
|
const serializedUncompressed = rawPublicKey.serializeUncompressed();
|
|
205
244
|
const firstByteRemoved = serializedUncompressed.slice(1);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/evm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.103",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@dynamic-labs-wallet/browser": "0.0.
|
|
6
|
+
"@dynamic-labs-wallet/browser": "0.0.103"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
9
|
"viem": "^2.22.1"
|
package/src/client/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DynamicWalletClient, EcdsaKeygenResult, EcdsaPublicKey, Ed25519KeygenResult, ThresholdSignatureScheme
|
|
2
|
-
import { type
|
|
1
|
+
import { DynamicWalletClient, DynamicWalletClientProps, EcdsaKeygenResult, EcdsaPublicKey, Ed25519KeygenResult, ThresholdSignatureScheme } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
import { type Chain, type PublicClient, type SignableMessage, type TransactionSerializable, type TypedData } from 'viem';
|
|
3
3
|
export declare class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
4
4
|
readonly chainName = "EVM";
|
|
5
5
|
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, }: DynamicWalletClientProps);
|
|
@@ -34,6 +34,12 @@ export declare class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
34
34
|
password?: string;
|
|
35
35
|
signedSessionId?: string;
|
|
36
36
|
}): Promise<string>;
|
|
37
|
+
signTypedData({ accountAddress, typedData, password, signedSessionId, }: {
|
|
38
|
+
accountAddress: string;
|
|
39
|
+
typedData: TypedData;
|
|
40
|
+
password?: string;
|
|
41
|
+
signedSessionId?: string;
|
|
42
|
+
}): Promise<`0x${string}`>;
|
|
37
43
|
deriveAccountAddress({ rawPublicKey }: {
|
|
38
44
|
rawPublicKey: EcdsaPublicKey;
|
|
39
45
|
}): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EAEd,mBAAmB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EACjB,cAAc,EAEd,mBAAmB,EAUnB,wBAAwB,EAEzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,KAAK,EAIV,KAAK,YAAY,EAEjB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AASd,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CA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SAAS,CAAC;KAChE,CAAC;IA+EI,aAAa;CAOpB"}
|
package/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type { EcdsaSignature } from '@dynamic-labs-wallet/browser';
|
|
1
|
+
import type { EcdsaSignature, Logger } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
import type { TypedData } from 'viem';
|
|
2
3
|
export declare const formatEVMMessage: (message_: string | {
|
|
3
4
|
raw: string | Uint8Array;
|
|
5
|
+
}, logger: Logger) => `0x${string}`;
|
|
6
|
+
export declare const formatTypedData: (typedData: TypedData | {
|
|
7
|
+
[key: string]: unknown;
|
|
4
8
|
}) => `0x${string}`;
|
|
5
|
-
export declare const serializeECDSASignature: (signature: EcdsaSignature) => `0x${string}`;
|
|
9
|
+
export declare const serializeECDSASignature: (signature: EcdsaSignature, logger: Logger) => `0x${string}`;
|
|
6
10
|
//# sourceMappingURL=utils.d.ts.map
|
package/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,KAAK,EAA2B,SAAS,EAAE,MAAM,MAAM,CAAC;AAW/D,eAAO,MAAM,gBAAgB,aACjB,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,UACvC,MAAM,kBAmBf,CAAC;AAEF,eAAO,MAAM,eAAe,cACf,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,kBAGlD,CAAC;AAEF,eAAO,MAAM,uBAAuB,cACvB,cAAc,UACjB,MAAM,kBAef,CAAC"}
|