@trustwallet/cli 0.12.1 → 0.12.2
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/dist/commands/wallet.d.ts.map +1 -1
- package/dist/index.js +157 -106
- package/dist/password.d.ts +12 -0
- package/dist/password.d.ts.map +1 -0
- package/dist/setup/phase-wallet.d.ts +1 -1
- package/dist/setup/phase-wallet.d.ts.map +1 -1
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/commands/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/commands/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6CpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAktB5D"}
|
package/dist/index.js
CHANGED
|
@@ -4366,12 +4366,12 @@ var init_dist = __esm({
|
|
|
4366
4366
|
});
|
|
4367
4367
|
|
|
4368
4368
|
// ../storage/dist/index.mjs
|
|
4369
|
-
function deriveKey(
|
|
4370
|
-
return crypto22.pbkdf2Sync(
|
|
4369
|
+
function deriveKey(password3, salt) {
|
|
4370
|
+
return crypto22.pbkdf2Sync(password3, salt, ITERATIONS, KEY_LENGTH, "sha256");
|
|
4371
4371
|
}
|
|
4372
|
-
function encrypt(plaintext,
|
|
4372
|
+
function encrypt(plaintext, password3) {
|
|
4373
4373
|
const salt = crypto22.randomBytes(SALT_LENGTH);
|
|
4374
|
-
const key = deriveKey(
|
|
4374
|
+
const key = deriveKey(password3, salt);
|
|
4375
4375
|
const iv = crypto22.randomBytes(IV_LENGTH);
|
|
4376
4376
|
const cipher = crypto22.createCipheriv(ALGORITHM, key, iv);
|
|
4377
4377
|
let encrypted = cipher.update(plaintext, "utf-8", "hex");
|
|
@@ -4383,9 +4383,9 @@ function encrypt(plaintext, password2) {
|
|
|
4383
4383
|
salt: salt.toString("hex")
|
|
4384
4384
|
};
|
|
4385
4385
|
}
|
|
4386
|
-
function decrypt(data,
|
|
4386
|
+
function decrypt(data, password3) {
|
|
4387
4387
|
const salt = Buffer.from(data.salt, "hex");
|
|
4388
|
-
const key = deriveKey(
|
|
4388
|
+
const key = deriveKey(password3, salt);
|
|
4389
4389
|
const iv = Buffer.from(data.iv, "hex");
|
|
4390
4390
|
const decipher = crypto22.createDecipheriv(ALGORITHM, key, iv);
|
|
4391
4391
|
decipher.setAuthTag(Buffer.from(data.authTag, "hex"));
|
|
@@ -4489,8 +4489,8 @@ var init_dist2 = __esm({
|
|
|
4489
4489
|
async getWalletPassword() {
|
|
4490
4490
|
return getPassword(SERVICE, WALLET_ACCOUNT);
|
|
4491
4491
|
}
|
|
4492
|
-
async saveWalletPassword(
|
|
4493
|
-
new import_keyring.Entry(SERVICE, WALLET_ACCOUNT).setPassword(
|
|
4492
|
+
async saveWalletPassword(password3) {
|
|
4493
|
+
new import_keyring.Entry(SERVICE, WALLET_ACCOUNT).setPassword(password3);
|
|
4494
4494
|
}
|
|
4495
4495
|
async deleteWalletPassword() {
|
|
4496
4496
|
new import_keyring.Entry(SERVICE, WALLET_ACCOUNT).deletePassword();
|
|
@@ -4582,8 +4582,8 @@ var init_dist2 = __esm({
|
|
|
4582
4582
|
constructor(config2) {
|
|
4583
4583
|
this.store = new FileStore(config2);
|
|
4584
4584
|
}
|
|
4585
|
-
async saveMnemonic(mnemonic,
|
|
4586
|
-
const encrypted = encrypt(mnemonic,
|
|
4585
|
+
async saveMnemonic(mnemonic, password3, chains) {
|
|
4586
|
+
const encrypted = encrypt(mnemonic, password3);
|
|
4587
4587
|
const config2 = {
|
|
4588
4588
|
encryptedMnemonic: encrypted.ciphertext,
|
|
4589
4589
|
iv: encrypted.iv,
|
|
@@ -4594,7 +4594,7 @@ var init_dist2 = __esm({
|
|
|
4594
4594
|
};
|
|
4595
4595
|
await this.store.write(WALLET_FILE, config2);
|
|
4596
4596
|
}
|
|
4597
|
-
async loadMnemonic(
|
|
4597
|
+
async loadMnemonic(password3) {
|
|
4598
4598
|
const config2 = await this.store.read(WALLET_FILE);
|
|
4599
4599
|
if (!config2) {
|
|
4600
4600
|
throw new Error("No wallet configuration found");
|
|
@@ -4605,7 +4605,7 @@ var init_dist2 = __esm({
|
|
|
4605
4605
|
authTag: config2.authTag,
|
|
4606
4606
|
salt: config2.salt
|
|
4607
4607
|
};
|
|
4608
|
-
return decrypt(encrypted,
|
|
4608
|
+
return decrypt(encrypted, password3);
|
|
4609
4609
|
}
|
|
4610
4610
|
async exists() {
|
|
4611
4611
|
return this.store.exists(WALLET_FILE);
|
|
@@ -7723,9 +7723,9 @@ var init_dist3 = __esm({
|
|
|
7723
7723
|
throw new Error("Wallet is locked. Re-authenticate to continue.");
|
|
7724
7724
|
}
|
|
7725
7725
|
this.reconnecting = (async () => {
|
|
7726
|
-
const
|
|
7726
|
+
const password3 = await this.passwordResolver();
|
|
7727
7727
|
const store = new WalletConfigStore();
|
|
7728
|
-
const mnemonic = await store.loadMnemonic(
|
|
7728
|
+
const mnemonic = await store.loadMnemonic(password3);
|
|
7729
7729
|
this.signer = await WalletCoreSigner.fromMnemonic(mnemonic);
|
|
7730
7730
|
this.blockchainClient = new BlockchainClient(this.signer);
|
|
7731
7731
|
this.connected = true;
|
|
@@ -7736,26 +7736,26 @@ var init_dist3 = __esm({
|
|
|
7736
7736
|
this.reconnecting = null;
|
|
7737
7737
|
}
|
|
7738
7738
|
}
|
|
7739
|
-
static async create(
|
|
7739
|
+
static async create(password3) {
|
|
7740
7740
|
const walletCore2 = getWalletCore();
|
|
7741
7741
|
const hdWallet = walletCore2.HDWallet.create(128, "");
|
|
7742
7742
|
const mnemonic = hdWallet.mnemonic();
|
|
7743
7743
|
const store = new WalletConfigStore();
|
|
7744
|
-
await store.saveMnemonic(mnemonic,
|
|
7744
|
+
await store.saveMnemonic(mnemonic, password3, Object.keys(CHAINS));
|
|
7745
7745
|
const signer = WalletCoreSigner.fromHDWallet(hdWallet);
|
|
7746
7746
|
const client = new BlockchainClient(signer);
|
|
7747
7747
|
return new _AgentWalletProvider(signer, client);
|
|
7748
7748
|
}
|
|
7749
|
-
static async fromStorage(
|
|
7749
|
+
static async fromStorage(password3) {
|
|
7750
7750
|
const store = new WalletConfigStore();
|
|
7751
|
-
const mnemonic = await store.loadMnemonic(
|
|
7751
|
+
const mnemonic = await store.loadMnemonic(password3);
|
|
7752
7752
|
const signer = await WalletCoreSigner.fromMnemonic(mnemonic);
|
|
7753
7753
|
const client = new BlockchainClient(signer);
|
|
7754
7754
|
return new _AgentWalletProvider(signer, client);
|
|
7755
7755
|
}
|
|
7756
|
-
static async fromMnemonic(mnemonic,
|
|
7756
|
+
static async fromMnemonic(mnemonic, password3) {
|
|
7757
7757
|
const store = new WalletConfigStore();
|
|
7758
|
-
await store.saveMnemonic(mnemonic,
|
|
7758
|
+
await store.saveMnemonic(mnemonic, password3, Object.keys(CHAINS));
|
|
7759
7759
|
const signer = await WalletCoreSigner.fromMnemonic(mnemonic);
|
|
7760
7760
|
const client = new BlockchainClient(signer);
|
|
7761
7761
|
return new _AgentWalletProvider(signer, client);
|
|
@@ -14441,11 +14441,11 @@ var require_util3 = __commonJS({
|
|
|
14441
14441
|
return false;
|
|
14442
14442
|
}
|
|
14443
14443
|
exports2.schemaHasRules = schemaHasRules;
|
|
14444
|
-
function schemaHasRulesButRef(schema,
|
|
14444
|
+
function schemaHasRulesButRef(schema, RULES2) {
|
|
14445
14445
|
if (typeof schema == "boolean")
|
|
14446
14446
|
return !schema;
|
|
14447
14447
|
for (const key in schema)
|
|
14448
|
-
if (key !== "$ref" &&
|
|
14448
|
+
if (key !== "$ref" && RULES2.all[key])
|
|
14449
14449
|
return true;
|
|
14450
14450
|
return false;
|
|
14451
14451
|
}
|
|
@@ -15839,17 +15839,17 @@ var require_validate = __commonJS({
|
|
|
15839
15839
|
}
|
|
15840
15840
|
function schemaKeywords(it4, types, typeErrors, errsCount) {
|
|
15841
15841
|
const { gen: gen2, schema, data, allErrors, opts, self: self2 } = it4;
|
|
15842
|
-
const { RULES } = self2;
|
|
15843
|
-
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1.schemaHasRulesButRef)(schema,
|
|
15844
|
-
gen2.block(() => keywordCode(it4, "$ref",
|
|
15842
|
+
const { RULES: RULES2 } = self2;
|
|
15843
|
+
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1.schemaHasRulesButRef)(schema, RULES2))) {
|
|
15844
|
+
gen2.block(() => keywordCode(it4, "$ref", RULES2.all.$ref.definition));
|
|
15845
15845
|
return;
|
|
15846
15846
|
}
|
|
15847
15847
|
if (!opts.jtd)
|
|
15848
15848
|
checkStrictTypes(it4, types);
|
|
15849
15849
|
gen2.block(() => {
|
|
15850
|
-
for (const group of
|
|
15850
|
+
for (const group of RULES2.rules)
|
|
15851
15851
|
groupKeywords(group);
|
|
15852
|
-
groupKeywords(
|
|
15852
|
+
groupKeywords(RULES2.post);
|
|
15853
15853
|
});
|
|
15854
15854
|
function groupKeywords(group) {
|
|
15855
15855
|
if (!(0, applicability_1.shouldUseGroup)(schema, group))
|
|
@@ -17551,10 +17551,10 @@ var require_core = __commonJS({
|
|
|
17551
17551
|
}
|
|
17552
17552
|
// Remove keyword
|
|
17553
17553
|
removeKeyword(keyword) {
|
|
17554
|
-
const { RULES } = this;
|
|
17555
|
-
delete
|
|
17556
|
-
delete
|
|
17557
|
-
for (const group of
|
|
17554
|
+
const { RULES: RULES2 } = this;
|
|
17555
|
+
delete RULES2.keywords[keyword];
|
|
17556
|
+
delete RULES2.all[keyword];
|
|
17557
|
+
for (const group of RULES2.rules) {
|
|
17558
17558
|
const i2 = group.rules.findIndex((rule) => rule.keyword === keyword);
|
|
17559
17559
|
if (i2 >= 0)
|
|
17560
17560
|
group.rules.splice(i2, 1);
|
|
@@ -17722,9 +17722,9 @@ var require_core = __commonJS({
|
|
|
17722
17722
|
}
|
|
17723
17723
|
var KEYWORD_NAME = /^[a-z_$][a-z0-9_$:-]*$/i;
|
|
17724
17724
|
function checkKeyword(keyword, def) {
|
|
17725
|
-
const { RULES } = this;
|
|
17725
|
+
const { RULES: RULES2 } = this;
|
|
17726
17726
|
(0, util_1.eachItem)(keyword, (kwd) => {
|
|
17727
|
-
if (
|
|
17727
|
+
if (RULES2.keywords[kwd])
|
|
17728
17728
|
throw new Error(`Keyword ${kwd} is already defined`);
|
|
17729
17729
|
if (!KEYWORD_NAME.test(kwd))
|
|
17730
17730
|
throw new Error(`Keyword ${kwd} has invalid name`);
|
|
@@ -17740,13 +17740,13 @@ var require_core = __commonJS({
|
|
|
17740
17740
|
const post = definition === null || definition === void 0 ? void 0 : definition.post;
|
|
17741
17741
|
if (dataType && post)
|
|
17742
17742
|
throw new Error('keyword with "post" flag cannot have "type"');
|
|
17743
|
-
const { RULES } = this;
|
|
17744
|
-
let ruleGroup = post ?
|
|
17743
|
+
const { RULES: RULES2 } = this;
|
|
17744
|
+
let ruleGroup = post ? RULES2.post : RULES2.rules.find(({ type: t }) => t === dataType);
|
|
17745
17745
|
if (!ruleGroup) {
|
|
17746
17746
|
ruleGroup = { type: dataType, rules: [] };
|
|
17747
|
-
|
|
17747
|
+
RULES2.rules.push(ruleGroup);
|
|
17748
17748
|
}
|
|
17749
|
-
|
|
17749
|
+
RULES2.keywords[keyword] = true;
|
|
17750
17750
|
if (!definition)
|
|
17751
17751
|
return;
|
|
17752
17752
|
const rule = {
|
|
@@ -17761,7 +17761,7 @@ var require_core = __commonJS({
|
|
|
17761
17761
|
addBeforeRule.call(this, ruleGroup, rule, definition.before);
|
|
17762
17762
|
else
|
|
17763
17763
|
ruleGroup.rules.push(rule);
|
|
17764
|
-
|
|
17764
|
+
RULES2.all[keyword] = rule;
|
|
17765
17765
|
(_a2 = definition.implements) === null || _a2 === void 0 ? void 0 : _a2.forEach((kwd) => this.addKeyword(kwd));
|
|
17766
17766
|
}
|
|
17767
17767
|
function addBeforeRule(ruleGroup, rule, before) {
|
|
@@ -38944,8 +38944,8 @@ async function tryRegisterWallet() {
|
|
|
38944
38944
|
if (!await store.exists()) return;
|
|
38945
38945
|
try {
|
|
38946
38946
|
const creds = await ensureTrustSDK();
|
|
38947
|
-
const
|
|
38948
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
38947
|
+
const password3 = await resolvePassword();
|
|
38948
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
38949
38949
|
await registerWalletWithBackend(creds, provider);
|
|
38950
38950
|
info("Wallet registered with backend");
|
|
38951
38951
|
} catch {
|
|
@@ -39577,6 +39577,21 @@ var import_node_crypto2 = require("crypto");
|
|
|
39577
39577
|
var import_prompts3 = require("@inquirer/prompts");
|
|
39578
39578
|
init_dist2();
|
|
39579
39579
|
init_dist();
|
|
39580
|
+
|
|
39581
|
+
// src/password.ts
|
|
39582
|
+
var RULES = [
|
|
39583
|
+
[(pw) => pw.length >= 8, "be at least 8 characters long"],
|
|
39584
|
+
[(pw) => /[a-z]/.test(pw), "include a lowercase letter"],
|
|
39585
|
+
[(pw) => /[A-Z]/.test(pw), "include an uppercase letter"],
|
|
39586
|
+
[(pw) => /[0-9]/.test(pw), "include a number"]
|
|
39587
|
+
];
|
|
39588
|
+
function getPasswordWeaknesses(pw) {
|
|
39589
|
+
const failed = RULES.filter(([test]) => !test(pw)).map(([, label]) => label);
|
|
39590
|
+
return failed.length > 0 ? failed.join(", ") : null;
|
|
39591
|
+
}
|
|
39592
|
+
|
|
39593
|
+
// src/setup/phase-wallet.ts
|
|
39594
|
+
var MAX_PASSWORD_CONFIRM_ATTEMPTS = 3;
|
|
39580
39595
|
var defaultPrompter3 = {
|
|
39581
39596
|
selectWalletOption: () => (0, import_prompts3.select)({
|
|
39582
39597
|
message: "Pick one:",
|
|
@@ -39597,24 +39612,49 @@ var defaultPrompter3 = {
|
|
|
39597
39612
|
description: "Read-only operations work without a wallet."
|
|
39598
39613
|
}
|
|
39599
39614
|
]
|
|
39600
|
-
})
|
|
39615
|
+
}),
|
|
39616
|
+
promptWalletPassword: async () => {
|
|
39617
|
+
for (let attempt = 1; attempt <= MAX_PASSWORD_CONFIRM_ATTEMPTS; attempt++) {
|
|
39618
|
+
const pw = await (0, import_prompts3.password)({
|
|
39619
|
+
message: "Choose a wallet password (min 8 chars, mixed case + digit):",
|
|
39620
|
+
mask: "\u25CF",
|
|
39621
|
+
validate: (s2) => {
|
|
39622
|
+
const w4 = getPasswordWeaknesses(s2);
|
|
39623
|
+
return w4 === null ? true : `Password must ${w4}.`;
|
|
39624
|
+
}
|
|
39625
|
+
});
|
|
39626
|
+
const confirm = await (0, import_prompts3.password)({
|
|
39627
|
+
message: "Confirm password:",
|
|
39628
|
+
mask: "\u25CF"
|
|
39629
|
+
});
|
|
39630
|
+
if (pw === confirm) return pw;
|
|
39631
|
+
const remaining = MAX_PASSWORD_CONFIRM_ATTEMPTS - attempt;
|
|
39632
|
+
if (remaining > 0) {
|
|
39633
|
+
error(`Passwords don't match. ${remaining} attempt(s) left.`);
|
|
39634
|
+
}
|
|
39635
|
+
}
|
|
39636
|
+
throw new CommandError(
|
|
39637
|
+
"VALIDATION_ERROR",
|
|
39638
|
+
`Could not capture a matching wallet password after ${MAX_PASSWORD_CONFIRM_ATTEMPTS} attempts.`
|
|
39639
|
+
);
|
|
39640
|
+
}
|
|
39601
39641
|
};
|
|
39602
39642
|
function makeDefaultDeps3() {
|
|
39603
39643
|
return {
|
|
39604
39644
|
prompter: defaultPrompter3,
|
|
39605
39645
|
storage: new WalletConfigStore(),
|
|
39606
39646
|
walletCreator: {
|
|
39607
|
-
async create(
|
|
39647
|
+
async create(pw) {
|
|
39608
39648
|
await ensureTrustSDK();
|
|
39609
|
-
const provider = await AgentWalletProvider.create(
|
|
39649
|
+
const provider = await AgentWalletProvider.create(pw);
|
|
39610
39650
|
const primaryAddress = await provider.getAddress("ethereum") ?? "<unknown>";
|
|
39611
39651
|
return { primaryAddress };
|
|
39612
39652
|
}
|
|
39613
39653
|
},
|
|
39614
39654
|
keychain: {
|
|
39615
39655
|
isAvailable: () => new KeychainManager().isAvailable(),
|
|
39616
|
-
async saveWalletPassword(
|
|
39617
|
-
await new KeychainManager().saveWalletPassword(
|
|
39656
|
+
async saveWalletPassword(pw) {
|
|
39657
|
+
await new KeychainManager().saveWalletPassword(pw);
|
|
39618
39658
|
},
|
|
39619
39659
|
async saveProbe(value) {
|
|
39620
39660
|
await new KeychainManager().saveProbe(value);
|
|
@@ -39626,8 +39666,7 @@ function makeDefaultDeps3() {
|
|
|
39626
39666
|
await new KeychainManager().deleteProbe();
|
|
39627
39667
|
}
|
|
39628
39668
|
},
|
|
39629
|
-
env: process.env
|
|
39630
|
-
generatePassword: () => (0, import_node_crypto2.randomBytes)(32).toString("hex")
|
|
39669
|
+
env: process.env
|
|
39631
39670
|
};
|
|
39632
39671
|
}
|
|
39633
39672
|
async function runWalletPhase(opts, deps = makeDefaultDeps3()) {
|
|
@@ -39652,6 +39691,14 @@ async function runWalletPhase(opts, deps = makeDefaultDeps3()) {
|
|
|
39652
39691
|
}
|
|
39653
39692
|
}
|
|
39654
39693
|
async function createAgentWallet(deps) {
|
|
39694
|
+
await preflightWalletCreate(deps);
|
|
39695
|
+
info(
|
|
39696
|
+
"Choose a password to encrypt your wallet. twak stores it in your local OS keychain so day-to-day commands don't re-prompt \u2014 nothing leaves your machine. Still: write it down somewhere safe (password manager) too. If the keychain ever fails, that's your only recovery path.\n"
|
|
39697
|
+
);
|
|
39698
|
+
const pw = await deps.prompter.promptWalletPassword();
|
|
39699
|
+
await writeNewWallet(deps, pw);
|
|
39700
|
+
}
|
|
39701
|
+
async function preflightWalletCreate(deps) {
|
|
39655
39702
|
if (await deps.storage.exists()) {
|
|
39656
39703
|
throw new WalletError(
|
|
39657
39704
|
"WALLET_EXISTS",
|
|
@@ -39665,10 +39712,11 @@ async function createAgentWallet(deps) {
|
|
|
39665
39712
|
);
|
|
39666
39713
|
}
|
|
39667
39714
|
await assertKeychainCanPersist(deps);
|
|
39715
|
+
}
|
|
39716
|
+
async function writeNewWallet(deps, pw) {
|
|
39668
39717
|
info("Creating agent wallet...");
|
|
39669
|
-
const
|
|
39670
|
-
|
|
39671
|
-
await deps.keychain.saveWalletPassword(password2);
|
|
39718
|
+
const { primaryAddress } = await deps.walletCreator.create(pw);
|
|
39719
|
+
await deps.keychain.saveWalletPassword(pw);
|
|
39672
39720
|
success("Wallet created.");
|
|
39673
39721
|
info(` Primary ETH address: ${primaryAddress}`);
|
|
39674
39722
|
success("Password saved to OS keychain.");
|
|
@@ -39698,18 +39746,29 @@ async function assertKeychainCanPersist(deps) {
|
|
|
39698
39746
|
}
|
|
39699
39747
|
async function runNonInteractive3(deps) {
|
|
39700
39748
|
const mode = deps.env.TWAK_SETUP_WALLET ?? "skip";
|
|
39701
|
-
if (mode === "create") {
|
|
39702
|
-
await createAgentWallet(deps);
|
|
39703
|
-
return;
|
|
39704
|
-
}
|
|
39705
39749
|
if (mode === "skip") {
|
|
39706
39750
|
info("Wallet creation skipped (set TWAK_SETUP_WALLET=create to opt in).");
|
|
39707
39751
|
return;
|
|
39708
39752
|
}
|
|
39709
|
-
|
|
39710
|
-
|
|
39711
|
-
|
|
39712
|
-
|
|
39753
|
+
if (mode !== "create") {
|
|
39754
|
+
throw new CommandError(
|
|
39755
|
+
"VALIDATION_ERROR",
|
|
39756
|
+
`Unknown TWAK_SETUP_WALLET value: ${mode}. Use 'create' or 'skip'.`
|
|
39757
|
+
);
|
|
39758
|
+
}
|
|
39759
|
+
const envPassword = deps.env.TWAK_WALLET_PASSWORD?.trim();
|
|
39760
|
+
if (!envPassword) {
|
|
39761
|
+
throw new CommandError(
|
|
39762
|
+
"VALIDATION_ERROR",
|
|
39763
|
+
"TWAK_WALLET_PASSWORD must be set when TWAK_SETUP_WALLET=create. Choose a strong password (min 8 chars, mixed case + digit) and pass it via the env var before re-running setup."
|
|
39764
|
+
);
|
|
39765
|
+
}
|
|
39766
|
+
const weakness = getPasswordWeaknesses(envPassword);
|
|
39767
|
+
if (weakness) {
|
|
39768
|
+
throw new CommandError("VALIDATION_ERROR", `TWAK_WALLET_PASSWORD too weak: must ${weakness}.`);
|
|
39769
|
+
}
|
|
39770
|
+
await preflightWalletCreate(deps);
|
|
39771
|
+
await writeNewWallet(deps, envPassword);
|
|
39713
39772
|
}
|
|
39714
39773
|
|
|
39715
39774
|
// src/commands/setup.ts
|
|
@@ -39861,17 +39920,9 @@ function registerWalletCommand(program3) {
|
|
|
39861
39920
|
wallet.command("create").description("Create a new agent wallet").requiredOption("--password <password>", "Password to encrypt the wallet").option("--no-keychain", "Do not save password to OS keychain").option("--skip-password-check", "Skip password strength validation").option("--json", "JSON output").action(async (opts) => {
|
|
39862
39921
|
try {
|
|
39863
39922
|
if (!opts.skipPasswordCheck) {
|
|
39864
|
-
const
|
|
39865
|
-
|
|
39866
|
-
|
|
39867
|
-
if (!/[a-z]/.test(pw)) issues.push("include a lowercase letter");
|
|
39868
|
-
if (!/[A-Z]/.test(pw)) issues.push("include an uppercase letter");
|
|
39869
|
-
if (!/[0-9]/.test(pw)) issues.push("include a number");
|
|
39870
|
-
if (issues.length > 0) {
|
|
39871
|
-
throw new WalletError(
|
|
39872
|
-
"VALIDATION_ERROR",
|
|
39873
|
-
`Password too weak: must ${issues.join(", ")}.`
|
|
39874
|
-
);
|
|
39923
|
+
const weakness = getPasswordWeaknesses(opts.password);
|
|
39924
|
+
if (weakness) {
|
|
39925
|
+
throw new WalletError("VALIDATION_ERROR", `Password too weak: must ${weakness}.`);
|
|
39875
39926
|
}
|
|
39876
39927
|
}
|
|
39877
39928
|
await ensureTrustSDK();
|
|
@@ -39918,8 +39969,8 @@ function registerWalletCommand(program3) {
|
|
|
39918
39969
|
throw new WalletError("CHAIN_UNSUPPORTED", `Unknown chain: ${opts.chain}`);
|
|
39919
39970
|
}
|
|
39920
39971
|
await ensureTrustSDK();
|
|
39921
|
-
const
|
|
39922
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
39972
|
+
const password3 = await resolvePassword(opts);
|
|
39973
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
39923
39974
|
const address = await provider.getAddress(opts.chain);
|
|
39924
39975
|
if (opts.json) {
|
|
39925
39976
|
output({ chain: opts.chain, address }, true);
|
|
@@ -39942,8 +39993,8 @@ ${qr3}`;
|
|
|
39942
39993
|
).option("--json", "JSON output").action(async (opts) => {
|
|
39943
39994
|
try {
|
|
39944
39995
|
await ensureTrustSDK();
|
|
39945
|
-
const
|
|
39946
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
39996
|
+
const password3 = await resolvePassword(opts);
|
|
39997
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
39947
39998
|
const addresses = await provider.getAddresses();
|
|
39948
39999
|
if (opts.json) {
|
|
39949
40000
|
output({ addresses }, true);
|
|
@@ -39996,8 +40047,8 @@ ${qr3}`;
|
|
|
39996
40047
|
throw new WalletError("VALIDATION_ERROR", "Provide --chain <key> or --all");
|
|
39997
40048
|
}
|
|
39998
40049
|
await ensureTrustSDK();
|
|
39999
|
-
const
|
|
40000
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
40050
|
+
const password3 = await resolvePassword(opts);
|
|
40051
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
40001
40052
|
const httpClient = await getClient();
|
|
40002
40053
|
if (!opts.all) {
|
|
40003
40054
|
const chain2 = getChainById(opts.chain);
|
|
@@ -40278,8 +40329,8 @@ ${qr3}`;
|
|
|
40278
40329
|
).option("--json", "JSON output").action(async (opts) => {
|
|
40279
40330
|
try {
|
|
40280
40331
|
await ensureTrustSDK();
|
|
40281
|
-
const
|
|
40282
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
40332
|
+
const password3 = await resolvePassword(opts);
|
|
40333
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
40283
40334
|
const httpClient = await getClient();
|
|
40284
40335
|
const allAddresses = await provider.getAddresses();
|
|
40285
40336
|
const chainsArg = opts.chains ?? Object.keys(CHAINS).join(",");
|
|
@@ -40393,8 +40444,8 @@ ${qr3}`;
|
|
|
40393
40444
|
throw new WalletError("CHAIN_UNSUPPORTED", `Unknown chain: ${opts.chain}`);
|
|
40394
40445
|
}
|
|
40395
40446
|
await ensureTrustSDK();
|
|
40396
|
-
const
|
|
40397
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
40447
|
+
const password3 = await resolvePassword(opts);
|
|
40448
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
40398
40449
|
const address = await provider.getAddress(opts.chain);
|
|
40399
40450
|
const signature = await provider.signMessage(opts.chain, opts.message);
|
|
40400
40451
|
output({ chain: opts.chain, address, message: opts.message, signature }, opts.json);
|
|
@@ -40406,8 +40457,8 @@ ${qr3}`;
|
|
|
40406
40457
|
wallet.command("register").description("Register wallet addresses with Trust Wallet backend (enables token holdings)").option("--password <password>", "Wallet password").option("--json", "JSON output").action(async (opts) => {
|
|
40407
40458
|
try {
|
|
40408
40459
|
const creds = await ensureTrustSDK();
|
|
40409
|
-
const
|
|
40410
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
40460
|
+
const password3 = await resolvePassword(opts);
|
|
40461
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
40411
40462
|
await registerWalletWithBackend(creds, provider);
|
|
40412
40463
|
if (!opts.json) success("Wallet registered with backend");
|
|
40413
40464
|
const addresses = await provider.getAddresses();
|
|
@@ -41009,8 +41060,8 @@ function registerTransferCommand(program3) {
|
|
|
41009
41060
|
).option("--json", "JSON output").action(async (opts) => {
|
|
41010
41061
|
try {
|
|
41011
41062
|
await ensureTrustSDK();
|
|
41012
|
-
const
|
|
41013
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
41063
|
+
const password3 = await resolvePassword2(opts);
|
|
41064
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
41014
41065
|
let coinId;
|
|
41015
41066
|
try {
|
|
41016
41067
|
({ coinId } = parseTokenId(opts.token));
|
|
@@ -41236,8 +41287,8 @@ function registerSwapCommand(program3) {
|
|
|
41236
41287
|
let amberDomains = /* @__PURE__ */ new Map();
|
|
41237
41288
|
if (needsWallet) {
|
|
41238
41289
|
await ensureTrustSDK();
|
|
41239
|
-
const
|
|
41240
|
-
provider = await AgentWalletProvider.fromStorage(
|
|
41290
|
+
const password3 = await resolvePassword(opts);
|
|
41291
|
+
provider = await AgentWalletProvider.fromStorage(password3);
|
|
41241
41292
|
walletAddress = await provider.getAddress(fromChain);
|
|
41242
41293
|
if (toChain !== fromChain) {
|
|
41243
41294
|
destinationAddress = await provider.getAddress(toChain);
|
|
@@ -41447,8 +41498,8 @@ function registerErc20Command(program3) {
|
|
|
41447
41498
|
).option("--json", "JSON output").action(async (opts) => {
|
|
41448
41499
|
try {
|
|
41449
41500
|
await ensureTrustSDK();
|
|
41450
|
-
const
|
|
41451
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
41501
|
+
const password3 = await resolvePassword(opts);
|
|
41502
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
41452
41503
|
let coinId;
|
|
41453
41504
|
let contractAddress;
|
|
41454
41505
|
try {
|
|
@@ -41514,8 +41565,8 @@ function registerErc20Command(program3) {
|
|
|
41514
41565
|
).option("--json", "JSON output").action(async (opts) => {
|
|
41515
41566
|
try {
|
|
41516
41567
|
await ensureTrustSDK();
|
|
41517
|
-
const
|
|
41518
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
41568
|
+
const password3 = await resolvePassword(opts);
|
|
41569
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
41519
41570
|
let coinId;
|
|
41520
41571
|
let contractAddress;
|
|
41521
41572
|
try {
|
|
@@ -42090,8 +42141,8 @@ function registerQueryCommand(program3) {
|
|
|
42090
42141
|
}
|
|
42091
42142
|
if (!opts.chain) {
|
|
42092
42143
|
await ensureTrustSDK();
|
|
42093
|
-
const
|
|
42094
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
42144
|
+
const password3 = await resolvePassword(opts);
|
|
42145
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
42095
42146
|
const allAddresses = await provider.getAddresses();
|
|
42096
42147
|
const addresses = allAddresses.map((wa2) => ({
|
|
42097
42148
|
chain: wa2.chainId,
|
|
@@ -42115,8 +42166,8 @@ function registerQueryCommand(program3) {
|
|
|
42115
42166
|
let address = opts.address;
|
|
42116
42167
|
if (!address) {
|
|
42117
42168
|
await ensureTrustSDK();
|
|
42118
|
-
const
|
|
42119
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
42169
|
+
const password3 = await resolvePassword(opts);
|
|
42170
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
42120
42171
|
address = await provider.getAddress(opts.chain);
|
|
42121
42172
|
}
|
|
42122
42173
|
const result = await service.getHistory({
|
|
@@ -42177,8 +42228,8 @@ function registerQueryCommand(program3) {
|
|
|
42177
42228
|
if (!address) {
|
|
42178
42229
|
try {
|
|
42179
42230
|
await ensureTrustSDK();
|
|
42180
|
-
const
|
|
42181
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
42231
|
+
const password3 = await resolvePassword(opts);
|
|
42232
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
42182
42233
|
address = await provider.getAddress(opts.chain);
|
|
42183
42234
|
} catch {
|
|
42184
42235
|
}
|
|
@@ -56907,8 +56958,8 @@ function registerServeCommand(program3) {
|
|
|
56907
56958
|
const blockchainClient = new BlockchainClient();
|
|
56908
56959
|
let agentWallet;
|
|
56909
56960
|
try {
|
|
56910
|
-
const
|
|
56911
|
-
if (
|
|
56961
|
+
const password3 = opts.password || process.env.TWAK_WALLET_PASSWORD || await new KeychainManager().getWalletPassword();
|
|
56962
|
+
if (password3) agentWallet = await AgentWalletProvider.fromStorage(password3);
|
|
56912
56963
|
} catch {
|
|
56913
56964
|
}
|
|
56914
56965
|
let wallet;
|
|
@@ -57080,8 +57131,8 @@ async function resolveWalletAddress(opts, context) {
|
|
|
57080
57131
|
);
|
|
57081
57132
|
}
|
|
57082
57133
|
await ensureTrustSDK();
|
|
57083
|
-
const
|
|
57084
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
57134
|
+
const password3 = await resolvePassword({ password: opts.password });
|
|
57135
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
57085
57136
|
const address = await provider.getAddress(chainKey);
|
|
57086
57137
|
info(`Using ${context} address ${address} on ${chainKey} (derived from your stored wallet).`);
|
|
57087
57138
|
return address;
|
|
@@ -57301,8 +57352,8 @@ ${url}`);
|
|
|
57301
57352
|
).option("--json", "JSON output").action(async (opts) => {
|
|
57302
57353
|
try {
|
|
57303
57354
|
await ensureTrustSDK();
|
|
57304
|
-
const
|
|
57305
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
57355
|
+
const password3 = await resolvePassword({ password: opts.password });
|
|
57356
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
57306
57357
|
let coinId;
|
|
57307
57358
|
try {
|
|
57308
57359
|
({ coinId } = parseTokenId(opts.asset));
|
|
@@ -57701,8 +57752,8 @@ function registerX402Command(program3) {
|
|
|
57701
57752
|
try {
|
|
57702
57753
|
await validateX402Url(url);
|
|
57703
57754
|
await ensureTrustSDK();
|
|
57704
|
-
const
|
|
57705
|
-
const provider = await AgentWalletProvider.fromStorage(
|
|
57755
|
+
const password3 = await resolvePassword3(opts);
|
|
57756
|
+
const provider = await AgentWalletProvider.fromStorage(password3);
|
|
57706
57757
|
const init3 = {
|
|
57707
57758
|
method: opts.method.toUpperCase(),
|
|
57708
57759
|
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
@@ -57826,7 +57877,7 @@ var crypto7 = __toESM(require("crypto"));
|
|
|
57826
57877
|
// package.json
|
|
57827
57878
|
var package_default = {
|
|
57828
57879
|
name: "@trustwallet/cli",
|
|
57829
|
-
version: "0.12.
|
|
57880
|
+
version: "0.12.2",
|
|
57830
57881
|
description: "TWAK CLI \u2014 command-line interface for Trust Wallet Agent Kit",
|
|
57831
57882
|
main: "dist/index.js",
|
|
57832
57883
|
types: "dist/index.d.ts",
|
|
@@ -58034,8 +58085,8 @@ function registerWatchCommand(program3) {
|
|
|
58034
58085
|
swapClient = new SwapClient(client);
|
|
58035
58086
|
if (!opts.dryRun) {
|
|
58036
58087
|
await ensureTrustSDK();
|
|
58037
|
-
const
|
|
58038
|
-
provider = await AgentWalletProvider.fromStorage(
|
|
58088
|
+
const password3 = await resolvePassword(opts);
|
|
58089
|
+
provider = await AgentWalletProvider.fromStorage(password3);
|
|
58039
58090
|
if (opts.autoLock) {
|
|
58040
58091
|
const minutes = parseInt(opts.autoLock, 10);
|
|
58041
58092
|
if (isNaN(minutes) || minutes <= 0) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the comma-separated list of password-strength requirements that
|
|
3
|
+
* `pw` fails to meet (e.g. "include an uppercase letter, include a number"),
|
|
4
|
+
* or null if the password meets every rule.
|
|
5
|
+
*
|
|
6
|
+
* Callers prefix their own framing — e.g. "Password too weak: must <…>.",
|
|
7
|
+
* "Password must <…>.", "TWAK_WALLET_PASSWORD too weak: must <…>." — so each
|
|
8
|
+
* entry point keeps its own user-visible error wording while sharing the
|
|
9
|
+
* rule set.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getPasswordWeaknesses(pw: string): string | null;
|
|
12
|
+
//# sourceMappingURL=password.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../src/password.ts"],"names":[],"mappings":"AAaA;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG/D"}
|
|
@@ -2,6 +2,7 @@ import type { SetupOptions } from './types';
|
|
|
2
2
|
export type WalletChoice = '1' | '2' | '3';
|
|
3
3
|
export interface WalletPrompter {
|
|
4
4
|
selectWalletOption(): Promise<WalletChoice>;
|
|
5
|
+
promptWalletPassword(): Promise<string>;
|
|
5
6
|
}
|
|
6
7
|
export interface WalletCreator {
|
|
7
8
|
create(password: string): Promise<{
|
|
@@ -22,7 +23,6 @@ export interface WalletPhaseDeps {
|
|
|
22
23
|
deleteProbe(): Promise<void>;
|
|
23
24
|
};
|
|
24
25
|
env: NodeJS.ProcessEnv;
|
|
25
|
-
generatePassword: () => string;
|
|
26
26
|
}
|
|
27
27
|
export declare function runWalletPhase(opts: SetupOptions, deps?: WalletPhaseDeps): Promise<void>;
|
|
28
28
|
//# sourceMappingURL=phase-wallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phase-wallet.d.ts","sourceRoot":"","sources":["../../src/setup/phase-wallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"phase-wallet.d.ts","sourceRoot":"","sources":["../../src/setup/phase-wallet.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,MAAM,YAAY,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAI3C,MAAM,WAAW,cAAc;IAC7B,kBAAkB,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;IAM5C,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC/D;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE;QAAE,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;IACxC,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,EAAE;QACR,WAAW,IAAI,OAAO,CAAC;QACvB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAMpD,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACxC,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;QACnC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;KAC9B,CAAC;IACF,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CACxB;AAwFD,wBAAsB,cAAc,CAClC,IAAI,EAAE,YAAY,EAClB,IAAI,GAAE,eAAmC,GACxC,OAAO,CAAC,IAAI,CAAC,CAyBf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustwallet/cli",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "TWAK CLI — command-line interface for Trust Wallet Agent Kit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
"tsup": "8.5.1",
|
|
33
33
|
"typescript": "5.7.3",
|
|
34
34
|
"vitest": "4.1.2",
|
|
35
|
-
"@twak/actions": "0.12.
|
|
36
|
-
"@twak/
|
|
37
|
-
"@twak/
|
|
38
|
-
"@twak/mcp": "0.12.
|
|
39
|
-
"@twak/
|
|
40
|
-
"@twak/
|
|
41
|
-
"@twak/
|
|
42
|
-
"@twak/
|
|
43
|
-
"@twak/
|
|
44
|
-
"@twak/
|
|
45
|
-
"@twak/
|
|
35
|
+
"@twak/actions": "0.12.2",
|
|
36
|
+
"@twak/core": "0.12.2",
|
|
37
|
+
"@twak/blockchain": "0.12.2",
|
|
38
|
+
"@twak/mcp": "0.12.2",
|
|
39
|
+
"@twak/swap": "0.12.2",
|
|
40
|
+
"@twak/wallet": "0.12.2",
|
|
41
|
+
"@twak/transactions": "0.12.2",
|
|
42
|
+
"@twak/wallet-core": "0.12.2",
|
|
43
|
+
"@twak/walletconnect": "0.12.2",
|
|
44
|
+
"@twak/storage": "0.12.2",
|
|
45
|
+
"@twak/security": "0.12.2"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|