@hardkas/accounts 0.11.6-alpha → 0.12.0-rc.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/{authorizers-TYSAH7ZC.js → authorizers-OVWWAL5J.js} +1 -1
- package/dist/{chunk-WXMOC6WN.js → chunk-6Q4K4A24.js} +6 -6
- package/dist/{chunk-ILASLDZU.js → chunk-TRVIQTIO.js} +60 -76
- package/dist/{chunk-3XXJ6UUU.js → chunk-YJL7P33W.js} +2 -2
- package/dist/{dev-accounts-UULCTDJB.js → dev-accounts-B6ZVTPCW.js} +2 -2
- package/dist/index.d.ts +26 -19
- package/dist/index.js +22 -8
- package/dist/{resolve-EXYT2GAC.js → resolve-GHZEED5L.js} +1 -1
- package/package.json +6 -6
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-R5P3WIWR.js";
|
|
4
4
|
import {
|
|
5
5
|
resolveHardkasAccount
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TRVIQTIO.js";
|
|
7
7
|
import {
|
|
8
8
|
loadKaspaWasm
|
|
9
9
|
} from "./chunk-6DPO5V3N.js";
|
|
@@ -24,7 +24,7 @@ var KaspaWasmPrivateKeySigner = class {
|
|
|
24
24
|
this.options = options;
|
|
25
25
|
}
|
|
26
26
|
options;
|
|
27
|
-
kind = "kaspa
|
|
27
|
+
kind = "kaspa";
|
|
28
28
|
async signTxPlan(input) {
|
|
29
29
|
const plan = input.planArtifact;
|
|
30
30
|
const sdk = await loadKaspaWasm(this.options.wasmConfig);
|
|
@@ -56,7 +56,7 @@ var KaspaWasmPrivateKeySigner = class {
|
|
|
56
56
|
if (!pkValue && account.keystorePath) {
|
|
57
57
|
try {
|
|
58
58
|
const KeystoreManager2 = (await import("./keystore-CMWEKGBF.js")).KeystoreManager;
|
|
59
|
-
const DEV_ACCOUNTS_PASSWORD2 = (await import("./dev-accounts-
|
|
59
|
+
const DEV_ACCOUNTS_PASSWORD2 = (await import("./dev-accounts-B6ZVTPCW.js")).DEV_ACCOUNTS_PASSWORD;
|
|
60
60
|
const keystore = await KeystoreManager2.loadEncryptedKeystore(account.keystorePath);
|
|
61
61
|
const unlock = await KeystoreManager2.decryptEncryptedKeystore(keystore, DEV_ACCOUNTS_PASSWORD2);
|
|
62
62
|
if (unlock.success && unlock.payload) {
|
|
@@ -76,7 +76,7 @@ var KaspaWasmPrivateKeySigner = class {
|
|
|
76
76
|
throw err;
|
|
77
77
|
}
|
|
78
78
|
const expectedAddress = new sdk.PrivateKey(pkValue).toKeypair().toAddress(plan.networkId || "simnet").toString();
|
|
79
|
-
const { PrivateKeyAuthorizer } = await import("./authorizers-
|
|
79
|
+
const { PrivateKeyAuthorizer } = await import("./authorizers-OVWWAL5J.js");
|
|
80
80
|
const sourceInputs = plan.inputs || plan.selectedUtxos || [];
|
|
81
81
|
for (let i = 0; i < numInputs; i++) {
|
|
82
82
|
if (!authorizers[i]) {
|
|
@@ -250,7 +250,7 @@ var KaspaWasmPrivateKeySigner = class {
|
|
|
250
250
|
const rpcTx = parseWasmTxToRpc(wasmTxStr, signedTx, inputOverrides, plan);
|
|
251
251
|
const rawTx = JSON.stringify(rpcTx);
|
|
252
252
|
return {
|
|
253
|
-
signatureKind: "kaspa
|
|
253
|
+
signatureKind: "kaspa",
|
|
254
254
|
signerAddress: input.accountName || plan.from.address || "authorized",
|
|
255
255
|
signedTransaction: {
|
|
256
256
|
format: "hex",
|
|
@@ -436,7 +436,7 @@ async function createDevSigner(workspaceDir, accountNameOrAddress) {
|
|
|
436
436
|
nameOrAddress: accountNameOrAddress,
|
|
437
437
|
config: { cwd: workspaceDir }
|
|
438
438
|
});
|
|
439
|
-
if (account.kind !== "kaspa
|
|
439
|
+
if (account.kind !== "kaspa") {
|
|
440
440
|
throw new Error(`Account '${accountNameOrAddress}' is not a private key account, cannot create local dev signer.`);
|
|
441
441
|
}
|
|
442
442
|
return new KaspaWasmPrivateKeySigner({
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import fs2 from "fs";
|
|
3
3
|
import path2 from "path";
|
|
4
4
|
import { createDeterministicAccounts } from "@hardkas/localnet";
|
|
5
|
+
import { CrossWorldAccountCollisionError, AccountNetworkMismatchError } from "@hardkas/core";
|
|
5
6
|
|
|
6
7
|
// src/real-accounts.ts
|
|
7
8
|
import fs from "fs";
|
|
@@ -193,83 +194,37 @@ function resolveRealAccountOrAddress(store, nameOrAddress) {
|
|
|
193
194
|
// src/resolve.ts
|
|
194
195
|
function resolveHardkasAccount(options) {
|
|
195
196
|
const { nameOrAddress, config } = options;
|
|
197
|
+
if (nameOrAddress.startsWith("kaspa:sim_")) {
|
|
198
|
+
return {
|
|
199
|
+
name: nameOrAddress,
|
|
200
|
+
kind: "synthetic",
|
|
201
|
+
executionMode: "simulator",
|
|
202
|
+
address: nameOrAddress
|
|
203
|
+
};
|
|
204
|
+
}
|
|
196
205
|
if (nameOrAddress.startsWith("kaspa:") || nameOrAddress.startsWith("kaspatest:") || nameOrAddress.startsWith("kaspasim:")) {
|
|
206
|
+
let network = "mainnet";
|
|
207
|
+
if (nameOrAddress.startsWith("kaspasim:")) network = "simnet";
|
|
208
|
+
else if (nameOrAddress.startsWith("kaspatest:")) {
|
|
209
|
+
const match = nameOrAddress.match(/^kaspatest:(\d+)_/);
|
|
210
|
+
network = match ? `testnet-${match[1]}` : void 0;
|
|
211
|
+
}
|
|
197
212
|
return {
|
|
198
213
|
name: nameOrAddress,
|
|
199
214
|
kind: "external-wallet",
|
|
215
|
+
...network ? { network } : {},
|
|
200
216
|
address: nameOrAddress
|
|
201
217
|
};
|
|
202
218
|
}
|
|
203
219
|
let alias = nameOrAddress;
|
|
204
220
|
if (alias === "0") alias = "alice";
|
|
205
221
|
if (alias === "1") alias = "bob";
|
|
206
|
-
const
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
"dev-accounts",
|
|
211
|
-
`${alias}.json`
|
|
212
|
-
);
|
|
213
|
-
if (fs2.existsSync(devAccountPath)) {
|
|
214
|
-
try {
|
|
215
|
-
const data = fs2.readFileSync(devAccountPath, "utf-8");
|
|
216
|
-
const keystore = JSON.parse(data);
|
|
217
|
-
if (keystore.type === "hardkas.encryptedKeystore.v2") {
|
|
218
|
-
return {
|
|
219
|
-
name: alias,
|
|
220
|
-
kind: "kaspa-private-key",
|
|
221
|
-
address: keystore.metadata?.address,
|
|
222
|
-
keystorePath: devAccountPath
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
} catch (e) {
|
|
226
|
-
}
|
|
222
|
+
const accounts = listHardkasAccounts(config);
|
|
223
|
+
const found = accounts.find((a) => a.name === alias);
|
|
224
|
+
if (found) {
|
|
225
|
+
return found;
|
|
227
226
|
}
|
|
228
|
-
const
|
|
229
|
-
if (fs2.existsSync(keystoreJsonPath)) {
|
|
230
|
-
try {
|
|
231
|
-
const data = fs2.readFileSync(keystoreJsonPath, "utf-8");
|
|
232
|
-
const ks = JSON.parse(data);
|
|
233
|
-
if (ks[alias]) {
|
|
234
|
-
return {
|
|
235
|
-
name: alias,
|
|
236
|
-
kind: ks[alias].type === "simulated" ? "simulated" : "kaspa-private-key",
|
|
237
|
-
address: ks[alias].address
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
} catch (e) {
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
if (config?.accounts && config.accounts[alias]) {
|
|
244
|
-
const accConfig = config.accounts[alias];
|
|
245
|
-
return {
|
|
246
|
-
name: alias,
|
|
247
|
-
...accConfig
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
const realStore = loadRealAccountStoreSync({ cwd: workspaceRoot });
|
|
251
|
-
const realAcc = realStore ? getRealDevAccount(realStore, alias) : null;
|
|
252
|
-
if (realAcc) {
|
|
253
|
-
return {
|
|
254
|
-
name: realAcc.name,
|
|
255
|
-
kind: "kaspa-private-key",
|
|
256
|
-
// Assuming Kaspa for now, could be extensible
|
|
257
|
-
address: realAcc.address,
|
|
258
|
-
...realAcc.privateKeyEnv ? { privateKeyEnv: realAcc.privateKeyEnv } : {},
|
|
259
|
-
...realAcc.privateKey ? { privateKey: realAcc.privateKey } : {}
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
const detAccounts = createDeterministicAccounts();
|
|
263
|
-
const det = detAccounts.find((a) => a.name === alias);
|
|
264
|
-
if (det) {
|
|
265
|
-
return {
|
|
266
|
-
name: det.name,
|
|
267
|
-
kind: "simulated",
|
|
268
|
-
address: det.address,
|
|
269
|
-
evmAddress: det.evmAddress
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
const available = listHardkasAccounts(config).map((a) => a.name).join(", ");
|
|
227
|
+
const available = accounts.map((a) => a.name).join(", ");
|
|
273
228
|
throw new Error(
|
|
274
229
|
`Unknown HardKAS account '${nameOrAddress}'. Available accounts: ${available}`
|
|
275
230
|
);
|
|
@@ -280,7 +235,8 @@ function listHardkasAccounts(config) {
|
|
|
280
235
|
for (const det of detAccounts) {
|
|
281
236
|
accounts.set(det.name, {
|
|
282
237
|
name: det.name,
|
|
283
|
-
kind: "
|
|
238
|
+
kind: "synthetic",
|
|
239
|
+
executionMode: "simulator",
|
|
284
240
|
address: det.address,
|
|
285
241
|
evmAddress: det.evmAddress
|
|
286
242
|
});
|
|
@@ -296,14 +252,19 @@ function listHardkasAccounts(config) {
|
|
|
296
252
|
const data = fs2.readFileSync(path2.join(devAccountsDir, file), "utf-8");
|
|
297
253
|
const keystore = JSON.parse(data);
|
|
298
254
|
if (keystore.type === "hardkas.encryptedKeystore.v2") {
|
|
255
|
+
if (!keystore.metadata?.network) {
|
|
256
|
+
throw new AccountNetworkMismatchError({ expected: "known network", actual: "undefined", detail: `at ${path2.join(devAccountsDir, file)}` });
|
|
257
|
+
}
|
|
299
258
|
accounts.set(name, {
|
|
300
259
|
name,
|
|
301
|
-
kind: "kaspa
|
|
260
|
+
kind: "kaspa",
|
|
261
|
+
network: keystore.metadata.network,
|
|
302
262
|
address: keystore.payload?.address || keystore.metadata?.address,
|
|
303
263
|
keystorePath: path2.join(devAccountsDir, file)
|
|
304
264
|
});
|
|
305
265
|
}
|
|
306
266
|
} catch (e) {
|
|
267
|
+
if (e instanceof AccountNetworkMismatchError) throw e;
|
|
307
268
|
}
|
|
308
269
|
}
|
|
309
270
|
}
|
|
@@ -314,21 +275,33 @@ function listHardkasAccounts(config) {
|
|
|
314
275
|
const data = fs2.readFileSync(keystoreJsonPath, "utf-8");
|
|
315
276
|
const ks = JSON.parse(data);
|
|
316
277
|
for (const [name, acc] of Object.entries(ks)) {
|
|
278
|
+
const existing = accounts.get(name);
|
|
279
|
+
const configKind = acc.type === "simulated" ? "synthetic" : "kaspa";
|
|
280
|
+
if (existing && existing.kind !== configKind) {
|
|
281
|
+
console.error(`COLLISION DETECTED for ${name}. existing:`, existing, `configKind:`, configKind, `workspaceRoot:`, workspaceRoot, `keystoreJsonPath:`, keystoreJsonPath);
|
|
282
|
+
throw new CrossWorldAccountCollisionError({ accountId: name, worlds: [existing.kind, configKind] });
|
|
283
|
+
}
|
|
317
284
|
if (acc.type === "simulated") {
|
|
318
285
|
accounts.set(name, {
|
|
319
286
|
name,
|
|
320
|
-
kind: "
|
|
287
|
+
kind: "synthetic",
|
|
288
|
+
executionMode: "simulator",
|
|
321
289
|
address: acc.address
|
|
322
290
|
});
|
|
323
291
|
} else {
|
|
292
|
+
if (!acc.network) {
|
|
293
|
+
throw new AccountNetworkMismatchError({ expected: "known network", actual: "undefined", detail: "in keystore.json" });
|
|
294
|
+
}
|
|
324
295
|
accounts.set(name, {
|
|
325
296
|
name,
|
|
326
|
-
kind: "kaspa
|
|
297
|
+
kind: "kaspa",
|
|
298
|
+
network: acc.network,
|
|
327
299
|
address: acc.address
|
|
328
300
|
});
|
|
329
301
|
}
|
|
330
302
|
}
|
|
331
303
|
} catch (e) {
|
|
304
|
+
if (e instanceof CrossWorldAccountCollisionError || e instanceof AccountNetworkMismatchError) throw e;
|
|
332
305
|
}
|
|
333
306
|
}
|
|
334
307
|
const realStore = loadRealAccountStoreSync({ cwd: workspaceRoot });
|
|
@@ -336,7 +309,9 @@ function listHardkasAccounts(config) {
|
|
|
336
309
|
for (const realAcc of listRealDevAccounts(realStore)) {
|
|
337
310
|
accounts.set(realAcc.name, {
|
|
338
311
|
name: realAcc.name,
|
|
339
|
-
kind: "kaspa
|
|
312
|
+
kind: "kaspa",
|
|
313
|
+
network: "simnet",
|
|
314
|
+
// Wait, listRealDevAccounts returns accounts, does it have network? The legacy real store assumed simnet. We'll leave it as simnet for now, or maybe the store should provide it.
|
|
340
315
|
address: realAcc.address,
|
|
341
316
|
...realAcc.privateKeyEnv ? { privateKeyEnv: realAcc.privateKeyEnv } : {},
|
|
342
317
|
...realAcc.privateKey ? { privateKey: realAcc.privateKey } : {}
|
|
@@ -353,15 +328,20 @@ function listHardkasAccounts(config) {
|
|
|
353
328
|
const data = fs2.readFileSync(path2.join(keystoreDir, file), "utf-8");
|
|
354
329
|
const keystore = JSON.parse(data);
|
|
355
330
|
if (keystore.type === "hardkas.encryptedKeystore.v2") {
|
|
331
|
+
if (!keystore.metadata?.network) {
|
|
332
|
+
throw new AccountNetworkMismatchError({ expected: "known network", actual: "undefined", detail: `at ${path2.join(keystoreDir, file)}` });
|
|
333
|
+
}
|
|
356
334
|
accounts.set(name, {
|
|
357
335
|
name,
|
|
358
|
-
kind: "kaspa
|
|
336
|
+
kind: "kaspa",
|
|
337
|
+
network: keystore.metadata.network,
|
|
359
338
|
address: keystore.payload?.address || keystore.metadata?.address,
|
|
360
339
|
// Payloads are encrypted, but address might be in metadata
|
|
361
340
|
keystorePath: path2.join(keystoreDir, file)
|
|
362
341
|
});
|
|
363
342
|
}
|
|
364
343
|
} catch (e) {
|
|
344
|
+
if (e instanceof AccountNetworkMismatchError) throw e;
|
|
365
345
|
}
|
|
366
346
|
}
|
|
367
347
|
}
|
|
@@ -369,12 +349,16 @@ function listHardkasAccounts(config) {
|
|
|
369
349
|
if (config?.accounts) {
|
|
370
350
|
for (const [name, accConfig] of Object.entries(config.accounts)) {
|
|
371
351
|
const existing = accounts.get(name);
|
|
372
|
-
|
|
373
|
-
|
|
352
|
+
const configKind = accConfig.kind === "simulated" ? "synthetic" : accConfig.kind;
|
|
353
|
+
if (existing && existing.kind !== configKind) {
|
|
354
|
+
console.error(`COLLISION DETECTED for ${name}. existing:`, existing, `configKind:`, configKind);
|
|
355
|
+
throw new CrossWorldAccountCollisionError({ accountId: name, worlds: [existing.kind, configKind] });
|
|
374
356
|
}
|
|
375
357
|
accounts.set(name, {
|
|
376
358
|
name,
|
|
377
|
-
...accConfig
|
|
359
|
+
...accConfig,
|
|
360
|
+
kind: configKind,
|
|
361
|
+
...configKind === "synthetic" ? { executionMode: "simulator" } : {}
|
|
378
362
|
});
|
|
379
363
|
}
|
|
380
364
|
}
|
|
@@ -441,7 +425,7 @@ function describeAccount(account) {
|
|
|
441
425
|
if (account.address) {
|
|
442
426
|
desc.address = account.address;
|
|
443
427
|
}
|
|
444
|
-
if (account.kind === "kaspa
|
|
428
|
+
if (account.kind === "kaspa" || account.kind === "evm-private-key") {
|
|
445
429
|
desc.privateKeyEnv = account.privateKeyEnv;
|
|
446
430
|
}
|
|
447
431
|
if (account.kind === "external-wallet" && account.walletId) {
|
|
@@ -63,7 +63,7 @@ var LazyAccountAuthorizer = class {
|
|
|
63
63
|
accountName;
|
|
64
64
|
workspaceRoot;
|
|
65
65
|
async authorize(context) {
|
|
66
|
-
const { resolveHardkasAccount } = await import("./resolve-
|
|
66
|
+
const { resolveHardkasAccount } = await import("./resolve-GHZEED5L.js");
|
|
67
67
|
const account = await resolveHardkasAccount({
|
|
68
68
|
nameOrAddress: this.accountName,
|
|
69
69
|
config: { cwd: this.workspaceRoot }
|
|
@@ -75,7 +75,7 @@ var LazyAccountAuthorizer = class {
|
|
|
75
75
|
if (!pkValue && account.keystorePath) {
|
|
76
76
|
try {
|
|
77
77
|
const { KeystoreManager } = await import("./keystore-CMWEKGBF.js");
|
|
78
|
-
const { DEV_ACCOUNTS_PASSWORD } = await import("./dev-accounts-
|
|
78
|
+
const { DEV_ACCOUNTS_PASSWORD } = await import("./dev-accounts-B6ZVTPCW.js");
|
|
79
79
|
const keystore = await KeystoreManager.loadEncryptedKeystore(account.keystorePath);
|
|
80
80
|
const unlock = await KeystoreManager.decryptEncryptedKeystore(keystore, DEV_ACCOUNTS_PASSWORD);
|
|
81
81
|
if (unlock.success && unlock.payload) {
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
ensureDevAccounts,
|
|
5
5
|
getOrCreateDevAccount,
|
|
6
6
|
listDevAccountsSync
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-6Q4K4A24.js";
|
|
8
8
|
import "./chunk-R5P3WIWR.js";
|
|
9
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-TRVIQTIO.js";
|
|
10
10
|
import "./chunk-6DPO5V3N.js";
|
|
11
11
|
import "./chunk-YLG2NIAU.js";
|
|
12
12
|
export {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TxPlanArtifact, SignedTxArtifact, HardkasArtifactBase } from '@hardkas/artifacts';
|
|
2
2
|
import { HardkasConfig } from '@hardkas/config';
|
|
3
|
+
import * as _hardkas_core from '@hardkas/core';
|
|
3
4
|
import { NetworkId } from '@hardkas/core';
|
|
4
5
|
import { TxPlan } from '@hardkas/tx-builder';
|
|
5
6
|
|
|
@@ -40,7 +41,7 @@ declare class LazyAccountAuthorizer implements TxInputAuthorizer {
|
|
|
40
41
|
authorize(context: TxInputAuthorizationContext): Promise<InputAuthorization>;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
type HardkasAccountKind = "
|
|
44
|
+
type HardkasAccountKind = "synthetic" | "kaspa" | "external-wallet" | "evm-private-key";
|
|
44
45
|
interface KeystorePayload {
|
|
45
46
|
address: string;
|
|
46
47
|
privateKey: string;
|
|
@@ -87,29 +88,33 @@ interface HardkasBaseAccount {
|
|
|
87
88
|
kind: HardkasAccountKind;
|
|
88
89
|
address?: string;
|
|
89
90
|
}
|
|
90
|
-
interface
|
|
91
|
-
kind: "
|
|
91
|
+
interface HardkasSyntheticAccount extends HardkasBaseAccount {
|
|
92
|
+
kind: "synthetic";
|
|
93
|
+
executionMode: "simulator";
|
|
92
94
|
address: string;
|
|
93
95
|
evmAddress?: string;
|
|
94
96
|
}
|
|
95
|
-
interface
|
|
96
|
-
kind: "kaspa
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
interface HardkasKaspaAccount extends HardkasBaseAccount {
|
|
98
|
+
kind: "kaspa";
|
|
99
|
+
network: "simnet" | "testnet-10" | "testnet-11" | "mainnet" | string;
|
|
100
|
+
privateKeyEnv?: string;
|
|
101
|
+
privateKey?: string;
|
|
102
|
+
keystorePath?: string;
|
|
103
|
+
address: string;
|
|
100
104
|
}
|
|
101
105
|
interface HardkasExternalWalletAccount extends HardkasBaseAccount {
|
|
102
106
|
kind: "external-wallet";
|
|
107
|
+
network?: "simnet" | "testnet-10" | "testnet-11" | "mainnet" | string;
|
|
103
108
|
walletId?: string;
|
|
104
109
|
address?: string;
|
|
105
110
|
}
|
|
106
111
|
interface HardkasEvmPrivateKeyAccount extends HardkasBaseAccount {
|
|
107
112
|
kind: "evm-private-key";
|
|
108
|
-
privateKeyEnv?: string
|
|
113
|
+
privateKeyEnv?: string;
|
|
109
114
|
address?: string;
|
|
110
115
|
}
|
|
111
|
-
type HardkasAccount =
|
|
112
|
-
type HardkasSignerKind = "
|
|
116
|
+
type HardkasAccount = HardkasSyntheticAccount | HardkasKaspaAccount | HardkasExternalWalletAccount | HardkasEvmPrivateKeyAccount;
|
|
117
|
+
type HardkasSignerKind = "synthetic" | "kaspa" | "external-wallet" | "unsupported";
|
|
113
118
|
|
|
114
119
|
interface SignTxPlanInput {
|
|
115
120
|
planArtifact: any;
|
|
@@ -138,8 +143,8 @@ interface HardkasSigner<TTx = unknown, TSignedTx = unknown> {
|
|
|
138
143
|
}
|
|
139
144
|
|
|
140
145
|
declare class SimulatedSigner implements HardkasSigner {
|
|
141
|
-
readonly account:
|
|
142
|
-
constructor(account:
|
|
146
|
+
readonly account: HardkasSyntheticAccount;
|
|
147
|
+
constructor(account: HardkasSyntheticAccount);
|
|
143
148
|
signTransaction(tx: unknown): Promise<unknown>;
|
|
144
149
|
}
|
|
145
150
|
|
|
@@ -184,6 +189,7 @@ declare class UnsupportedRealKaspaSigner implements HardkasTxPlanSigner {
|
|
|
184
189
|
* Main entry point for signing transaction plan artifacts.
|
|
185
190
|
*/
|
|
186
191
|
declare function signTxPlanArtifact(input: {
|
|
192
|
+
target: _hardkas_core.HardkasExecutionTarget;
|
|
187
193
|
planArtifact: TxPlanArtifact;
|
|
188
194
|
account?: HardkasAccount;
|
|
189
195
|
authorizers?: Readonly<Record<number, TxInputAuthorizer>>;
|
|
@@ -248,6 +254,11 @@ interface CreateKaspaWalletOptions {
|
|
|
248
254
|
*/
|
|
249
255
|
declare function createLocalKaspaWallet(options?: CreateKaspaWalletOptions): Promise<GeneratedKaspaDevAccount>;
|
|
250
256
|
|
|
257
|
+
interface KaspaWasmSignerOptions {
|
|
258
|
+
account?: HardkasKaspaAccount;
|
|
259
|
+
allowMainnet?: boolean;
|
|
260
|
+
wasmConfig?: WasmProviderConfig;
|
|
261
|
+
}
|
|
251
262
|
/**
|
|
252
263
|
* Real Kaspa signer using the official WASM SDK.
|
|
253
264
|
* Only works if the 'kaspa' package is installed.
|
|
@@ -255,11 +266,7 @@ declare function createLocalKaspaWallet(options?: CreateKaspaWalletOptions): Pro
|
|
|
255
266
|
declare class KaspaWasmPrivateKeySigner implements HardkasTxPlanSigner {
|
|
256
267
|
private options;
|
|
257
268
|
kind: HardkasSignerKind;
|
|
258
|
-
constructor(options:
|
|
259
|
-
account?: HardkasKaspaPrivateKeyAccount;
|
|
260
|
-
allowMainnet?: boolean | undefined;
|
|
261
|
-
wasmConfig?: WasmProviderConfig;
|
|
262
|
-
});
|
|
269
|
+
constructor(options: KaspaWasmSignerOptions);
|
|
263
270
|
signTxPlan(input: SignTxPlanInput): Promise<SignTxPlanResult>;
|
|
264
271
|
}
|
|
265
272
|
/**
|
|
@@ -558,4 +565,4 @@ declare class WalletStateStoreJson {
|
|
|
558
565
|
nextChangeIndex(walletId: string): number;
|
|
559
566
|
}
|
|
560
567
|
|
|
561
|
-
export { AddressManager, type ChainType, type CreateKaspaWalletOptions, DEV_ACCOUNTS_PASSWORD, type DeriveRequest, type DerivedAddress, type EncryptedKeystoreV2, type EvmExportResult, type GeneratedKaspaDevAccount, type HardkasAccount, type HardkasAccountKind, type HardkasBaseAccount, type HardkasEvmPrivateKeyAccount, type HardkasExternalWalletAccount, type
|
|
568
|
+
export { AddressManager, type ChainType, type CreateKaspaWalletOptions, DEV_ACCOUNTS_PASSWORD, type DeriveRequest, type DerivedAddress, type EncryptedKeystoreV2, type EvmExportResult, type GeneratedKaspaDevAccount, type HardkasAccount, type HardkasAccountKind, type HardkasBaseAccount, type HardkasEvmPrivateKeyAccount, type HardkasExternalWalletAccount, type HardkasKaspaAccount, type HardkasSigner, type HardkasSignerKind, type HardkasSyntheticAccount, type HardkasTxPlanSigner, type HelperDeriveRequest, type InputAuthorization, type KaspaKeyGenerator, KaspaSdkKeyGenerator, type KaspaSdkKeyGeneratorOptions, KaspaSdkRealTxSigner, type KaspaSdkRealTxSignerOptions, type KaspaSigningBackendStatus, KaspaWasmPrivateKeySigner, type KaspaWasmSignerOptions, type KeystoreCipherParams, type KeystoreKdfParams, KeystoreManager, type KeystorePayload, type KeystoreUnlockResult, LazyAccountAuthorizer, type NetworkType, type PathRequest, PrivateKeyAuthorizer, type RealAccountStore, type RealDevAccount, type RealTxSigner, type RealTxSigningInput, type RealTxSigningResult, type ResolveAccountOptions, type SignTxPlanInput, type SignTxPlanResult, SimulatedSigner, StaticSignatureScriptAuthorizer, type TxInputAuthorizationContext, type TxInputAuthorizer, UnsupportedKaspaKeyGenerator, UnsupportedRealKaspaSigner, UnsupportedRealTxSigner, type WalletArtifact, type WalletClaims, type WalletCreateRequest, type WalletImportRequest, WalletManager, WalletManagerImpl, type WalletMetadata, type WalletState, WalletStateStoreJson, type WalletStateStoreOptions, type WasmInputSigner, type WasmProviderConfig, appendToKeystoreJson, assertSigningNetworkAllowed, createDevSigner, createEmptyRealAccountStore, createLocalKaspaWallet, describeAccount, detectCapabilities, ensureDevAccounts, getDefaultRealAccountsPath, getKaspaSigningBackendStatus, getOrCreateDevAccount, getRealDevAccount, getRequiredEnv, importRealDevAccount, listDevAccountsSync, listHardkasAccounts, listRealDevAccounts, loadKaspaWasm, loadOrCreateRealAccountStore, loadRealAccountStore, loadRealAccountStoreSync, prepareEvmAccountExport, removeRealDevAccount, resolveHardkasAccount, resolveHardkasAccountAddress, resolveRealAccountOrAddress, saveRealAccountStore, signTxPlanArtifact, validateAccountName, validateAddressNetwork, validateAddressPrefix, withKeystoreLock };
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
ensureDevAccounts,
|
|
7
7
|
getOrCreateDevAccount,
|
|
8
8
|
listDevAccountsSync
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-6Q4K4A24.js";
|
|
10
10
|
import "./chunk-R5P3WIWR.js";
|
|
11
11
|
import {
|
|
12
12
|
createEmptyRealAccountStore,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
validateAccountName,
|
|
28
28
|
validateAddressNetwork,
|
|
29
29
|
validateAddressPrefix
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-TRVIQTIO.js";
|
|
31
31
|
import {
|
|
32
32
|
detectCapabilities,
|
|
33
33
|
getKaspaSigningBackendStatus,
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
LazyAccountAuthorizer,
|
|
41
41
|
PrivateKeyAuthorizer,
|
|
42
42
|
StaticSignatureScriptAuthorizer
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-YJL7P33W.js";
|
|
44
44
|
|
|
45
45
|
// src/simulated.ts
|
|
46
46
|
var SimulatedSigner = class {
|
|
@@ -134,13 +134,26 @@ var UnsupportedRealKaspaSigner = class {
|
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
async function signTxPlanArtifact(input) {
|
|
137
|
-
const { planArtifact, account, authorizers } = input;
|
|
137
|
+
const { target, planArtifact, account, authorizers } = input;
|
|
138
138
|
const planRecord = planArtifact;
|
|
139
139
|
if (planArtifact.schema === "hardkas.txPlan") {
|
|
140
140
|
} else if (planRecord.status !== "built" && planRecord.status !== "unsigned") {
|
|
141
141
|
throw new Error(`Cannot sign artifact with status: ${planRecord.status}`);
|
|
142
142
|
}
|
|
143
|
-
|
|
143
|
+
const { assertExecutionCompatibility } = await import("@hardkas/core");
|
|
144
|
+
assertExecutionCompatibility({
|
|
145
|
+
operation: "sign",
|
|
146
|
+
target,
|
|
147
|
+
...account ? {
|
|
148
|
+
account: {
|
|
149
|
+
kind: account.kind,
|
|
150
|
+
...account.network ? { network: account.network } : {},
|
|
151
|
+
...account.executionMode ? { executionMode: account.executionMode } : {}
|
|
152
|
+
}
|
|
153
|
+
} : {},
|
|
154
|
+
artifact: { execution: planArtifact.execution }
|
|
155
|
+
});
|
|
156
|
+
if (planArtifact.mode === "simulator") {
|
|
144
157
|
return createSimulatedSignedTxArtifact(
|
|
145
158
|
planArtifact,
|
|
146
159
|
`simulated-signed-tx:${planArtifact.planId}`,
|
|
@@ -152,12 +165,12 @@ async function signTxPlanArtifact(input) {
|
|
|
152
165
|
"Mainnet signing is disabled by default. Use --allow-mainnet-signing only if you understand the risks."
|
|
153
166
|
);
|
|
154
167
|
}
|
|
155
|
-
if (account && account.kind === "
|
|
168
|
+
if (account && account.kind === "synthetic") {
|
|
156
169
|
throw new Error(
|
|
157
|
-
`Real Kaspa transaction plans (mode: ${planArtifact.mode}) cannot be signed with
|
|
170
|
+
`Real Kaspa transaction plans (mode: ${planArtifact.mode}) cannot be signed with synthetic accounts.`
|
|
158
171
|
);
|
|
159
172
|
}
|
|
160
|
-
if (!account || account.kind === "kaspa
|
|
173
|
+
if (!account || account.kind === "kaspa" || typeof account.authorize === "function") {
|
|
161
174
|
const status = await getKaspaSigningBackendStatus(input.config?.wasm);
|
|
162
175
|
if (!status.available) {
|
|
163
176
|
throw new Error(
|
|
@@ -196,6 +209,7 @@ async function signTxPlanArtifact(input) {
|
|
|
196
209
|
payload: result.signedTransaction?.payload || ""
|
|
197
210
|
},
|
|
198
211
|
lineage: createLineageTransition(planArtifact, "hardkas.signedTx"),
|
|
212
|
+
...planArtifact.execution ? { execution: planArtifact.execution } : {},
|
|
199
213
|
...planArtifact.workflowId ? { workflowId: planArtifact.workflowId } : {},
|
|
200
214
|
...planArtifact.assumptionLevel ? { assumptionLevel: planArtifact.assumptionLevel } : {},
|
|
201
215
|
...planArtifact.policyRefs ? { policyRefs: planArtifact.policyRefs } : {},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/accounts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0-rc.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"hash-wasm": "^4.12.0",
|
|
26
26
|
"kaspa-wasm": "0.13.0",
|
|
27
|
-
"@hardkas/artifacts": "0.
|
|
28
|
-
"@hardkas/core": "0.
|
|
29
|
-
"@hardkas/config": "0.
|
|
30
|
-
"@hardkas/tx-builder": "0.
|
|
31
|
-
"@hardkas/localnet": "0.
|
|
27
|
+
"@hardkas/artifacts": "0.12.0-rc.2",
|
|
28
|
+
"@hardkas/core": "0.12.0-rc.2",
|
|
29
|
+
"@hardkas/config": "0.12.0-rc.2",
|
|
30
|
+
"@hardkas/tx-builder": "0.12.0-rc.2",
|
|
31
|
+
"@hardkas/localnet": "0.12.0-rc.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"tsup": "^8.3.5",
|