@hardkas/accounts 0.11.6-alpha → 0.12.0-rc.10

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.
@@ -2,7 +2,8 @@ import {
2
2
  LazyAccountAuthorizer,
3
3
  PrivateKeyAuthorizer,
4
4
  StaticSignatureScriptAuthorizer
5
- } from "./chunk-3XXJ6UUU.js";
5
+ } from "./chunk-5WYALW6N.js";
6
+ import "./chunk-MCKGQKYU.js";
6
7
  export {
7
8
  LazyAccountAuthorizer,
8
9
  PrivateKeyAuthorizer,
@@ -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,97 +194,76 @@ 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 workspaceRoot = config?.cwd || process.cwd();
207
- const devAccountPath = path2.join(
208
- workspaceRoot,
209
- ".hardkas",
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
- }
227
- }
228
- const keystoreJsonPath = path2.join(workspaceRoot, ".hardkas", "keystore.json");
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
- }
222
+ const accounts = listHardkasAccounts(config);
223
+ const found = accounts.find((a) => a.name === alias);
224
+ if (found) {
225
+ return found;
242
226
  }
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
  );
276
231
  }
277
232
  function listHardkasAccounts(config) {
278
233
  const accounts = /* @__PURE__ */ new Map();
234
+ let targetMode = "localnet";
235
+ const execConfig = config?.execution;
236
+ if (execConfig) {
237
+ if (execConfig.mode) {
238
+ targetMode = execConfig.mode;
239
+ } else if (execConfig.default) {
240
+ const targetName = execConfig.default;
241
+ const target = execConfig.targets?.[targetName];
242
+ if (target?.mode) {
243
+ targetMode = target.mode;
244
+ } else if (targetName === "simulator") {
245
+ targetMode = "simulator";
246
+ }
247
+ }
248
+ }
279
249
  const detAccounts = createDeterministicAccounts();
280
250
  for (const det of detAccounts) {
281
- accounts.set(det.name, {
282
- name: det.name,
283
- kind: "simulated",
284
- address: det.address,
285
- evmAddress: det.evmAddress
286
- });
251
+ if (targetMode === "simulator") {
252
+ accounts.set(det.name, {
253
+ name: det.name,
254
+ kind: "synthetic",
255
+ executionMode: "simulator",
256
+ address: det.address,
257
+ evmAddress: det.evmAddress
258
+ });
259
+ } else {
260
+ accounts.set(det.name, {
261
+ name: det.name,
262
+ kind: "kaspa",
263
+ network: "simnet",
264
+ address: det.address
265
+ });
266
+ }
287
267
  }
288
268
  const workspaceRoot = config?.cwd || process.cwd();
289
269
  const devAccountsDir = path2.join(workspaceRoot, ".hardkas", "dev-accounts");
@@ -296,14 +276,19 @@ function listHardkasAccounts(config) {
296
276
  const data = fs2.readFileSync(path2.join(devAccountsDir, file), "utf-8");
297
277
  const keystore = JSON.parse(data);
298
278
  if (keystore.type === "hardkas.encryptedKeystore.v2") {
279
+ if (!keystore.metadata?.network) {
280
+ throw new AccountNetworkMismatchError({ expected: "known network", actual: "undefined", detail: `at ${path2.join(devAccountsDir, file)}` });
281
+ }
299
282
  accounts.set(name, {
300
283
  name,
301
- kind: "kaspa-private-key",
284
+ kind: "kaspa",
285
+ network: keystore.metadata.network,
302
286
  address: keystore.payload?.address || keystore.metadata?.address,
303
287
  keystorePath: path2.join(devAccountsDir, file)
304
288
  });
305
289
  }
306
290
  } catch (e) {
291
+ if (e instanceof AccountNetworkMismatchError) throw e;
307
292
  }
308
293
  }
309
294
  }
@@ -314,21 +299,33 @@ function listHardkasAccounts(config) {
314
299
  const data = fs2.readFileSync(keystoreJsonPath, "utf-8");
315
300
  const ks = JSON.parse(data);
316
301
  for (const [name, acc] of Object.entries(ks)) {
302
+ const existing = accounts.get(name);
303
+ const configKind = acc.type === "simulated" ? "synthetic" : "kaspa";
304
+ if (existing && existing.kind !== configKind) {
305
+ console.error(`COLLISION DETECTED for ${name}. existing:`, existing, `configKind:`, configKind, `workspaceRoot:`, workspaceRoot, `keystoreJsonPath:`, keystoreJsonPath);
306
+ throw new CrossWorldAccountCollisionError({ accountId: name, worlds: [existing.kind, configKind] });
307
+ }
317
308
  if (acc.type === "simulated") {
318
309
  accounts.set(name, {
319
310
  name,
320
- kind: "simulated",
311
+ kind: "synthetic",
312
+ executionMode: "simulator",
321
313
  address: acc.address
322
314
  });
323
315
  } else {
316
+ if (!acc.network) {
317
+ throw new AccountNetworkMismatchError({ expected: "known network", actual: "undefined", detail: "in keystore.json" });
318
+ }
324
319
  accounts.set(name, {
325
320
  name,
326
- kind: "kaspa-private-key",
321
+ kind: "kaspa",
322
+ network: acc.network,
327
323
  address: acc.address
328
324
  });
329
325
  }
330
326
  }
331
327
  } catch (e) {
328
+ if (e instanceof CrossWorldAccountCollisionError || e instanceof AccountNetworkMismatchError) throw e;
332
329
  }
333
330
  }
334
331
  const realStore = loadRealAccountStoreSync({ cwd: workspaceRoot });
@@ -336,7 +333,9 @@ function listHardkasAccounts(config) {
336
333
  for (const realAcc of listRealDevAccounts(realStore)) {
337
334
  accounts.set(realAcc.name, {
338
335
  name: realAcc.name,
339
- kind: "kaspa-private-key",
336
+ kind: "kaspa",
337
+ network: "simnet",
338
+ // 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
339
  address: realAcc.address,
341
340
  ...realAcc.privateKeyEnv ? { privateKeyEnv: realAcc.privateKeyEnv } : {},
342
341
  ...realAcc.privateKey ? { privateKey: realAcc.privateKey } : {}
@@ -353,15 +352,20 @@ function listHardkasAccounts(config) {
353
352
  const data = fs2.readFileSync(path2.join(keystoreDir, file), "utf-8");
354
353
  const keystore = JSON.parse(data);
355
354
  if (keystore.type === "hardkas.encryptedKeystore.v2") {
355
+ if (!keystore.metadata?.network) {
356
+ throw new AccountNetworkMismatchError({ expected: "known network", actual: "undefined", detail: `at ${path2.join(keystoreDir, file)}` });
357
+ }
356
358
  accounts.set(name, {
357
359
  name,
358
- kind: "kaspa-private-key",
360
+ kind: "kaspa",
361
+ network: keystore.metadata.network,
359
362
  address: keystore.payload?.address || keystore.metadata?.address,
360
363
  // Payloads are encrypted, but address might be in metadata
361
364
  keystorePath: path2.join(keystoreDir, file)
362
365
  });
363
366
  }
364
367
  } catch (e) {
368
+ if (e instanceof AccountNetworkMismatchError) throw e;
365
369
  }
366
370
  }
367
371
  }
@@ -369,12 +373,16 @@ function listHardkasAccounts(config) {
369
373
  if (config?.accounts) {
370
374
  for (const [name, accConfig] of Object.entries(config.accounts)) {
371
375
  const existing = accounts.get(name);
372
- if (existing && existing.kind === "kaspa-private-key" && accConfig.kind === "simulated") {
373
- continue;
376
+ const configKind = accConfig.kind === "simulated" ? "synthetic" : accConfig.kind;
377
+ if (existing && existing.kind !== configKind) {
378
+ console.error(`COLLISION DETECTED for ${name}. existing:`, existing, `configKind:`, configKind);
379
+ throw new CrossWorldAccountCollisionError({ accountId: name, worlds: [existing.kind, configKind] });
374
380
  }
375
381
  accounts.set(name, {
376
382
  name,
377
- ...accConfig
383
+ ...accConfig,
384
+ kind: configKind,
385
+ ...configKind === "synthetic" ? { executionMode: "simulator" } : {}
378
386
  });
379
387
  }
380
388
  }
@@ -441,7 +449,7 @@ function describeAccount(account) {
441
449
  if (account.address) {
442
450
  desc.address = account.address;
443
451
  }
444
- if (account.kind === "kaspa-private-key" || account.kind === "evm-private-key") {
452
+ if (account.kind === "kaspa" || account.kind === "evm-private-key") {
445
453
  desc.privateKeyEnv = account.privateKeyEnv;
446
454
  }
447
455
  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-EXYT2GAC.js");
66
+ const { resolveHardkasAccount } = await import("./resolve-LNOAVBLS.js");
67
67
  const account = await resolveHardkasAccount({
68
68
  nameOrAddress: this.accountName,
69
69
  config: { cwd: this.workspaceRoot }
@@ -74,8 +74,8 @@ var LazyAccountAuthorizer = class {
74
74
  }
75
75
  if (!pkValue && account.keystorePath) {
76
76
  try {
77
- const { KeystoreManager } = await import("./keystore-CMWEKGBF.js");
78
- const { DEV_ACCOUNTS_PASSWORD } = await import("./dev-accounts-UULCTDJB.js");
77
+ const { KeystoreManager } = await import("./keystore-2KRHVGCM.js");
78
+ const { DEV_ACCOUNTS_PASSWORD } = await import("./dev-accounts-IIHQSSO2.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) {
@@ -0,0 +1,15 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+ var __commonJS = (cb, mod) => function __require2() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+
12
+ export {
13
+ __require,
14
+ __commonJS
15
+ };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-R5P3WIWR.js";
4
4
  import {
5
5
  resolveHardkasAccount
6
- } from "./chunk-ILASLDZU.js";
6
+ } from "./chunk-23LEGEIY.js";
7
7
  import {
8
8
  loadKaspaWasm
9
9
  } from "./chunk-6DPO5V3N.js";
@@ -24,11 +24,11 @@ var KaspaWasmPrivateKeySigner = class {
24
24
  this.options = options;
25
25
  }
26
26
  options;
27
- kind = "kaspa-private-key";
27
+ kind = "kaspa";
28
28
  async signTxPlan(input) {
29
29
  const plan = input.planArtifact;
30
30
  const sdk = await loadKaspaWasm(this.options.wasmConfig);
31
- const { detectCapabilities } = await import("./signer-backend-W3LNCQA3.js");
31
+ const { detectCapabilities } = await import("./signer-backend-X3FD3XMB.js");
32
32
  const capabilities = detectCapabilities(sdk);
33
33
  if (plan.computeBudget !== void 0 || plan.outputs.some((o) => o.covenant)) {
34
34
  if (!capabilities.transactionV1Signing) {
@@ -55,8 +55,8 @@ var KaspaWasmPrivateKeySigner = class {
55
55
  }
56
56
  if (!pkValue && account.keystorePath) {
57
57
  try {
58
- const KeystoreManager2 = (await import("./keystore-CMWEKGBF.js")).KeystoreManager;
59
- const DEV_ACCOUNTS_PASSWORD2 = (await import("./dev-accounts-UULCTDJB.js")).DEV_ACCOUNTS_PASSWORD;
58
+ const KeystoreManager2 = (await import("./keystore-2KRHVGCM.js")).KeystoreManager;
59
+ const DEV_ACCOUNTS_PASSWORD2 = (await import("./dev-accounts-IIHQSSO2.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-TYSAH7ZC.js");
79
+ const { PrivateKeyAuthorizer } = await import("./authorizers-NEWT33BI.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-private-key",
253
+ signatureKind: "kaspa",
254
254
  signerAddress: input.accountName || plan.from.address || "authorized",
255
255
  signedTransaction: {
256
256
  format: "hex",
@@ -341,7 +341,7 @@ async function getOrCreateDevAccount(workspaceDir, index, alias) {
341
341
  try {
342
342
  sdkModule = await import(
343
343
  /* @vite-ignore */
344
- "@kaspa/core-lib"
344
+ "./core-lib-2VZIZ7XT.js"
345
345
  );
346
346
  } catch (e) {
347
347
  console.warn(`
@@ -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-private-key") {
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({