@dynamic-labs-wallet/sui 0.0.95 → 0.0.97
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 +29 -17
- package/index.esm.js +29 -17
- package/package.json +2 -2
- package/src/client/client.d.ts +10 -8
- package/src/client/client.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -224,11 +224,15 @@ class DynamicSuiWalletClient extends browser.DynamicWalletClient {
|
|
|
224
224
|
* The output is compatible with RFC8032 Ed25519 private key format.
|
|
225
225
|
*
|
|
226
226
|
* @param suiPrivateKey - The Sui private key in Bech32 format starting with "suiprivkey1"
|
|
227
|
-
* @returns
|
|
227
|
+
* @returns An object containing the private key and the private key bytes
|
|
228
228
|
* @throws Error if the input is not a valid Sui private key format
|
|
229
|
-
*/
|
|
229
|
+
*/ convertSuiPrivateKey(suiPrivateKey) {
|
|
230
230
|
if (!suiPrivateKey.startsWith('suiprivkey1')) {
|
|
231
|
-
|
|
231
|
+
this.logger.debug('Sui private key not in Bech32 format');
|
|
232
|
+
return {
|
|
233
|
+
privateKey: suiPrivateKey,
|
|
234
|
+
privateKeyBytes: Buffer.from(suiPrivateKey, 'hex')
|
|
235
|
+
};
|
|
232
236
|
}
|
|
233
237
|
try {
|
|
234
238
|
const suiConverter = converter('suiprivkey');
|
|
@@ -240,7 +244,10 @@ class DynamicSuiWalletClient extends browser.DynamicWalletClient {
|
|
|
240
244
|
if (cleanHex.length !== 64) {
|
|
241
245
|
throw new Error(`Invalid output: Expected 64 characters, got ${cleanHex.length}`);
|
|
242
246
|
}
|
|
243
|
-
return
|
|
247
|
+
return {
|
|
248
|
+
privateKey: cleanHex.toLowerCase(),
|
|
249
|
+
privateKeyBytes: Buffer.from(cleanHex, 'hex')
|
|
250
|
+
};
|
|
244
251
|
} catch (error) {
|
|
245
252
|
if (error instanceof Error) {
|
|
246
253
|
throw new Error(`Failed to convert Sui private key: ${error.message}`);
|
|
@@ -250,19 +257,23 @@ class DynamicSuiWalletClient extends browser.DynamicWalletClient {
|
|
|
250
257
|
}
|
|
251
258
|
/**
|
|
252
259
|
* Gets the public key for a given private key
|
|
253
|
-
*
|
|
254
|
-
* @
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
260
|
+
* @param privateKeyBytes A Buffer containing the Ed25519 private key bytes
|
|
261
|
+
* @returns The public key (Sui address) derived from the private key
|
|
262
|
+
*/ getPublicKeyFromPrivateKey(privateKeyBytes) {
|
|
263
|
+
try {
|
|
264
|
+
const keypair = ed25519.Ed25519Keypair.fromSecretKey(privateKeyBytes);
|
|
265
|
+
const publicKey = keypair.getPublicKey();
|
|
266
|
+
const publicKeyBase58 = publicKey.toSuiAddress();
|
|
267
|
+
return publicKeyBase58;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
this.logger.error('Unable to derive public key from private key. Check private key format', error instanceof Error ? error.message : 'Unknown error');
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
261
272
|
}
|
|
262
273
|
/**
|
|
263
274
|
* Imports the private key for a given account address
|
|
264
275
|
*
|
|
265
|
-
* @param privateKey The private key to import
|
|
276
|
+
* @param privateKey The private key to import, accepts both Bech32 and hex formats
|
|
266
277
|
* @param chainName The chain name to import the private key for
|
|
267
278
|
* @param thresholdSignatureScheme The threshold signature scheme to use
|
|
268
279
|
* @param password The password for encrypted backup shares
|
|
@@ -273,8 +284,8 @@ class DynamicSuiWalletClient extends browser.DynamicWalletClient {
|
|
|
273
284
|
const ceremonyCompletePromise = new Promise((resolve)=>{
|
|
274
285
|
ceremonyCeremonyCompleteResolver = resolve;
|
|
275
286
|
});
|
|
276
|
-
const
|
|
277
|
-
const
|
|
287
|
+
const { privateKey: formattedPrivateKey, privateKeyBytes } = await this.convertSuiPrivateKey(privateKey);
|
|
288
|
+
const publicKey = this.getPublicKeyFromPrivateKey(privateKeyBytes);
|
|
278
289
|
const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
|
|
279
290
|
chainName,
|
|
280
291
|
privateKey: formattedPrivateKey,
|
|
@@ -341,7 +352,7 @@ class DynamicSuiWalletClient extends browser.DynamicWalletClient {
|
|
|
341
352
|
*
|
|
342
353
|
* @param accountAddress The account address to export the private key for
|
|
343
354
|
* @param password The password for encrypted backup shares
|
|
344
|
-
* @returns The private key
|
|
355
|
+
* @returns The private key in hex format
|
|
345
356
|
*/ async exportPrivateKey({ accountAddress, password = undefined, signedSessionId }) {
|
|
346
357
|
try {
|
|
347
358
|
const { derivedPrivateKey } = await this.exportKey({
|
|
@@ -353,7 +364,8 @@ class DynamicSuiWalletClient extends browser.DynamicWalletClient {
|
|
|
353
364
|
if (!derivedPrivateKey) {
|
|
354
365
|
throw new Error('Derived private key is undefined');
|
|
355
366
|
}
|
|
356
|
-
|
|
367
|
+
const privateScalarHex = derivedPrivateKey.slice(0, 64);
|
|
368
|
+
return privateScalarHex;
|
|
357
369
|
} catch (error) {
|
|
358
370
|
this.logger.error(browser.ERROR_EXPORT_PRIVATE_KEY, error);
|
|
359
371
|
throw new Error(browser.ERROR_EXPORT_PRIVATE_KEY);
|
package/index.esm.js
CHANGED
|
@@ -222,11 +222,15 @@ class DynamicSuiWalletClient extends DynamicWalletClient {
|
|
|
222
222
|
* The output is compatible with RFC8032 Ed25519 private key format.
|
|
223
223
|
*
|
|
224
224
|
* @param suiPrivateKey - The Sui private key in Bech32 format starting with "suiprivkey1"
|
|
225
|
-
* @returns
|
|
225
|
+
* @returns An object containing the private key and the private key bytes
|
|
226
226
|
* @throws Error if the input is not a valid Sui private key format
|
|
227
|
-
*/
|
|
227
|
+
*/ convertSuiPrivateKey(suiPrivateKey) {
|
|
228
228
|
if (!suiPrivateKey.startsWith('suiprivkey1')) {
|
|
229
|
-
|
|
229
|
+
this.logger.debug('Sui private key not in Bech32 format');
|
|
230
|
+
return {
|
|
231
|
+
privateKey: suiPrivateKey,
|
|
232
|
+
privateKeyBytes: Buffer.from(suiPrivateKey, 'hex')
|
|
233
|
+
};
|
|
230
234
|
}
|
|
231
235
|
try {
|
|
232
236
|
const suiConverter = converter('suiprivkey');
|
|
@@ -238,7 +242,10 @@ class DynamicSuiWalletClient extends DynamicWalletClient {
|
|
|
238
242
|
if (cleanHex.length !== 64) {
|
|
239
243
|
throw new Error(`Invalid output: Expected 64 characters, got ${cleanHex.length}`);
|
|
240
244
|
}
|
|
241
|
-
return
|
|
245
|
+
return {
|
|
246
|
+
privateKey: cleanHex.toLowerCase(),
|
|
247
|
+
privateKeyBytes: Buffer.from(cleanHex, 'hex')
|
|
248
|
+
};
|
|
242
249
|
} catch (error) {
|
|
243
250
|
if (error instanceof Error) {
|
|
244
251
|
throw new Error(`Failed to convert Sui private key: ${error.message}`);
|
|
@@ -248,19 +255,23 @@ class DynamicSuiWalletClient extends DynamicWalletClient {
|
|
|
248
255
|
}
|
|
249
256
|
/**
|
|
250
257
|
* Gets the public key for a given private key
|
|
251
|
-
*
|
|
252
|
-
* @
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
258
|
+
* @param privateKeyBytes A Buffer containing the Ed25519 private key bytes
|
|
259
|
+
* @returns The public key (Sui address) derived from the private key
|
|
260
|
+
*/ getPublicKeyFromPrivateKey(privateKeyBytes) {
|
|
261
|
+
try {
|
|
262
|
+
const keypair = Ed25519Keypair.fromSecretKey(privateKeyBytes);
|
|
263
|
+
const publicKey = keypair.getPublicKey();
|
|
264
|
+
const publicKeyBase58 = publicKey.toSuiAddress();
|
|
265
|
+
return publicKeyBase58;
|
|
266
|
+
} catch (error) {
|
|
267
|
+
this.logger.error('Unable to derive public key from private key. Check private key format', error instanceof Error ? error.message : 'Unknown error');
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
259
270
|
}
|
|
260
271
|
/**
|
|
261
272
|
* Imports the private key for a given account address
|
|
262
273
|
*
|
|
263
|
-
* @param privateKey The private key to import
|
|
274
|
+
* @param privateKey The private key to import, accepts both Bech32 and hex formats
|
|
264
275
|
* @param chainName The chain name to import the private key for
|
|
265
276
|
* @param thresholdSignatureScheme The threshold signature scheme to use
|
|
266
277
|
* @param password The password for encrypted backup shares
|
|
@@ -271,8 +282,8 @@ class DynamicSuiWalletClient extends DynamicWalletClient {
|
|
|
271
282
|
const ceremonyCompletePromise = new Promise((resolve)=>{
|
|
272
283
|
ceremonyCeremonyCompleteResolver = resolve;
|
|
273
284
|
});
|
|
274
|
-
const
|
|
275
|
-
const
|
|
285
|
+
const { privateKey: formattedPrivateKey, privateKeyBytes } = await this.convertSuiPrivateKey(privateKey);
|
|
286
|
+
const publicKey = this.getPublicKeyFromPrivateKey(privateKeyBytes);
|
|
276
287
|
const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
|
|
277
288
|
chainName,
|
|
278
289
|
privateKey: formattedPrivateKey,
|
|
@@ -339,7 +350,7 @@ class DynamicSuiWalletClient extends DynamicWalletClient {
|
|
|
339
350
|
*
|
|
340
351
|
* @param accountAddress The account address to export the private key for
|
|
341
352
|
* @param password The password for encrypted backup shares
|
|
342
|
-
* @returns The private key
|
|
353
|
+
* @returns The private key in hex format
|
|
343
354
|
*/ async exportPrivateKey({ accountAddress, password = undefined, signedSessionId }) {
|
|
344
355
|
try {
|
|
345
356
|
const { derivedPrivateKey } = await this.exportKey({
|
|
@@ -351,7 +362,8 @@ class DynamicSuiWalletClient extends DynamicWalletClient {
|
|
|
351
362
|
if (!derivedPrivateKey) {
|
|
352
363
|
throw new Error('Derived private key is undefined');
|
|
353
364
|
}
|
|
354
|
-
|
|
365
|
+
const privateScalarHex = derivedPrivateKey.slice(0, 64);
|
|
366
|
+
return privateScalarHex;
|
|
355
367
|
} catch (error) {
|
|
356
368
|
this.logger.error(ERROR_EXPORT_PRIVATE_KEY, error);
|
|
357
369
|
throw new Error(ERROR_EXPORT_PRIVATE_KEY);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/sui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.97",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@dynamic-labs-wallet/browser": "0.0.
|
|
6
|
+
"@dynamic-labs-wallet/browser": "0.0.97",
|
|
7
7
|
"@mysten/sui": "1.26.0",
|
|
8
8
|
"@noble/hashes": "1.7.1",
|
|
9
9
|
"bech32-converting": "^1.0.9"
|
package/src/client/client.d.ts
CHANGED
|
@@ -45,21 +45,23 @@ export declare class DynamicSuiWalletClient extends DynamicWalletClient {
|
|
|
45
45
|
* The output is compatible with RFC8032 Ed25519 private key format.
|
|
46
46
|
*
|
|
47
47
|
* @param suiPrivateKey - The Sui private key in Bech32 format starting with "suiprivkey1"
|
|
48
|
-
* @returns
|
|
48
|
+
* @returns An object containing the private key and the private key bytes
|
|
49
49
|
* @throws Error if the input is not a valid Sui private key format
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
convertSuiPrivateKey(suiPrivateKey: string): {
|
|
52
|
+
privateKey: string;
|
|
53
|
+
privateKeyBytes: Buffer;
|
|
54
|
+
};
|
|
52
55
|
/**
|
|
53
56
|
* Gets the public key for a given private key
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
56
|
-
* @returns The public key for the given private key
|
|
57
|
+
* @param privateKeyBytes A Buffer containing the Ed25519 private key bytes
|
|
58
|
+
* @returns The public key (Sui address) derived from the private key
|
|
57
59
|
*/
|
|
58
|
-
getPublicKeyFromPrivateKey(
|
|
60
|
+
getPublicKeyFromPrivateKey(privateKeyBytes: Buffer): string;
|
|
59
61
|
/**
|
|
60
62
|
* Imports the private key for a given account address
|
|
61
63
|
*
|
|
62
|
-
* @param privateKey The private key to import
|
|
64
|
+
* @param privateKey The private key to import, accepts both Bech32 and hex formats
|
|
63
65
|
* @param chainName The chain name to import the private key for
|
|
64
66
|
* @param thresholdSignatureScheme The threshold signature scheme to use
|
|
65
67
|
* @param password The password for encrypted backup shares
|
|
@@ -82,7 +84,7 @@ export declare class DynamicSuiWalletClient extends DynamicWalletClient {
|
|
|
82
84
|
*
|
|
83
85
|
* @param accountAddress The account address to export the private key for
|
|
84
86
|
* @param password The password for encrypted backup shares
|
|
85
|
-
* @returns The private key
|
|
87
|
+
* @returns The private key in hex format
|
|
86
88
|
*/
|
|
87
89
|
exportPrivateKey({ accountAddress, password, signedSessionId, }: {
|
|
88
90
|
accountAddress: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EAWzB,MAAM,8BAA8B,CAAC;AAWtC,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CAAC,SAAS,SAAS;gBAEf,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,KAAK,GACN,EAAE,wBAAwB;IAWrB,mBAAmB,CAAC,EACxB,wBAAwB,EACxB,QAAoB,EACpB,OAAO,EACP,eAAe,GAChB,EAAE;QACD,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;QACjC,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;KAClC,CAAC;IAsEI,kCAAkC,CAAC,EACvC,SAAS,EACT,cAAc,GACf,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,cAAc,EAAE,cAAc,CAAC;KAChC;IAYD;;OAEG;YACW,eAAe;YAoCf,sBAAsB;YA6BtB,0BAA0B;IA6BlC,W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