@aztec/cli-wallet 0.0.1-commit.e61ad554 → 0.0.1-commit.ee80a48
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/dest/storage/wallet_db.d.ts +1 -1
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +46 -31
- package/package.json +14 -14
- package/src/storage/wallet_db.ts +49 -36
|
@@ -50,4 +50,4 @@ export declare class WalletDB {
|
|
|
50
50
|
}>;
|
|
51
51
|
storeAlias(type: AliasType, key: string, value: Buffer, log: LogFn): Promise<void>;
|
|
52
52
|
}
|
|
53
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
53
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0X2RiLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmFnZS93YWxsZXRfZGIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLEtBQUssRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQ25ELE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFpQixNQUFNLGlCQUFpQixDQUFDO0FBQ3hFLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLDRCQUE0QixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRS9DLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBR3pELGVBQU8sTUFBTSxPQUFPLHdGQUF5RixDQUFDO0FBQzlHL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.d.ts","sourceRoot":"","sources":["../../src/storage/wallet_db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,eAAO,MAAM,OAAO,wFAAyF,CAAC;AAC9G,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjD,qBAAa,QAAQ;;
|
|
1
|
+
{"version":3,"file":"wallet_db.d.ts","sourceRoot":"","sources":["../../src/storage/wallet_db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,eAAO,MAAM,OAAO,wFAAyF,CAAC;AAC9G,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjD,qBAAa,QAAQ;;IAMnB,OAAO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AAM,UAYxC;IAEK,aAAa,CAAC,GAAG,EAAE,MAAM,mBAW9B;IAEK,WAAW,CAAC,IAAI,CAAC,EAAE,SAAS;;;SAWjC;IAEK,oBAAoB,CAAC,cAAc,EAAE,YAAY,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAGtG;IAEK,uBAAuB,CAAC,cAAc,EAAE,YAAY,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,oCAOvF;IAEK,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;;;;;OASnD;IAEK,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,iBAMvE;CACF"}
|
|
@@ -9,6 +9,7 @@ export const Aliases = [
|
|
|
9
9
|
'authwits'
|
|
10
10
|
];
|
|
11
11
|
export class WalletDB {
|
|
12
|
+
#store;
|
|
12
13
|
#accounts;
|
|
13
14
|
#aliases;
|
|
14
15
|
#bridgedFeeJuice;
|
|
@@ -21,6 +22,7 @@ export class WalletDB {
|
|
|
21
22
|
return WalletDB.instance;
|
|
22
23
|
}
|
|
23
24
|
async init(store) {
|
|
25
|
+
this.#store = store;
|
|
24
26
|
this.#accounts = store.openMap('accounts');
|
|
25
27
|
this.#aliases = store.openMap('aliases');
|
|
26
28
|
this.#bridgedFeeJuice = store.openMap('bridgedFeeJuice');
|
|
@@ -33,13 +35,15 @@ export class WalletDB {
|
|
|
33
35
|
]));
|
|
34
36
|
}
|
|
35
37
|
async pushBridgedFeeJuice(recipient, secret, amount, leafIndex, log) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
stackPointer
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
await this.#store.transactionAsync(async ()=>{
|
|
39
|
+
let stackPointer = (await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
|
|
40
|
+
stackPointer++;
|
|
41
|
+
await this.#bridgedFeeJuice.set(`${recipient.toString()}:${stackPointer}`, Buffer.from(`${amount.toString()}:${secret.toString()}:${leafIndex.toString()}`));
|
|
42
|
+
await this.#bridgedFeeJuice.set(`${recipient.toString()}:stackPointer`, Buffer.from([
|
|
43
|
+
stackPointer
|
|
44
|
+
]));
|
|
45
|
+
log(`Pushed ${amount} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
|
|
46
|
+
});
|
|
43
47
|
}
|
|
44
48
|
async popBridgedFeeJuice(recipient, log) {
|
|
45
49
|
let stackPointer = (await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
|
|
@@ -59,17 +63,22 @@ export class WalletDB {
|
|
|
59
63
|
};
|
|
60
64
|
}
|
|
61
65
|
async storeAccount(address, { type, secretKey, salt, alias, publicKey }, log) {
|
|
62
|
-
|
|
63
|
-
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
64
|
-
}
|
|
65
|
-
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
66
|
-
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
67
|
-
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
66
|
+
let publicSigningKey;
|
|
68
67
|
if (type === 'ecdsasecp256r1ssh' && publicKey) {
|
|
69
|
-
|
|
70
|
-
await this.storeAccountMetadata(address, 'publicSigningKey', publicSigningKey);
|
|
68
|
+
publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
|
|
71
69
|
}
|
|
72
|
-
await this.#
|
|
70
|
+
await this.#store.transactionAsync(async ()=>{
|
|
71
|
+
if (alias) {
|
|
72
|
+
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
73
|
+
}
|
|
74
|
+
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
75
|
+
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
76
|
+
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
77
|
+
if (publicSigningKey) {
|
|
78
|
+
await this.#accounts.set(`${address.toString()}:publicSigningKey`, publicSigningKey);
|
|
79
|
+
}
|
|
80
|
+
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
81
|
+
});
|
|
73
82
|
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
74
83
|
await this.refreshAliasCache();
|
|
75
84
|
}
|
|
@@ -79,29 +88,35 @@ export class WalletDB {
|
|
|
79
88
|
await this.refreshAliasCache();
|
|
80
89
|
}
|
|
81
90
|
async storeContract(address, artifactPath, log, alias) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
await this.#store.transactionAsync(async ()=>{
|
|
92
|
+
if (alias) {
|
|
93
|
+
await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
|
|
94
|
+
await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
|
|
95
|
+
}
|
|
96
|
+
await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
|
|
97
|
+
await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
|
|
98
|
+
await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
|
|
99
|
+
});
|
|
89
100
|
log(`Contract stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
90
101
|
await this.refreshAliasCache();
|
|
91
102
|
}
|
|
92
103
|
async storeAuthwitness(authWit, log, alias) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
await this.#store.transactionAsync(async ()=>{
|
|
105
|
+
if (alias) {
|
|
106
|
+
await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
|
|
107
|
+
}
|
|
108
|
+
await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
|
|
109
|
+
});
|
|
97
110
|
log(`Authorization witness stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
98
111
|
await this.refreshAliasCache();
|
|
99
112
|
}
|
|
100
113
|
async storeTx({ txHash }, log, alias) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
114
|
+
await this.#store.transactionAsync(async ()=>{
|
|
115
|
+
if (alias) {
|
|
116
|
+
await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
|
|
117
|
+
}
|
|
118
|
+
await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
|
|
119
|
+
});
|
|
105
120
|
log(`Transaction hash stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
106
121
|
await this.refreshAliasCache();
|
|
107
122
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/cli-wallet",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.ee80a48",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/cmds/index.js",
|
|
@@ -67,19 +67,19 @@
|
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/accounts": "0.0.1-commit.
|
|
71
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
72
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
73
|
-
"@aztec/cli": "0.0.1-commit.
|
|
74
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
75
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
76
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
77
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
78
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
79
|
-
"@aztec/noir-noirc_abi": "0.0.1-commit.
|
|
80
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
81
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
82
|
-
"@aztec/wallet-sdk": "0.0.1-commit.
|
|
70
|
+
"@aztec/accounts": "0.0.1-commit.ee80a48",
|
|
71
|
+
"@aztec/aztec.js": "0.0.1-commit.ee80a48",
|
|
72
|
+
"@aztec/bb.js": "0.0.1-commit.ee80a48",
|
|
73
|
+
"@aztec/cli": "0.0.1-commit.ee80a48",
|
|
74
|
+
"@aztec/entrypoints": "0.0.1-commit.ee80a48",
|
|
75
|
+
"@aztec/ethereum": "0.0.1-commit.ee80a48",
|
|
76
|
+
"@aztec/foundation": "0.0.1-commit.ee80a48",
|
|
77
|
+
"@aztec/kv-store": "0.0.1-commit.ee80a48",
|
|
78
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.ee80a48",
|
|
79
|
+
"@aztec/noir-noirc_abi": "0.0.1-commit.ee80a48",
|
|
80
|
+
"@aztec/pxe": "0.0.1-commit.ee80a48",
|
|
81
|
+
"@aztec/stdlib": "0.0.1-commit.ee80a48",
|
|
82
|
+
"@aztec/wallet-sdk": "0.0.1-commit.ee80a48",
|
|
83
83
|
"commander": "^12.1.0",
|
|
84
84
|
"inquirer": "^10.1.8",
|
|
85
85
|
"source-map-support": "^0.5.21",
|
package/src/storage/wallet_db.ts
CHANGED
|
@@ -12,6 +12,7 @@ export const Aliases = ['accounts', 'contracts', 'artifacts', 'secrets', 'transa
|
|
|
12
12
|
export type AliasType = (typeof Aliases)[number];
|
|
13
13
|
|
|
14
14
|
export class WalletDB {
|
|
15
|
+
#store!: AztecAsyncKVStore;
|
|
15
16
|
#accounts!: AztecAsyncMap<string, Buffer>;
|
|
16
17
|
#aliases!: AztecAsyncMap<string, Buffer>;
|
|
17
18
|
#bridgedFeeJuice!: AztecAsyncMap<string, Buffer>;
|
|
@@ -29,6 +30,7 @@ export class WalletDB {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
async init(store: AztecAsyncKVStore) {
|
|
33
|
+
this.#store = store;
|
|
32
34
|
this.#accounts = store.openMap('accounts');
|
|
33
35
|
this.#aliases = store.openMap('aliases');
|
|
34
36
|
this.#bridgedFeeJuice = store.openMap('bridgedFeeJuice');
|
|
@@ -41,14 +43,17 @@ export class WalletDB {
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
async pushBridgedFeeJuice(recipient: AztecAddress, secret: Fr, amount: bigint, leafIndex: bigint, log: LogFn) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
await this.#store.transactionAsync(async () => {
|
|
47
|
+
let stackPointer =
|
|
48
|
+
(await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
|
|
49
|
+
stackPointer++;
|
|
50
|
+
await this.#bridgedFeeJuice.set(
|
|
51
|
+
`${recipient.toString()}:${stackPointer}`,
|
|
52
|
+
Buffer.from(`${amount.toString()}:${secret.toString()}:${leafIndex.toString()}`),
|
|
53
|
+
);
|
|
54
|
+
await this.#bridgedFeeJuice.set(`${recipient.toString()}:stackPointer`, Buffer.from([stackPointer]));
|
|
55
|
+
log(`Pushed ${amount} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
|
|
56
|
+
});
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
async popBridgedFeeJuice(recipient: AztecAddress, log: LogFn) {
|
|
@@ -76,19 +81,24 @@ export class WalletDB {
|
|
|
76
81
|
}: { type: AccountType; secretKey: Fr; salt: Fr; alias: string | undefined; publicKey: string | undefined },
|
|
77
82
|
log: LogFn,
|
|
78
83
|
) {
|
|
79
|
-
|
|
80
|
-
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
81
|
-
}
|
|
82
|
-
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
83
|
-
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
84
|
-
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
84
|
+
let publicSigningKey: Buffer | undefined;
|
|
85
85
|
if (type === 'ecdsasecp256r1ssh' && publicKey) {
|
|
86
|
-
|
|
87
|
-
await this.storeAccountMetadata(address, 'publicSigningKey', publicSigningKey);
|
|
86
|
+
publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
|
|
88
87
|
}
|
|
89
|
-
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
90
|
-
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
91
88
|
|
|
89
|
+
await this.#store.transactionAsync(async () => {
|
|
90
|
+
if (alias) {
|
|
91
|
+
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
92
|
+
}
|
|
93
|
+
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
94
|
+
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
95
|
+
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
96
|
+
if (publicSigningKey) {
|
|
97
|
+
await this.#accounts.set(`${address.toString()}:publicSigningKey`, publicSigningKey);
|
|
98
|
+
}
|
|
99
|
+
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
100
|
+
});
|
|
101
|
+
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
92
102
|
await this.refreshAliasCache();
|
|
93
103
|
}
|
|
94
104
|
|
|
@@ -100,35 +110,38 @@ export class WalletDB {
|
|
|
100
110
|
}
|
|
101
111
|
|
|
102
112
|
async storeContract(address: AztecAddress, artifactPath: string, log: LogFn, alias?: string) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
await this.#store.transactionAsync(async () => {
|
|
114
|
+
if (alias) {
|
|
115
|
+
await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
|
|
116
|
+
await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
|
|
117
|
+
}
|
|
118
|
+
await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
|
|
119
|
+
await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
|
|
120
|
+
await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
|
|
121
|
+
});
|
|
110
122
|
log(`Contract stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
111
|
-
|
|
112
123
|
await this.refreshAliasCache();
|
|
113
124
|
}
|
|
114
125
|
|
|
115
126
|
async storeAuthwitness(authWit: AuthWitness, log: LogFn, alias?: string) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
await this.#store.transactionAsync(async () => {
|
|
128
|
+
if (alias) {
|
|
129
|
+
await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
|
|
130
|
+
}
|
|
131
|
+
await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
|
|
132
|
+
});
|
|
120
133
|
log(`Authorization witness stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
121
|
-
|
|
122
134
|
await this.refreshAliasCache();
|
|
123
135
|
}
|
|
124
136
|
|
|
125
137
|
async storeTx({ txHash }: { txHash: TxHash }, log: LogFn, alias?: string) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
await this.#store.transactionAsync(async () => {
|
|
139
|
+
if (alias) {
|
|
140
|
+
await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
|
|
141
|
+
}
|
|
142
|
+
await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
|
|
143
|
+
});
|
|
130
144
|
log(`Transaction hash stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
131
|
-
|
|
132
145
|
await this.refreshAliasCache();
|
|
133
146
|
}
|
|
134
147
|
|