@hardkas/accounts 0.9.0-alpha → 0.9.2-alpha

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.
Files changed (2) hide show
  1. package/dist/index.js +53 -25
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -79,7 +79,7 @@ function loadRealAccountStoreSync(options) {
79
79
  return store;
80
80
  } catch (e) {
81
81
  throw new Error(
82
- `Failed to load real account store at ${filePath}: ${e instanceof Error ? e.message : String(e)}`
82
+ `Failed to load real account store at ${filePath}: ${e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e)}`
83
83
  );
84
84
  }
85
85
  }
@@ -102,7 +102,7 @@ async function saveRealAccountStore(store, options) {
102
102
  });
103
103
  } catch (e) {
104
104
  throw new Error(
105
- `Failed to save real account store at ${filePath}: ${e instanceof Error ? e.message : String(e)}`
105
+ `Failed to save real account store at ${filePath}: ${e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e)}`
106
106
  );
107
107
  }
108
108
  }
@@ -124,7 +124,9 @@ function validateAddressPrefix(address) {
124
124
  const validPrefixes = ["kaspa:", "kaspatest:", "kaspasim:"];
125
125
  const hasValidPrefix = validPrefixes.some((prefix) => address.startsWith(prefix));
126
126
  if (!hasValidPrefix) {
127
- const err = new Error(`HARDKAS_INVALID_ADDRESS: Invalid address '${address}'. Must start with one of: ${validPrefixes.join(", ")}`);
127
+ const err = new Error(
128
+ `HARDKAS_INVALID_ADDRESS: Invalid address '${address}'. Must start with one of: ${validPrefixes.join(", ")}`
129
+ );
128
130
  err.code = "HARDKAS_INVALID_ADDRESS";
129
131
  throw err;
130
132
  }
@@ -148,7 +150,9 @@ function validateAddressNetwork(address, networkId, allowMainnet) {
148
150
  return;
149
151
  }
150
152
  if (!address.startsWith(expectedPrefix)) {
151
- const err = new Error(`NETWORK_ADDRESS_MISMATCH: Address '${address}' does not match the expected prefix '${expectedPrefix}' for network '${networkId}'.`);
153
+ const err = new Error(
154
+ `NETWORK_ADDRESS_MISMATCH: Address '${address}' does not match the expected prefix '${expectedPrefix}' for network '${networkId}'.`
155
+ );
152
156
  err.code = "NETWORK_ADDRESS_MISMATCH";
153
157
  throw err;
154
158
  }
@@ -243,7 +247,7 @@ function resolveHardkasAccount(options) {
243
247
  ...accConfig
244
248
  };
245
249
  }
246
- const realStore = loadRealAccountStoreSync();
250
+ const realStore = loadRealAccountStoreSync({ cwd: workspaceRoot });
247
251
  const realAcc = realStore ? getRealDevAccount(realStore, alias) : null;
248
252
  if (realAcc) {
249
253
  return {
@@ -304,7 +308,7 @@ function listHardkasAccounts(config) {
304
308
  }
305
309
  }
306
310
  }
307
- const realStore = loadRealAccountStoreSync();
311
+ const realStore = loadRealAccountStoreSync({ cwd: workspaceRoot });
308
312
  if (realStore) {
309
313
  for (const realAcc of listRealDevAccounts(realStore)) {
310
314
  accounts.set(realAcc.name, {
@@ -365,14 +369,18 @@ async function resolveHardkasAccountAddress(accountOrAddress, config, context =
365
369
  new kaspa.Address(accountOrAddress);
366
370
  }
367
371
  } catch (e) {
368
- const err = new Error(`HARDKAS_INVALID_ADDRESS: Invalid Kaspa address format or checksum.`);
372
+ const err = new Error(
373
+ `HARDKAS_INVALID_ADDRESS: Invalid Kaspa address format or checksum.`
374
+ );
369
375
  err.code = "HARDKAS_INVALID_ADDRESS";
370
376
  throw err;
371
377
  }
372
378
  } catch (e) {
373
- if (e.code === "HARDKAS_INVALID_ADDRESS") throw e;
374
- if (e.code === "ERR_MODULE_NOT_FOUND" || e.message.includes("Cannot find module") || e.message.includes("kaspa-wasm")) {
375
- const err = new Error("ADDRESS_VALIDATOR_UNAVAILABLE: The Kaspa address validator backend is not available.");
379
+ if (e instanceof Error && e.code === "HARDKAS_INVALID_ADDRESS") throw e;
380
+ if (e instanceof Error && (e.code === "ERR_MODULE_NOT_FOUND" || (e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e)).includes("Cannot find module") || (e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e)).includes("kaspa-wasm"))) {
381
+ const err = new Error(
382
+ "ADDRESS_VALIDATOR_UNAVAILABLE: The Kaspa address validator backend is not available."
383
+ );
376
384
  err.code = "ADDRESS_VALIDATOR_UNAVAILABLE";
377
385
  throw err;
378
386
  }
@@ -655,7 +663,7 @@ var KeystoreManager = class {
655
663
  return keystore;
656
664
  } catch (e) {
657
665
  throw new Error(
658
- `Failed to load keystore at ${filePath}: ${e instanceof Error ? e.message : String(e)}`
666
+ `Failed to load keystore at ${filePath}: ${e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e)}`
659
667
  );
660
668
  }
661
669
  }
@@ -674,7 +682,7 @@ var KeystoreManager = class {
674
682
  });
675
683
  } catch (e) {
676
684
  throw new Error(
677
- `Failed to save keystore at ${filePath}: ${e instanceof Error ? e.message : String(e)}`
685
+ `Failed to save keystore at ${filePath}: ${e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e)}`
678
686
  );
679
687
  }
680
688
  }
@@ -761,7 +769,7 @@ async function getOrCreateDevAccount(workspaceDir, index, alias) {
761
769
  try {
762
770
  address = pubKey.toAddress(network).toString();
763
771
  } catch (e) {
764
- const msg = e instanceof Error ? e.message : String(e);
772
+ const msg = e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e);
765
773
  if (msg.includes("Second argument must be") || msg.includes("Unsupported")) {
766
774
  const err = new Error("DEV_ACCOUNT_BACKEND_UNSUPPORTED_NETWORK");
767
775
  err.code = "DEV_ACCOUNT_BACKEND_UNSUPPORTED_NETWORK";
@@ -773,12 +781,13 @@ async function getOrCreateDevAccount(workspaceDir, index, alias) {
773
781
  privateKey = privKey.toString();
774
782
  }
775
783
  } catch (e) {
776
- if (e.message === "DEV_ACCOUNT_BACKEND_UNSUPPORTED_NETWORK") {
784
+ const msg = e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e);
785
+ if (msg === "DEV_ACCOUNT_BACKEND_UNSUPPORTED_NETWORK") {
777
786
  throw e;
778
787
  }
779
788
  console.warn(`
780
789
  [Warning] Could not generate dev account '${alias}'.
781
- ${e.message}`);
790
+ ${msg}`);
782
791
  return { address: "", privateKey: "", publicKey: "" };
783
792
  }
784
793
  const accountData = {
@@ -888,13 +897,17 @@ var KaspaWasmPrivateKeySigner = class {
888
897
  let pkValue = account.privateKeyEnv ? process.env[account.privateKeyEnv] : void 0;
889
898
  if (!pkValue && account.privateKey) {
890
899
  if (plan.networkId === "mainnet") {
891
- throw new Error(`Mainnet guard: Unsafe plaintext privateKey fallback is forbidden on mainnet for account '${account.name}'. Use privateKeyEnv instead.`);
900
+ throw new Error(
901
+ `Mainnet guard: Unsafe plaintext privateKey fallback is forbidden on mainnet for account '${account.name}'. Use privateKeyEnv instead.`
902
+ );
892
903
  }
893
904
  pkValue = account.privateKey;
894
905
  }
895
906
  if (!pkValue && account.keystorePath) {
896
907
  try {
897
- const keystore = await KeystoreManager.loadEncryptedKeystore(account.keystorePath);
908
+ const keystore = await KeystoreManager.loadEncryptedKeystore(
909
+ account.keystorePath
910
+ );
898
911
  const unlock = await KeystoreManager.decryptEncryptedKeystore(
899
912
  keystore,
900
913
  DEV_ACCOUNTS_PASSWORD
@@ -906,12 +919,16 @@ var KaspaWasmPrivateKeySigner = class {
906
919
  }
907
920
  }
908
921
  if (!pkValue) {
909
- const err = new Error(`DEV_ACCOUNT_KEY_UNAVAILABLE: Missing required private key for account '${account.name}'.`);
922
+ const err = new Error(
923
+ `DEV_ACCOUNT_KEY_UNAVAILABLE: Missing required private key for account '${account.name}'.`
924
+ );
910
925
  err.code = "DEV_ACCOUNT_KEY_UNAVAILABLE";
911
926
  throw err;
912
927
  }
913
928
  if (typeof pkValue !== "string" || pkValue.trim() === "" || !/^[0-9a-fA-F]{64}$/.test(pkValue)) {
914
- const err = new Error("INVALID_PRIVATE_KEY_MATERIAL: Private key must be a valid 64-character hex string.");
929
+ const err = new Error(
930
+ "INVALID_PRIVATE_KEY_MATERIAL: Private key must be a valid 64-character hex string."
931
+ );
915
932
  err.code = "INVALID_PRIVATE_KEY_MATERIAL";
916
933
  throw err;
917
934
  }
@@ -1137,7 +1154,9 @@ var KaspaSdkKeyGenerator = class {
1137
1154
  const privateKeyStr = typeof kp.privateKey === "object" ? hex : kp.privateKey;
1138
1155
  const publicKeyStr = typeof kp.publicKey === "object" ? kp.publicKey.toString() : kp.publicKey;
1139
1156
  if (typeof privateKeyStr !== "string" || !/^[0-9a-f]{64}$/i.test(privateKeyStr)) {
1140
- throw new Error("Generated private key is not a valid 64-character hex string.");
1157
+ throw new Error(
1158
+ "Generated private key is not a valid 64-character hex string."
1159
+ );
1141
1160
  }
1142
1161
  return {
1143
1162
  address,
@@ -1150,7 +1169,7 @@ var KaspaSdkKeyGenerator = class {
1150
1169
  );
1151
1170
  } catch (e) {
1152
1171
  throw new Error(
1153
- `Failed to generate account using SDK: ${e instanceof Error ? e.message : String(e)}`
1172
+ `Failed to generate account using SDK: ${e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e)}`
1154
1173
  );
1155
1174
  }
1156
1175
  }
@@ -1165,7 +1184,12 @@ async function createLocalKaspaWallet(options) {
1165
1184
  }
1166
1185
 
1167
1186
  // src/fixture-signer.ts
1168
- import { calculateContentHash as calculateContentHash3, HARDKAS_VERSION as HARDKAS_VERSION3, ARTIFACT_VERSION as ARTIFACT_VERSION2, CURRENT_HASH_VERSION } from "@hardkas/artifacts";
1187
+ import {
1188
+ calculateContentHash as calculateContentHash3,
1189
+ HARDKAS_VERSION as HARDKAS_VERSION3,
1190
+ ARTIFACT_VERSION as ARTIFACT_VERSION2,
1191
+ CURRENT_HASH_VERSION
1192
+ } from "@hardkas/artifacts";
1169
1193
  function toHex2(arr) {
1170
1194
  return Buffer.from(arr).toString("hex");
1171
1195
  }
@@ -1215,7 +1239,9 @@ var HardkasFixtureSigner = class {
1215
1239
  try {
1216
1240
  return await import("kaspa-wasm");
1217
1241
  } catch (e) {
1218
- const err = new Error("SIGNER_BACKEND_UNAVAILABLE: Official Kaspa WASM backend is required to sign transactions.\nInstall it via: npm install kaspa-wasm");
1242
+ const err = new Error(
1243
+ "SIGNER_BACKEND_UNAVAILABLE: Official Kaspa WASM backend is required to sign transactions.\nInstall it via: npm install kaspa-wasm"
1244
+ );
1219
1245
  err.code = "SIGNER_BACKEND_UNAVAILABLE";
1220
1246
  throw err;
1221
1247
  }
@@ -1237,7 +1263,9 @@ var HardkasFixtureSigner = class {
1237
1263
  }
1238
1264
  const spk = u.scriptPublicKey;
1239
1265
  if (!spk) {
1240
- throw new Error("UTXO is missing scriptPublicKey. Real signing flows must never fabricate cryptographic state.");
1266
+ throw new Error(
1267
+ "UTXO is missing scriptPublicKey. Real signing flows must never fabricate cryptographic state."
1268
+ );
1241
1269
  }
1242
1270
  return {
1243
1271
  address: plan.from.address,
@@ -1399,7 +1427,7 @@ var KaspaSdkRealTxSigner = class {
1399
1427
  txId
1400
1428
  };
1401
1429
  } catch (e) {
1402
- const msg = e instanceof Error ? e.message : String(e);
1430
+ const msg = e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e);
1403
1431
  if (msg.includes("is not a constructor") || msg.includes("is not a function")) {
1404
1432
  throw new Error(
1405
1433
  `Kaspa SDK signer adapter could not find required transaction signing primitives: ${msg}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardkas/accounts",
3
- "version": "0.9.0-alpha",
3
+ "version": "0.9.2-alpha",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -19,10 +19,10 @@
19
19
  "dependencies": {
20
20
  "hash-wasm": "^4.12.0",
21
21
  "kaspa-wasm": "0.13.0",
22
- "@hardkas/artifacts": "0.9.0-alpha",
23
- "@hardkas/config": "0.9.0-alpha",
24
- "@hardkas/core": "0.9.0-alpha",
25
- "@hardkas/localnet": "0.9.0-alpha"
22
+ "@hardkas/artifacts": "0.9.2-alpha",
23
+ "@hardkas/config": "0.9.2-alpha",
24
+ "@hardkas/core": "0.9.2-alpha",
25
+ "@hardkas/localnet": "0.9.2-alpha"
26
26
  },
27
27
  "devDependencies": {
28
28
  "tsup": "^8.3.5",