@t2000/sdk 0.1.1 → 0.1.3
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/README.md +3 -3
- package/dist/index.cjs +10 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,9 @@ import { Transaction } from '@mysten/sui/transactions';
|
|
|
5
5
|
|
|
6
6
|
interface T2000Options {
|
|
7
7
|
keyPath?: string;
|
|
8
|
+
/** PIN to decrypt the key file. Accepts any string (4+ chars). */
|
|
9
|
+
pin?: string;
|
|
10
|
+
/** @deprecated Use `pin` instead. */
|
|
8
11
|
passphrase?: string;
|
|
9
12
|
network?: 'mainnet' | 'testnet';
|
|
10
13
|
rpcUrl?: string;
|
|
@@ -206,7 +209,8 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
206
209
|
rpcUrl?: string;
|
|
207
210
|
}): T2000;
|
|
208
211
|
static init(options: {
|
|
209
|
-
|
|
212
|
+
pin: string;
|
|
213
|
+
passphrase?: string;
|
|
210
214
|
keyPath?: string;
|
|
211
215
|
name?: string;
|
|
212
216
|
sponsored?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ import { Transaction } from '@mysten/sui/transactions';
|
|
|
5
5
|
|
|
6
6
|
interface T2000Options {
|
|
7
7
|
keyPath?: string;
|
|
8
|
+
/** PIN to decrypt the key file. Accepts any string (4+ chars). */
|
|
9
|
+
pin?: string;
|
|
10
|
+
/** @deprecated Use `pin` instead. */
|
|
8
11
|
passphrase?: string;
|
|
9
12
|
network?: 'mainnet' | 'testnet';
|
|
10
13
|
rpcUrl?: string;
|
|
@@ -206,7 +209,8 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
206
209
|
rpcUrl?: string;
|
|
207
210
|
}): T2000;
|
|
208
211
|
static init(options: {
|
|
209
|
-
|
|
212
|
+
pin: string;
|
|
213
|
+
passphrase?: string;
|
|
210
214
|
keyPath?: string;
|
|
211
215
|
name?: string;
|
|
212
216
|
sponsored?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -153,7 +153,7 @@ function decrypt(encrypted, passphrase) {
|
|
|
153
153
|
try {
|
|
154
154
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
155
155
|
} catch {
|
|
156
|
-
throw new T2000Error("WALLET_LOCKED", "Invalid
|
|
156
|
+
throw new T2000Error("WALLET_LOCKED", "Invalid PIN");
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
function generateKeypair() {
|
|
@@ -995,12 +995,13 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
995
995
|
this._address = getAddress(keypair);
|
|
996
996
|
}
|
|
997
997
|
static async create(options = {}) {
|
|
998
|
-
const { keyPath, passphrase, network = DEFAULT_NETWORK, rpcUrl, sponsored, name } = options;
|
|
998
|
+
const { keyPath, pin, passphrase, network = DEFAULT_NETWORK, rpcUrl, sponsored, name } = options;
|
|
999
|
+
const secret = pin ?? passphrase;
|
|
999
1000
|
const client = getSuiClient(rpcUrl);
|
|
1000
1001
|
if (sponsored) {
|
|
1001
1002
|
const keypair2 = generateKeypair();
|
|
1002
|
-
if (
|
|
1003
|
-
await saveKey(keypair2,
|
|
1003
|
+
if (secret) {
|
|
1004
|
+
await saveKey(keypair2, secret, keyPath);
|
|
1004
1005
|
}
|
|
1005
1006
|
return new _T2000(keypair2, client);
|
|
1006
1007
|
}
|
|
@@ -1011,10 +1012,10 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
1011
1012
|
"No wallet found. Run `t2000 init` to create one."
|
|
1012
1013
|
);
|
|
1013
1014
|
}
|
|
1014
|
-
if (!
|
|
1015
|
-
throw new T2000Error("WALLET_LOCKED", "
|
|
1015
|
+
if (!secret) {
|
|
1016
|
+
throw new T2000Error("WALLET_LOCKED", "PIN required to unlock wallet");
|
|
1016
1017
|
}
|
|
1017
|
-
const keypair = await loadKey(
|
|
1018
|
+
const keypair = await loadKey(secret, keyPath);
|
|
1018
1019
|
return new _T2000(keypair, client);
|
|
1019
1020
|
}
|
|
1020
1021
|
static fromPrivateKey(privateKey, options = {}) {
|
|
@@ -1023,8 +1024,9 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
1023
1024
|
return new _T2000(keypair, client);
|
|
1024
1025
|
}
|
|
1025
1026
|
static async init(options) {
|
|
1027
|
+
const secret = options.pin ?? options.passphrase ?? "";
|
|
1026
1028
|
const keypair = generateKeypair();
|
|
1027
|
-
await saveKey(keypair,
|
|
1029
|
+
await saveKey(keypair, secret, options.keyPath);
|
|
1028
1030
|
const client = getSuiClient();
|
|
1029
1031
|
const agent = new _T2000(keypair, client);
|
|
1030
1032
|
const address = agent.address();
|