@hardkas/accounts 0.8.14-alpha → 0.8.16-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.
- package/dist/index.d.ts +3 -0
- package/dist/index.js +80 -20
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -249,6 +249,8 @@ interface RealDevAccount {
|
|
|
249
249
|
readonly publicKey?: string;
|
|
250
250
|
/** @deprecated Use keystoreRef for encrypted storage. Plaintext keys in this field are considered legacy/unsafe. */
|
|
251
251
|
readonly privateKey?: string;
|
|
252
|
+
/** Environment variable name containing the private key */
|
|
253
|
+
readonly privateKeyEnv?: string;
|
|
252
254
|
/** Reference to the encrypted keystore file in .hardkas/keystore/ */
|
|
253
255
|
readonly keystoreRef?: string;
|
|
254
256
|
readonly createdAt: string;
|
|
@@ -278,6 +280,7 @@ declare function importRealDevAccount(store: RealAccountStore, account: {
|
|
|
278
280
|
readonly address: string;
|
|
279
281
|
readonly publicKey?: string;
|
|
280
282
|
readonly privateKey?: string;
|
|
283
|
+
readonly privateKeyEnv?: string;
|
|
281
284
|
readonly keystoreRef?: string;
|
|
282
285
|
}): RealAccountStore;
|
|
283
286
|
declare function removeRealDevAccount(store: RealAccountStore, name: string): RealAccountStore;
|
package/dist/index.js
CHANGED
|
@@ -214,7 +214,9 @@ function resolveHardkasAccount(options) {
|
|
|
214
214
|
name: realAcc.name,
|
|
215
215
|
kind: "kaspa-private-key",
|
|
216
216
|
// Assuming Kaspa for now, could be extensible
|
|
217
|
-
address: realAcc.address
|
|
217
|
+
address: realAcc.address,
|
|
218
|
+
...realAcc.privateKeyEnv ? { privateKeyEnv: realAcc.privateKeyEnv } : {},
|
|
219
|
+
...realAcc.privateKey ? { privateKey: realAcc.privateKey } : {}
|
|
218
220
|
};
|
|
219
221
|
}
|
|
220
222
|
const detAccounts = createDeterministicAccounts();
|
|
@@ -271,7 +273,9 @@ function listHardkasAccounts(config) {
|
|
|
271
273
|
accounts.set(realAcc.name, {
|
|
272
274
|
name: realAcc.name,
|
|
273
275
|
kind: "kaspa-private-key",
|
|
274
|
-
address: realAcc.address
|
|
276
|
+
address: realAcc.address,
|
|
277
|
+
...realAcc.privateKeyEnv ? { privateKeyEnv: realAcc.privateKeyEnv } : {},
|
|
278
|
+
...realAcc.privateKey ? { privateKey: realAcc.privateKey } : {}
|
|
275
279
|
});
|
|
276
280
|
}
|
|
277
281
|
}
|
|
@@ -523,7 +527,13 @@ var KaspaWasmPrivateKeySigner = class {
|
|
|
523
527
|
mode: plan.mode,
|
|
524
528
|
allowMainnet: this.options.allowMainnet
|
|
525
529
|
});
|
|
526
|
-
|
|
530
|
+
let pkValue = account.privateKeyEnv ? process.env[account.privateKeyEnv] : void 0;
|
|
531
|
+
if (!pkValue && account.privateKey) {
|
|
532
|
+
if (plan.networkId === "mainnet") {
|
|
533
|
+
throw new Error(`Mainnet guard: Unsafe plaintext privateKey fallback is forbidden on mainnet for account '${account.name}'. Use privateKeyEnv instead.`);
|
|
534
|
+
}
|
|
535
|
+
pkValue = account.privateKey;
|
|
536
|
+
}
|
|
527
537
|
if (!pkValue) {
|
|
528
538
|
throw new Error(`Missing required private key for account '${account.name}'.`);
|
|
529
539
|
}
|
|
@@ -688,7 +698,11 @@ async function signTxPlanArtifact(input) {
|
|
|
688
698
|
payload: result.signedTransaction?.payload || ""
|
|
689
699
|
},
|
|
690
700
|
lineage: createLineageTransition(planArtifact, "hardkas.signedTx"),
|
|
691
|
-
...planArtifact.workflowId ? { workflowId: planArtifact.workflowId } : {}
|
|
701
|
+
...planArtifact.workflowId ? { workflowId: planArtifact.workflowId } : {},
|
|
702
|
+
...planArtifact.assumptionLevel ? { assumptionLevel: planArtifact.assumptionLevel } : {},
|
|
703
|
+
...planArtifact.policyRefs ? { policyRefs: planArtifact.policyRefs } : {},
|
|
704
|
+
...planArtifact.networkProfileRef ? { networkProfileRef: planArtifact.networkProfileRef } : {},
|
|
705
|
+
...planArtifact.assumptionRef ? { assumptionRef: planArtifact.assumptionRef } : {}
|
|
692
706
|
};
|
|
693
707
|
const contentHash = calculateContentHash2(artifact);
|
|
694
708
|
artifact.signedId = `signed-${contentHash.slice(0, 16)}`;
|
|
@@ -1224,28 +1238,74 @@ async function getOrCreateDevAccount(workspaceDir, index, alias) {
|
|
|
1224
1238
|
}
|
|
1225
1239
|
const seedString = `${SIMNET_DETERMINISTIC_SEED}-${index}`;
|
|
1226
1240
|
const privateKeyHex = crypto2.createHash("sha256").update(seedString).digest("hex");
|
|
1227
|
-
|
|
1241
|
+
const network = "simnet";
|
|
1242
|
+
const isSimnet = ["simnet", "kaspasim", "local"].includes(network);
|
|
1243
|
+
let address = "";
|
|
1244
|
+
let privateKey = "";
|
|
1245
|
+
let publicKey = "";
|
|
1228
1246
|
try {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1247
|
+
if (isSimnet) {
|
|
1248
|
+
let kaspaWasm;
|
|
1249
|
+
try {
|
|
1250
|
+
kaspaWasm = await import(
|
|
1251
|
+
/* @vite-ignore */
|
|
1252
|
+
"kaspa-wasm"
|
|
1253
|
+
);
|
|
1254
|
+
} catch (e) {
|
|
1255
|
+
console.warn(`
|
|
1256
|
+
[Warning] kaspa-wasm is not installed. Required for simnet.`);
|
|
1257
|
+
return { address: "", privateKey: "", publicKey: "" };
|
|
1258
|
+
}
|
|
1259
|
+
const privKey = new kaspaWasm.PrivateKey(privateKeyHex);
|
|
1260
|
+
const kp = privKey.toKeypair();
|
|
1261
|
+
address = kp.toAddress(network).toString();
|
|
1262
|
+
publicKey = kp.publicKey;
|
|
1263
|
+
privateKey = kp.privateKey;
|
|
1264
|
+
} else {
|
|
1265
|
+
let sdkModule;
|
|
1266
|
+
try {
|
|
1267
|
+
sdkModule = await import(
|
|
1268
|
+
/* @vite-ignore */
|
|
1269
|
+
"@kaspa/core-lib"
|
|
1270
|
+
);
|
|
1271
|
+
} catch (e) {
|
|
1272
|
+
console.warn(`
|
|
1273
|
+
[Warning] @kaspa/core-lib is not installed.`);
|
|
1274
|
+
return { address: "", privateKey: "", publicKey: "" };
|
|
1275
|
+
}
|
|
1276
|
+
const sdk = sdkModule.default || sdkModule;
|
|
1277
|
+
if (typeof sdk.initRuntime === "function") {
|
|
1278
|
+
await sdk.initRuntime();
|
|
1279
|
+
}
|
|
1280
|
+
const privKey = new sdk.PrivateKey(privateKeyHex);
|
|
1281
|
+
const pubKey = privKey.toPublicKey();
|
|
1282
|
+
try {
|
|
1283
|
+
address = pubKey.toAddress(network).toString();
|
|
1284
|
+
} catch (e) {
|
|
1285
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
1286
|
+
if (msg.includes("Second argument must be") || msg.includes("Unsupported")) {
|
|
1287
|
+
const err = new Error("DEV_ACCOUNT_BACKEND_UNSUPPORTED_NETWORK");
|
|
1288
|
+
err.code = "DEV_ACCOUNT_BACKEND_UNSUPPORTED_NETWORK";
|
|
1289
|
+
throw err;
|
|
1290
|
+
}
|
|
1291
|
+
throw e;
|
|
1292
|
+
}
|
|
1293
|
+
publicKey = pubKey.toString();
|
|
1294
|
+
privateKey = privKey.toString();
|
|
1295
|
+
}
|
|
1233
1296
|
} catch (e) {
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1297
|
+
if (e.message === "DEV_ACCOUNT_BACKEND_UNSUPPORTED_NETWORK") {
|
|
1298
|
+
throw e;
|
|
1299
|
+
}
|
|
1300
|
+
console.warn(`
|
|
1301
|
+
[Warning] Could not generate dev account '${alias}'.
|
|
1302
|
+
${e.message}`);
|
|
1239
1303
|
return { address: "", privateKey: "", publicKey: "" };
|
|
1240
1304
|
}
|
|
1241
|
-
const sdk = sdkModule.default || sdkModule;
|
|
1242
|
-
const privKey = new sdk.PrivateKey(privateKeyHex);
|
|
1243
|
-
const pubKey = privKey.toPublicKey();
|
|
1244
|
-
const address = pubKey.toAddress("simnet").toString();
|
|
1245
1305
|
const accountData = {
|
|
1246
1306
|
address,
|
|
1247
|
-
privateKey
|
|
1248
|
-
publicKey
|
|
1307
|
+
privateKey,
|
|
1308
|
+
publicKey
|
|
1249
1309
|
};
|
|
1250
1310
|
if (!fs4.existsSync(devAccountsDir)) {
|
|
1251
1311
|
await fs4.promises.mkdir(devAccountsDir, { recursive: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/accounts",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.16-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.8.
|
|
23
|
-
"@hardkas/config": "0.8.
|
|
24
|
-
"@hardkas/core": "0.8.
|
|
25
|
-
"@hardkas/localnet": "0.8.
|
|
22
|
+
"@hardkas/artifacts": "0.8.16-alpha",
|
|
23
|
+
"@hardkas/config": "0.8.16-alpha",
|
|
24
|
+
"@hardkas/core": "0.8.16-alpha",
|
|
25
|
+
"@hardkas/localnet": "0.8.16-alpha"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"tsup": "^8.3.5",
|