@dynamic-labs/waas-svm 4.9.2-preview.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Dynamic Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @dynamic-labs/waas-svm
2
+
3
+ Contains logic for Dynamic WaaS SVM connectors.
4
+
5
+ ## Exported
6
+
7
+ - DynamicWaasSVMConnector
@@ -0,0 +1,36 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+
21
+ function __awaiter(thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ }
30
+
31
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
32
+ var e = new Error(message);
33
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
34
+ };
35
+
36
+ exports.__awaiter = __awaiter;
@@ -0,0 +1,32 @@
1
+ 'use client'
2
+ /******************************************************************************
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.
15
+ ***************************************************************************** */
16
+
17
+ function __awaiter(thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ }
26
+
27
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
28
+ var e = new Error(message);
29
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
30
+ };
31
+
32
+ export { __awaiter };
package/package.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var version = "4.9.2-preview.0";
7
+
8
+ exports.version = version;
package/package.js ADDED
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ var version = "4.9.2-preview.0";
3
+
4
+ export { version };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@dynamic-labs/waas-svm",
3
+ "version": "4.9.2-preview.0",
4
+ "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
+ "author": "Dynamic Labs, Inc.",
6
+ "license": "MIT",
7
+ "main": "./src/index.cjs",
8
+ "module": "./src/index.js",
9
+ "types": "./src/index.d.ts",
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./src/index.d.ts",
14
+ "import": "./src/index.js",
15
+ "require": "./src/index.cjs"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "homepage": "https://www.dynamic.xyz/",
20
+ "dependencies": {
21
+ "@dynamic-labs-wallet/svm": "0.0.33",
22
+ "@solana/web3.js": "1.98.0",
23
+ "eventemitter3": "5.0.1",
24
+ "@dynamic-labs/assert-package-version": "4.9.2-preview.0",
25
+ "@dynamic-labs/logger": "4.9.2-preview.0",
26
+ "@dynamic-labs/rpc-providers": "4.9.2-preview.0",
27
+ "@dynamic-labs/solana-core": "4.9.2-preview.0",
28
+ "@dynamic-labs/types": "4.9.2-preview.0",
29
+ "@dynamic-labs/utils": "4.9.2-preview.0",
30
+ "@dynamic-labs/wallet-connector-core": "4.9.2-preview.0"
31
+ },
32
+ "peerDependencies": {}
33
+ }
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var DynamicWaasSVMConnector = require('./connector/DynamicWaasSVMConnector.cjs');
7
+
8
+ const DynamicWaasSVMConnectors = () => [DynamicWaasSVMConnector.DynamicWaasSVMConnector];
9
+
10
+ exports.DynamicWaasSVMConnectors = DynamicWaasSVMConnectors;
@@ -0,0 +1,2 @@
1
+ import { DynamicWaasSVMConnector } from './connector/DynamicWaasSVMConnector';
2
+ export declare const DynamicWaasSVMConnectors: () => (typeof DynamicWaasSVMConnector)[];
@@ -0,0 +1,6 @@
1
+ 'use client'
2
+ import { DynamicWaasSVMConnector } from './connector/DynamicWaasSVMConnector.js';
3
+
4
+ const DynamicWaasSVMConnectors = () => [DynamicWaasSVMConnector];
5
+
6
+ export { DynamicWaasSVMConnectors };
@@ -0,0 +1,204 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var svm = require('@dynamic-labs-wallet/svm');
8
+ var solanaCore = require('@dynamic-labs/solana-core');
9
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
10
+ var utils = require('@dynamic-labs/utils');
11
+ var logger = require('../../utils/logger.cjs');
12
+ var DynamicWaasSVMSigner = require('../signer/DynamicWaasSVMSigner.cjs');
13
+
14
+ class DynamicWaasSVMConnector extends solanaCore.SolanaWalletConnector {
15
+ connect() {
16
+ throw new Error('Method not implemented.');
17
+ }
18
+ constructor(props) {
19
+ super(props);
20
+ this.name = 'Dynamic Waas';
21
+ this.overrideKey = 'dynamicwaas';
22
+ this.isEmbeddedWallet = true;
23
+ }
24
+ setGetAuthTokenFunction(getAuthToken) {
25
+ this.getAuthToken = getAuthToken;
26
+ }
27
+ setEnvironmentId(environmentId) {
28
+ this.environmentId = environmentId;
29
+ }
30
+ setBaseApiUrl(baseApiUrl) {
31
+ this.baseApiUrl = baseApiUrl;
32
+ }
33
+ setActiveAccountAddress(accountAddress) {
34
+ this.activeAccountAddress = accountAddress;
35
+ }
36
+ createDynamicWaasClient() {
37
+ var _a;
38
+ const authToken = (_a = this.getAuthToken) === null || _a === void 0 ? void 0 : _a.call(this);
39
+ if (!authToken) {
40
+ throw new Error('Auth token is required');
41
+ }
42
+ if (!this.environmentId) {
43
+ throw new Error('Environment ID is required');
44
+ }
45
+ return new svm.DynamicSvmWalletClient({
46
+ authToken,
47
+ baseApiUrl: this.baseApiUrl,
48
+ baseMPCRelayApiUrl: 'relay.dynamic-preprod.xyz',
49
+ environmentId: this.environmentId,
50
+ });
51
+ }
52
+ getWaasWalletClient() {
53
+ if (!this.dynamicWaasClient) {
54
+ this.dynamicWaasClient = this.createDynamicWaasClient();
55
+ }
56
+ return this.dynamicWaasClient;
57
+ }
58
+ validateActiveWallet(expectedAddress) {
59
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
60
+ const walletClient = this.getWaasWalletClient();
61
+ const targetWallet = yield walletClient.getWallet({
62
+ accountAddress: expectedAddress,
63
+ });
64
+ if (!targetWallet) {
65
+ throw new utils.DynamicError('Account not found');
66
+ }
67
+ const isWalletActive = walletConnectorCore.isSameAddress(targetWallet.accountAddress, this.activeAccountAddress || '', this.connectedChain);
68
+ if (!isWalletActive) {
69
+ this.activeAccountAddress = targetWallet.accountAddress;
70
+ }
71
+ });
72
+ }
73
+ createWalletAccount() {
74
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
75
+ const walletClient = this.getWaasWalletClient();
76
+ const createdWallet = yield walletClient.createWalletAccount({
77
+ thresholdSignatureScheme: 'TWO_OF_THREE',
78
+ });
79
+ return createdWallet;
80
+ });
81
+ }
82
+ signMessage(message) {
83
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
84
+ const walletClient = this.getWaasWalletClient();
85
+ const signedMessage = yield walletClient.signMessage({
86
+ accountAddress: this.activeAccountAddress,
87
+ message,
88
+ });
89
+ return signedMessage;
90
+ });
91
+ }
92
+ signTransaction(transaction) {
93
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
94
+ const walletClient = this.getWaasWalletClient();
95
+ if (!this.activeAccountAddress) {
96
+ throw new Error('Active account address is required');
97
+ }
98
+ const signedTransaction = yield walletClient.signTransaction({
99
+ senderAddress: this.activeAccountAddress,
100
+ transaction,
101
+ });
102
+ try {
103
+ signedTransaction.serialize({
104
+ requireAllSignatures: false,
105
+ verifySignatures: true,
106
+ });
107
+ }
108
+ catch (err) {
109
+ //this will throw if we signed the tx incorrectly
110
+ logger.logger.warn('[signTransaction] Error signing transaction', err);
111
+ }
112
+ return signedTransaction;
113
+ });
114
+ }
115
+ signAllTransactions(transactions) {
116
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
117
+ try {
118
+ const signedTransactions = yield Promise.all(transactions.map((transaction) => this.signTransaction(transaction)));
119
+ return signedTransactions;
120
+ }
121
+ catch (err) {
122
+ logger.logger.warn('[signAllTransactions] Error signing transactions', err);
123
+ throw err;
124
+ }
125
+ });
126
+ }
127
+ signAndSendTransaction(transaction, options) {
128
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
129
+ if (!this.activeAccountAddress) {
130
+ throw new Error('Active account address is required');
131
+ }
132
+ const connection = this.getWalletClient();
133
+ const signedTransaction = yield this.signTransaction(transaction);
134
+ const signature = yield connection.sendRawTransaction(signedTransaction.serialize(), options);
135
+ // Listen for transaction confirmation with timeout
136
+ return new Promise((resolve, reject) => {
137
+ const timeout = setTimeout(() => {
138
+ reject(new Error('Transaction timed out'));
139
+ }, 60000);
140
+ connection.onSignature(signature, (result) => {
141
+ clearTimeout(timeout);
142
+ if (result.err) {
143
+ reject(new Error(`Transaction failed: ${result.err}`));
144
+ }
145
+ else {
146
+ resolve(signature);
147
+ }
148
+ }, 'confirmed');
149
+ });
150
+ });
151
+ }
152
+ getSigner() {
153
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
154
+ // TODO: remove this unknown
155
+ return new DynamicWaasSVMSigner.DynamicWaasSVMSigner({
156
+ walletConnector: this,
157
+ });
158
+ });
159
+ }
160
+ getWalletClientByAddress({ accountAddress, }) {
161
+ this.setActiveAccountAddress(accountAddress);
162
+ return this.getWalletClient();
163
+ }
164
+ exportPrivateKey() {
165
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ accountAddress, } = {}) {
166
+ const walletClient = this.getWaasWalletClient();
167
+ const targetAccountAddress = accountAddress || this.activeAccountAddress;
168
+ if (!targetAccountAddress) {
169
+ throw new Error('Account address is required');
170
+ }
171
+ const privateKey = yield walletClient.exportPrivateKey({
172
+ accountAddress: targetAccountAddress,
173
+ });
174
+ if (!(privateKey === null || privateKey === void 0 ? void 0 : privateKey.derivedPrivateKey)) {
175
+ throw new Error('Error exporting private key');
176
+ }
177
+ return privateKey.derivedPrivateKey;
178
+ });
179
+ }
180
+ importPrivateKey(_a) {
181
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ privateKey, chainName, thresholdSignatureScheme = 'TWO_OF_TWO', }) {
182
+ const walletClient = this.getWaasWalletClient();
183
+ yield walletClient.importPrivateKey({
184
+ chainName,
185
+ privateKey,
186
+ thresholdSignatureScheme: thresholdSignatureScheme,
187
+ });
188
+ });
189
+ }
190
+ exportClientKeyshares(_a) {
191
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ accountAddress, }) {
192
+ const walletClient = this.getWaasWalletClient();
193
+ const targetAccountAddress = accountAddress || this.activeAccountAddress;
194
+ if (!targetAccountAddress) {
195
+ throw new Error('Account address is required');
196
+ }
197
+ yield walletClient.exportClientKeyshares({
198
+ accountAddress: targetAccountAddress,
199
+ });
200
+ });
201
+ }
202
+ }
203
+
204
+ exports.DynamicWaasSVMConnector = DynamicWaasSVMConnector;
@@ -0,0 +1,46 @@
1
+ import { DynamicSvmWalletClient } from '@dynamic-labs-wallet/svm';
2
+ import { Connection, Transaction, VersionedTransaction, SendOptions } from '@solana/web3.js';
3
+ import { ISolanaSigner, SolanaWalletConnector, SolanaWalletConnectorOpts } from '@dynamic-labs/solana-core';
4
+ export declare class DynamicWaasSVMConnector extends SolanaWalletConnector {
5
+ connect(): Promise<void>;
6
+ name: string;
7
+ overrideKey: string;
8
+ isEmbeddedWallet: boolean;
9
+ private environmentId?;
10
+ private getAuthToken?;
11
+ private dynamicWaasClient;
12
+ activeAccountAddress: string | undefined;
13
+ private baseApiUrl?;
14
+ constructor(props: SolanaWalletConnectorOpts);
15
+ setGetAuthTokenFunction(getAuthToken: () => string): void;
16
+ setEnvironmentId(environmentId: string): void;
17
+ setBaseApiUrl(baseApiUrl: string): void;
18
+ private setActiveAccountAddress;
19
+ createDynamicWaasClient(): DynamicSvmWalletClient;
20
+ getWaasWalletClient(): DynamicSvmWalletClient;
21
+ validateActiveWallet(expectedAddress: string): Promise<void>;
22
+ createWalletAccount(): Promise<{
23
+ accountAddress: string;
24
+ rawPublicKey: Uint8Array;
25
+ clientKeyShares: any[];
26
+ }>;
27
+ signMessage(message: string): Promise<string>;
28
+ signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<Transaction | VersionedTransaction>;
29
+ signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<(Transaction | VersionedTransaction)[]>;
30
+ signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<string>;
31
+ getSigner(): Promise<ISolanaSigner>;
32
+ getWalletClientByAddress({ accountAddress, }: {
33
+ accountAddress: string;
34
+ }): Connection;
35
+ exportPrivateKey({ accountAddress, }?: {
36
+ accountAddress?: string;
37
+ }): Promise<string>;
38
+ importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, }: {
39
+ privateKey: string;
40
+ chainName: string;
41
+ thresholdSignatureScheme?: string;
42
+ }): Promise<void>;
43
+ exportClientKeyshares({ accountAddress, }: {
44
+ accountAddress: string;
45
+ }): Promise<void>;
46
+ }
@@ -0,0 +1,200 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { DynamicSvmWalletClient } from '@dynamic-labs-wallet/svm';
4
+ import { SolanaWalletConnector } from '@dynamic-labs/solana-core';
5
+ import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
6
+ import { DynamicError } from '@dynamic-labs/utils';
7
+ import { logger } from '../../utils/logger.js';
8
+ import { DynamicWaasSVMSigner } from '../signer/DynamicWaasSVMSigner.js';
9
+
10
+ class DynamicWaasSVMConnector extends SolanaWalletConnector {
11
+ connect() {
12
+ throw new Error('Method not implemented.');
13
+ }
14
+ constructor(props) {
15
+ super(props);
16
+ this.name = 'Dynamic Waas';
17
+ this.overrideKey = 'dynamicwaas';
18
+ this.isEmbeddedWallet = true;
19
+ }
20
+ setGetAuthTokenFunction(getAuthToken) {
21
+ this.getAuthToken = getAuthToken;
22
+ }
23
+ setEnvironmentId(environmentId) {
24
+ this.environmentId = environmentId;
25
+ }
26
+ setBaseApiUrl(baseApiUrl) {
27
+ this.baseApiUrl = baseApiUrl;
28
+ }
29
+ setActiveAccountAddress(accountAddress) {
30
+ this.activeAccountAddress = accountAddress;
31
+ }
32
+ createDynamicWaasClient() {
33
+ var _a;
34
+ const authToken = (_a = this.getAuthToken) === null || _a === void 0 ? void 0 : _a.call(this);
35
+ if (!authToken) {
36
+ throw new Error('Auth token is required');
37
+ }
38
+ if (!this.environmentId) {
39
+ throw new Error('Environment ID is required');
40
+ }
41
+ return new DynamicSvmWalletClient({
42
+ authToken,
43
+ baseApiUrl: this.baseApiUrl,
44
+ baseMPCRelayApiUrl: 'relay.dynamic-preprod.xyz',
45
+ environmentId: this.environmentId,
46
+ });
47
+ }
48
+ getWaasWalletClient() {
49
+ if (!this.dynamicWaasClient) {
50
+ this.dynamicWaasClient = this.createDynamicWaasClient();
51
+ }
52
+ return this.dynamicWaasClient;
53
+ }
54
+ validateActiveWallet(expectedAddress) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const walletClient = this.getWaasWalletClient();
57
+ const targetWallet = yield walletClient.getWallet({
58
+ accountAddress: expectedAddress,
59
+ });
60
+ if (!targetWallet) {
61
+ throw new DynamicError('Account not found');
62
+ }
63
+ const isWalletActive = isSameAddress(targetWallet.accountAddress, this.activeAccountAddress || '', this.connectedChain);
64
+ if (!isWalletActive) {
65
+ this.activeAccountAddress = targetWallet.accountAddress;
66
+ }
67
+ });
68
+ }
69
+ createWalletAccount() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const walletClient = this.getWaasWalletClient();
72
+ const createdWallet = yield walletClient.createWalletAccount({
73
+ thresholdSignatureScheme: 'TWO_OF_THREE',
74
+ });
75
+ return createdWallet;
76
+ });
77
+ }
78
+ signMessage(message) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ const walletClient = this.getWaasWalletClient();
81
+ const signedMessage = yield walletClient.signMessage({
82
+ accountAddress: this.activeAccountAddress,
83
+ message,
84
+ });
85
+ return signedMessage;
86
+ });
87
+ }
88
+ signTransaction(transaction) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const walletClient = this.getWaasWalletClient();
91
+ if (!this.activeAccountAddress) {
92
+ throw new Error('Active account address is required');
93
+ }
94
+ const signedTransaction = yield walletClient.signTransaction({
95
+ senderAddress: this.activeAccountAddress,
96
+ transaction,
97
+ });
98
+ try {
99
+ signedTransaction.serialize({
100
+ requireAllSignatures: false,
101
+ verifySignatures: true,
102
+ });
103
+ }
104
+ catch (err) {
105
+ //this will throw if we signed the tx incorrectly
106
+ logger.warn('[signTransaction] Error signing transaction', err);
107
+ }
108
+ return signedTransaction;
109
+ });
110
+ }
111
+ signAllTransactions(transactions) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ try {
114
+ const signedTransactions = yield Promise.all(transactions.map((transaction) => this.signTransaction(transaction)));
115
+ return signedTransactions;
116
+ }
117
+ catch (err) {
118
+ logger.warn('[signAllTransactions] Error signing transactions', err);
119
+ throw err;
120
+ }
121
+ });
122
+ }
123
+ signAndSendTransaction(transaction, options) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ if (!this.activeAccountAddress) {
126
+ throw new Error('Active account address is required');
127
+ }
128
+ const connection = this.getWalletClient();
129
+ const signedTransaction = yield this.signTransaction(transaction);
130
+ const signature = yield connection.sendRawTransaction(signedTransaction.serialize(), options);
131
+ // Listen for transaction confirmation with timeout
132
+ return new Promise((resolve, reject) => {
133
+ const timeout = setTimeout(() => {
134
+ reject(new Error('Transaction timed out'));
135
+ }, 60000);
136
+ connection.onSignature(signature, (result) => {
137
+ clearTimeout(timeout);
138
+ if (result.err) {
139
+ reject(new Error(`Transaction failed: ${result.err}`));
140
+ }
141
+ else {
142
+ resolve(signature);
143
+ }
144
+ }, 'confirmed');
145
+ });
146
+ });
147
+ }
148
+ getSigner() {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ // TODO: remove this unknown
151
+ return new DynamicWaasSVMSigner({
152
+ walletConnector: this,
153
+ });
154
+ });
155
+ }
156
+ getWalletClientByAddress({ accountAddress, }) {
157
+ this.setActiveAccountAddress(accountAddress);
158
+ return this.getWalletClient();
159
+ }
160
+ exportPrivateKey() {
161
+ return __awaiter(this, arguments, void 0, function* ({ accountAddress, } = {}) {
162
+ const walletClient = this.getWaasWalletClient();
163
+ const targetAccountAddress = accountAddress || this.activeAccountAddress;
164
+ if (!targetAccountAddress) {
165
+ throw new Error('Account address is required');
166
+ }
167
+ const privateKey = yield walletClient.exportPrivateKey({
168
+ accountAddress: targetAccountAddress,
169
+ });
170
+ if (!(privateKey === null || privateKey === void 0 ? void 0 : privateKey.derivedPrivateKey)) {
171
+ throw new Error('Error exporting private key');
172
+ }
173
+ return privateKey.derivedPrivateKey;
174
+ });
175
+ }
176
+ importPrivateKey(_a) {
177
+ return __awaiter(this, arguments, void 0, function* ({ privateKey, chainName, thresholdSignatureScheme = 'TWO_OF_TWO', }) {
178
+ const walletClient = this.getWaasWalletClient();
179
+ yield walletClient.importPrivateKey({
180
+ chainName,
181
+ privateKey,
182
+ thresholdSignatureScheme: thresholdSignatureScheme,
183
+ });
184
+ });
185
+ }
186
+ exportClientKeyshares(_a) {
187
+ return __awaiter(this, arguments, void 0, function* ({ accountAddress, }) {
188
+ const walletClient = this.getWaasWalletClient();
189
+ const targetAccountAddress = accountAddress || this.activeAccountAddress;
190
+ if (!targetAccountAddress) {
191
+ throw new Error('Account address is required');
192
+ }
193
+ yield walletClient.exportClientKeyshares({
194
+ accountAddress: targetAccountAddress,
195
+ });
196
+ });
197
+ }
198
+ }
199
+
200
+ export { DynamicWaasSVMConnector };
package/src/index.cjs ADDED
@@ -0,0 +1,14 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var assertPackageVersion = require('@dynamic-labs/assert-package-version');
7
+ var _package = require('../package.cjs');
8
+ var DynamicWaasSVMConnector = require('./connector/DynamicWaasSVMConnector.cjs');
9
+ var DynamicWaasSvmConnectors = require('./DynamicWaasSvmConnectors.cjs');
10
+
11
+ assertPackageVersion.assertPackageVersion('@dynamic-labs/waas-svm', _package.version);
12
+
13
+ exports.DynamicWaasSVMConnector = DynamicWaasSVMConnector.DynamicWaasSVMConnector;
14
+ exports.DynamicWaasSVMConnectors = DynamicWaasSvmConnectors.DynamicWaasSVMConnectors;
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { DynamicWaasSVMConnector } from './connector/DynamicWaasSVMConnector';
2
+ export { DynamicWaasSVMConnectors } from './DynamicWaasSvmConnectors';
package/src/index.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use client'
2
+ import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
3
+ import { version } from '../package.js';
4
+ export { DynamicWaasSVMConnector } from './connector/DynamicWaasSVMConnector.js';
5
+ export { DynamicWaasSVMConnectors } from './DynamicWaasSvmConnectors.js';
6
+
7
+ assertPackageVersion('@dynamic-labs/waas-svm', version);