@dynamic-labs-wallet/ton 1.0.91 → 1.0.93
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 +22 -5
- package/index.esm.js +23 -6
- package/package.json +2 -2
- package/src/client/client.d.ts +11 -2
- package/src/client/client.d.ts.map +1 -1
package/index.cjs
CHANGED
|
@@ -613,7 +613,7 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
613
613
|
{
|
|
614
614
|
key: "importPrivateKey",
|
|
615
615
|
value: function importPrivateKey(param) {
|
|
616
|
-
var privateKey = param.privateKey, chainName = param.chainName, thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, onError = param.onError, publicAddressCheck = param.publicAddressCheck, legacyWalletId = param.legacyWalletId;
|
|
616
|
+
var privateKey = param.privateKey, chainName = param.chainName, thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, onError = param.onError, publicAddressCheck = param.publicAddressCheck, legacyWalletId = param.legacyWalletId, isRawScalarImport = param.isRawScalarImport;
|
|
617
617
|
var _this = this;
|
|
618
618
|
return _async_to_generator(function() {
|
|
619
619
|
var ceremonyCeremonyCompleteResolver, ceremonyCompletePromise, formattedPrivateKey, publicKeyHex, derivedAddress, _ref, rawPublicKey, clientKeyShares, accountAddress, pubKeyBytes, error;
|
|
@@ -630,7 +630,9 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
630
630
|
ceremonyCeremonyCompleteResolver = resolve;
|
|
631
631
|
});
|
|
632
632
|
formattedPrivateKey = privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey;
|
|
633
|
-
publicKeyHex = _this.getPublicKeyFromPrivateKey(formattedPrivateKey
|
|
633
|
+
publicKeyHex = isRawScalarImport ? _this.getPublicKeyFromPrivateKey(formattedPrivateKey, {
|
|
634
|
+
isRawScalar: true
|
|
635
|
+
}) : _this.getPublicKeyFromPrivateKey(formattedPrivateKey);
|
|
634
636
|
derivedAddress = deriveTonAddress({
|
|
635
637
|
publicKeyHex: publicKeyHex,
|
|
636
638
|
workchain: 0
|
|
@@ -644,13 +646,15 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
644
646
|
chainName: chainName,
|
|
645
647
|
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
646
648
|
privateKey: formattedPrivateKey,
|
|
649
|
+
isRawScalarImport: isRawScalarImport,
|
|
647
650
|
onCeremonyComplete: function(accountAddress, walletId, shareSetId) {
|
|
648
651
|
_this.initializeWalletMapEntry({
|
|
649
652
|
accountAddress: accountAddress,
|
|
650
653
|
walletId: walletId,
|
|
651
654
|
chainName: _this.chainName,
|
|
652
655
|
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
653
|
-
shareSetId: shareSetId
|
|
656
|
+
shareSetId: shareSetId,
|
|
657
|
+
variant: isRawScalarImport ? 'ed25519Standard' : undefined
|
|
654
658
|
});
|
|
655
659
|
ceremonyCeremonyCompleteResolver(undefined);
|
|
656
660
|
},
|
|
@@ -725,12 +729,25 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
725
729
|
},
|
|
726
730
|
{
|
|
727
731
|
key: "getPublicKeyFromPrivateKey",
|
|
728
|
-
value: function getPublicKeyFromPrivateKey(privateKeyHex) {
|
|
732
|
+
value: function getPublicKeyFromPrivateKey(privateKeyHex, opts) {
|
|
729
733
|
try {
|
|
730
|
-
var
|
|
734
|
+
var strippedKey = privateKeyHex.replace(/^0x/, '');
|
|
735
|
+
// Validate hex up front: Buffer.from(..., 'hex') silently drops invalid
|
|
736
|
+
// characters, which could otherwise yield a wrong buffer that still passes
|
|
737
|
+
// the length check below.
|
|
738
|
+
if (!/^[0-9a-fA-F]*$/.test(strippedKey)) {
|
|
739
|
+
throw new Error('Invalid private key: expected a hex string');
|
|
740
|
+
}
|
|
741
|
+
var privateKeyBytes = Buffer.from(strippedKey, 'hex');
|
|
731
742
|
if (privateKeyBytes.length !== 32) {
|
|
732
743
|
throw new Error("Invalid private key length: ".concat(privateKeyBytes.length, ", expected 32"));
|
|
733
744
|
}
|
|
745
|
+
if (opts === null || opts === void 0 ? void 0 : opts.isRawScalar) {
|
|
746
|
+
// Raw 32-byte ed25519 signing scalar (not a seed): derive A = s·B
|
|
747
|
+
// instead of seed-expanding via keyPairFromSeed.
|
|
748
|
+
var publicKeyBytes = browser.getEd25519PublicKeyFromRawScalar(new Uint8Array(privateKeyBytes));
|
|
749
|
+
return Buffer.from(publicKeyBytes).toString('hex');
|
|
750
|
+
}
|
|
734
751
|
var keyPair = crypto.keyPairFromSeed(privateKeyBytes);
|
|
735
752
|
return keyPair.publicKey.toString('hex');
|
|
736
753
|
} catch (error) {
|
package/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DynamicWalletClient, ERROR_PASSWORD_MISMATCH } from '@dynamic-labs-wallet/browser';
|
|
1
|
+
import { getEd25519PublicKeyFromRawScalar, DynamicWalletClient, ERROR_PASSWORD_MISMATCH } from '@dynamic-labs-wallet/browser';
|
|
2
2
|
import { keyPairFromSeed } from '@ton/crypto';
|
|
3
3
|
import { WalletContractV5R1 } from '@ton/ton';
|
|
4
4
|
import * as sdkApiCore from '@dynamic-labs/sdk-api-core';
|
|
@@ -593,7 +593,7 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
593
593
|
{
|
|
594
594
|
key: "importPrivateKey",
|
|
595
595
|
value: function importPrivateKey(param) {
|
|
596
|
-
var privateKey = param.privateKey, chainName = param.chainName, thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, onError = param.onError, publicAddressCheck = param.publicAddressCheck, legacyWalletId = param.legacyWalletId;
|
|
596
|
+
var privateKey = param.privateKey, chainName = param.chainName, thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, onError = param.onError, publicAddressCheck = param.publicAddressCheck, legacyWalletId = param.legacyWalletId, isRawScalarImport = param.isRawScalarImport;
|
|
597
597
|
var _this = this;
|
|
598
598
|
return _async_to_generator(function() {
|
|
599
599
|
var ceremonyCeremonyCompleteResolver, ceremonyCompletePromise, formattedPrivateKey, publicKeyHex, derivedAddress, _ref, rawPublicKey, clientKeyShares, accountAddress, pubKeyBytes, error;
|
|
@@ -610,7 +610,9 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
610
610
|
ceremonyCeremonyCompleteResolver = resolve;
|
|
611
611
|
});
|
|
612
612
|
formattedPrivateKey = privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey;
|
|
613
|
-
publicKeyHex = _this.getPublicKeyFromPrivateKey(formattedPrivateKey
|
|
613
|
+
publicKeyHex = isRawScalarImport ? _this.getPublicKeyFromPrivateKey(formattedPrivateKey, {
|
|
614
|
+
isRawScalar: true
|
|
615
|
+
}) : _this.getPublicKeyFromPrivateKey(formattedPrivateKey);
|
|
614
616
|
derivedAddress = deriveTonAddress({
|
|
615
617
|
publicKeyHex: publicKeyHex,
|
|
616
618
|
workchain: 0
|
|
@@ -624,13 +626,15 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
624
626
|
chainName: chainName,
|
|
625
627
|
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
626
628
|
privateKey: formattedPrivateKey,
|
|
629
|
+
isRawScalarImport: isRawScalarImport,
|
|
627
630
|
onCeremonyComplete: function(accountAddress, walletId, shareSetId) {
|
|
628
631
|
_this.initializeWalletMapEntry({
|
|
629
632
|
accountAddress: accountAddress,
|
|
630
633
|
walletId: walletId,
|
|
631
634
|
chainName: _this.chainName,
|
|
632
635
|
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
633
|
-
shareSetId: shareSetId
|
|
636
|
+
shareSetId: shareSetId,
|
|
637
|
+
variant: isRawScalarImport ? 'ed25519Standard' : undefined
|
|
634
638
|
});
|
|
635
639
|
ceremonyCeremonyCompleteResolver(undefined);
|
|
636
640
|
},
|
|
@@ -705,12 +709,25 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
705
709
|
},
|
|
706
710
|
{
|
|
707
711
|
key: "getPublicKeyFromPrivateKey",
|
|
708
|
-
value: function getPublicKeyFromPrivateKey(privateKeyHex) {
|
|
712
|
+
value: function getPublicKeyFromPrivateKey(privateKeyHex, opts) {
|
|
709
713
|
try {
|
|
710
|
-
var
|
|
714
|
+
var strippedKey = privateKeyHex.replace(/^0x/, '');
|
|
715
|
+
// Validate hex up front: Buffer.from(..., 'hex') silently drops invalid
|
|
716
|
+
// characters, which could otherwise yield a wrong buffer that still passes
|
|
717
|
+
// the length check below.
|
|
718
|
+
if (!/^[0-9a-fA-F]*$/.test(strippedKey)) {
|
|
719
|
+
throw new Error('Invalid private key: expected a hex string');
|
|
720
|
+
}
|
|
721
|
+
var privateKeyBytes = Buffer.from(strippedKey, 'hex');
|
|
711
722
|
if (privateKeyBytes.length !== 32) {
|
|
712
723
|
throw new Error("Invalid private key length: ".concat(privateKeyBytes.length, ", expected 32"));
|
|
713
724
|
}
|
|
725
|
+
if (opts === null || opts === void 0 ? void 0 : opts.isRawScalar) {
|
|
726
|
+
// Raw 32-byte ed25519 signing scalar (not a seed): derive A = s·B
|
|
727
|
+
// instead of seed-expanding via keyPairFromSeed.
|
|
728
|
+
var publicKeyBytes = getEd25519PublicKeyFromRawScalar(new Uint8Array(privateKeyBytes));
|
|
729
|
+
return Buffer.from(publicKeyBytes).toString('hex');
|
|
730
|
+
}
|
|
714
731
|
var keyPair = keyPairFromSeed(privateKeyBytes);
|
|
715
732
|
return keyPair.publicKey.toString('hex');
|
|
716
733
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/ton",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.93",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@dynamic-labs-wallet/browser": "1.0.
|
|
7
|
+
"@dynamic-labs-wallet/browser": "1.0.93",
|
|
8
8
|
"@ton/crypto": "^3.3.0",
|
|
9
9
|
"@ton/ton": "^16.0.0",
|
|
10
10
|
"@dynamic-labs/sdk-api-core": "^0.0.1093"
|
package/src/client/client.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare class DynamicTonWalletClient extends DynamicWalletClient {
|
|
|
39
39
|
signedSessionId: string;
|
|
40
40
|
mfaToken?: string;
|
|
41
41
|
}>): Promise<string>;
|
|
42
|
-
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, signedSessionId, onError, publicAddressCheck, legacyWalletId, }: {
|
|
42
|
+
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, signedSessionId, onError, publicAddressCheck, legacyWalletId, isRawScalarImport, }: {
|
|
43
43
|
privateKey: string;
|
|
44
44
|
chainName: string;
|
|
45
45
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
@@ -49,13 +49,22 @@ export declare class DynamicTonWalletClient extends DynamicWalletClient {
|
|
|
49
49
|
publicAddressCheck?: string;
|
|
50
50
|
/** ID of the legacy embedded wallet being upgraded to v3 */
|
|
51
51
|
legacyWalletId?: string;
|
|
52
|
+
/**
|
|
53
|
+
* When true, `privateKey` is a raw 32-byte ed25519 signing scalar (hex),
|
|
54
|
+
* e.g. one exported from an external MPC system (Fireblocks Embedded
|
|
55
|
+
* Wallets), rather than a TON seed. Routes the import through the
|
|
56
|
+
* non-exportable `Ed25519` protocol.
|
|
57
|
+
*/
|
|
58
|
+
isRawScalarImport?: boolean;
|
|
52
59
|
}): Promise<{
|
|
53
60
|
accountAddress: string;
|
|
54
61
|
publicKeyHex: string;
|
|
55
62
|
rawPublicKey: Uint8Array;
|
|
56
63
|
clientKeyShares: ClientKeyShare[];
|
|
57
64
|
}>;
|
|
58
|
-
getPublicKeyFromPrivateKey(privateKeyHex: string
|
|
65
|
+
getPublicKeyFromPrivateKey(privateKeyHex: string, opts?: {
|
|
66
|
+
isRawScalar?: boolean;
|
|
67
|
+
}): string;
|
|
59
68
|
getTonWallets(): Promise<any>;
|
|
60
69
|
}
|
|
61
70
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAGnB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,8BAA8B,EACpC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAarE,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CAAC,SAAS,SAAS;IAErB,mBAAmB,CAAC,EACxB,wBAAwB,EACxB,QAAoB,EACpB,OAAO,EACP,eAAe,EACf,iBAAiB,GAClB,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,EAAE,MAAM,CAAC;QACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,UAAU,CAAC;KAC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