@hardkas/accounts 0.5.5-alpha → 0.7.0-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 -1
- package/dist/index.js +36 -10
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ interface HardkasBaseAccount {
|
|
|
52
52
|
interface HardkasSimulatedAccount extends HardkasBaseAccount {
|
|
53
53
|
kind: "simulated";
|
|
54
54
|
address: string;
|
|
55
|
+
evmAddress?: string;
|
|
55
56
|
}
|
|
56
57
|
interface HardkasKaspaPrivateKeyAccount extends HardkasBaseAccount {
|
|
57
58
|
kind: "kaspa-private-key";
|
|
@@ -107,7 +108,7 @@ interface ResolveAccountOptions {
|
|
|
107
108
|
}
|
|
108
109
|
declare function resolveHardkasAccount(options: ResolveAccountOptions): HardkasAccount;
|
|
109
110
|
declare function listHardkasAccounts(config?: HardkasConfig): HardkasAccount[];
|
|
110
|
-
declare function resolveHardkasAccountAddress(accountOrAddress: string, config?: HardkasConfig): string;
|
|
111
|
+
declare function resolveHardkasAccountAddress(accountOrAddress: string, config?: HardkasConfig, context?: "L1" | "L2"): string;
|
|
111
112
|
declare function describeAccount(account: HardkasAccount): Record<string, unknown>;
|
|
112
113
|
|
|
113
114
|
interface EvmExportResult {
|
|
@@ -264,6 +265,7 @@ declare function importRealDevAccount(store: RealAccountStore, account: {
|
|
|
264
265
|
readonly address: string;
|
|
265
266
|
readonly publicKey?: string;
|
|
266
267
|
readonly privateKey?: string;
|
|
268
|
+
readonly keystoreRef?: string;
|
|
267
269
|
}): RealAccountStore;
|
|
268
270
|
declare function removeRealDevAccount(store: RealAccountStore, name: string): RealAccountStore;
|
|
269
271
|
declare function getRealDevAccount(store: RealAccountStore, name: string): RealDevAccount | null;
|
package/dist/index.js
CHANGED
|
@@ -23,8 +23,9 @@ import fs from "fs";
|
|
|
23
23
|
import path from "path";
|
|
24
24
|
import { writeFileAtomicSync } from "@hardkas/core";
|
|
25
25
|
import { HARDKAS_VERSION, ARTIFACT_SCHEMAS, ARTIFACT_VERSION } from "@hardkas/artifacts";
|
|
26
|
-
function getDefaultRealAccountsPath(cwd
|
|
27
|
-
|
|
26
|
+
function getDefaultRealAccountsPath(cwd) {
|
|
27
|
+
const root = cwd ?? process.cwd();
|
|
28
|
+
return path.join(root, ".hardkas", "accounts.real.json");
|
|
28
29
|
}
|
|
29
30
|
function createEmptyRealAccountStore() {
|
|
30
31
|
return {
|
|
@@ -178,7 +179,8 @@ function resolveHardkasAccount(options) {
|
|
|
178
179
|
return {
|
|
179
180
|
name: det.name,
|
|
180
181
|
kind: "simulated",
|
|
181
|
-
address: det.address
|
|
182
|
+
address: det.address,
|
|
183
|
+
evmAddress: det.evmAddress
|
|
182
184
|
};
|
|
183
185
|
}
|
|
184
186
|
const available = listHardkasAccounts(config).map((a) => a.name).join(", ");
|
|
@@ -191,7 +193,8 @@ function listHardkasAccounts(config) {
|
|
|
191
193
|
accounts.set(det.name, {
|
|
192
194
|
name: det.name,
|
|
193
195
|
kind: "simulated",
|
|
194
|
-
address: det.address
|
|
196
|
+
address: det.address,
|
|
197
|
+
evmAddress: det.evmAddress
|
|
195
198
|
});
|
|
196
199
|
}
|
|
197
200
|
const realStore = loadRealAccountStoreSync();
|
|
@@ -206,6 +209,9 @@ function listHardkasAccounts(config) {
|
|
|
206
209
|
}
|
|
207
210
|
const keystoreDir = path2.join(process.cwd(), ".hardkas", "keystore");
|
|
208
211
|
if (fs2.existsSync(keystoreDir)) {
|
|
212
|
+
if (!config || !config.cwd) {
|
|
213
|
+
throw new Error("Workspace root/cwd is required for hermetic keystore path resolution");
|
|
214
|
+
}
|
|
209
215
|
const files = fs2.readdirSync(keystoreDir);
|
|
210
216
|
for (const file of files) {
|
|
211
217
|
if (file.endsWith(".json")) {
|
|
@@ -236,11 +242,24 @@ function listHardkasAccounts(config) {
|
|
|
236
242
|
}
|
|
237
243
|
return Array.from(accounts.values());
|
|
238
244
|
}
|
|
239
|
-
function resolveHardkasAccountAddress(accountOrAddress, config) {
|
|
245
|
+
function resolveHardkasAccountAddress(accountOrAddress, config, context = "L1") {
|
|
240
246
|
if (accountOrAddress.startsWith("kaspa:") || accountOrAddress.startsWith("kaspatest:") || accountOrAddress.startsWith("kaspasim:")) {
|
|
247
|
+
if (context === "L2") {
|
|
248
|
+
throw new Error(`Invalid L2 address provided: ${accountOrAddress}. Expected EVM address or account alias.`);
|
|
249
|
+
}
|
|
250
|
+
return accountOrAddress;
|
|
251
|
+
}
|
|
252
|
+
if (accountOrAddress.startsWith("0x") && accountOrAddress.length === 42) {
|
|
241
253
|
return accountOrAddress;
|
|
242
254
|
}
|
|
243
255
|
const account = resolveHardkasAccount({ nameOrAddress: accountOrAddress, config });
|
|
256
|
+
if (context === "L2") {
|
|
257
|
+
const evmAddress = account.evmAddress;
|
|
258
|
+
if (!evmAddress) {
|
|
259
|
+
throw new Error(`Account '${account.name}' does not have an EVM address configured for L2.`);
|
|
260
|
+
}
|
|
261
|
+
return evmAddress;
|
|
262
|
+
}
|
|
244
263
|
if (!account.address) {
|
|
245
264
|
throw new Error(`Account '${account.name}' does not have a resolved address yet.`);
|
|
246
265
|
}
|
|
@@ -319,6 +338,7 @@ import {
|
|
|
319
338
|
calculateContentHash as calculateContentHash2,
|
|
320
339
|
HARDKAS_VERSION as HARDKAS_VERSION2
|
|
321
340
|
} from "@hardkas/artifacts";
|
|
341
|
+
import { systemRuntimeContext } from "@hardkas/core";
|
|
322
342
|
|
|
323
343
|
// src/signer-backend.ts
|
|
324
344
|
async function loadKaspaWasm() {
|
|
@@ -377,7 +397,10 @@ var KaspaWasmPrivateKeySigner = class {
|
|
|
377
397
|
if (!u.outpoint.transactionId || u.outpoint.index === void 0) {
|
|
378
398
|
throw new Error(`UTXO is missing transactionId or index. Re-run tx plan.`);
|
|
379
399
|
}
|
|
380
|
-
const spk = u.scriptPublicKey
|
|
400
|
+
const spk = u.scriptPublicKey;
|
|
401
|
+
if (!spk) {
|
|
402
|
+
throw new Error("UTXO is missing scriptPublicKey. Real signing flows must never fabricate cryptographic state.");
|
|
403
|
+
}
|
|
381
404
|
return new sdk.UtxoEntry(
|
|
382
405
|
BigInt(u.amountSompi),
|
|
383
406
|
spk,
|
|
@@ -455,9 +478,10 @@ var UnsupportedRealKaspaSigner = class {
|
|
|
455
478
|
};
|
|
456
479
|
async function signTxPlanArtifact(input) {
|
|
457
480
|
const { planArtifact, account } = input;
|
|
481
|
+
const planRecord = planArtifact;
|
|
458
482
|
if (planArtifact.schema === "hardkas.txPlan") {
|
|
459
|
-
} else if (
|
|
460
|
-
throw new Error(`Cannot sign artifact with status: ${
|
|
483
|
+
} else if (planRecord.status !== "built" && planRecord.status !== "unsigned") {
|
|
484
|
+
throw new Error(`Cannot sign artifact with status: ${planRecord.status}`);
|
|
461
485
|
}
|
|
462
486
|
if (planArtifact.mode === "simulated") {
|
|
463
487
|
if (account.kind !== "simulated") {
|
|
@@ -474,7 +498,8 @@ async function signTxPlanArtifact(input) {
|
|
|
474
498
|
if (account.kind === "simulated") {
|
|
475
499
|
return createSimulatedSignedTxArtifact(
|
|
476
500
|
planArtifact,
|
|
477
|
-
`simulated-signed-tx:${planArtifact.planId}
|
|
501
|
+
`simulated-signed-tx:${planArtifact.planId}`,
|
|
502
|
+
systemRuntimeContext
|
|
478
503
|
);
|
|
479
504
|
}
|
|
480
505
|
if (account.kind === "kaspa-private-key") {
|
|
@@ -520,7 +545,8 @@ async function signTxPlanArtifact(input) {
|
|
|
520
545
|
if (account.kind === "evm-private-key") {
|
|
521
546
|
throw new Error("EVM accounts are reserved for future Igra support and cannot sign Kaspa L1 transactions.");
|
|
522
547
|
}
|
|
523
|
-
|
|
548
|
+
const accountRecord = account;
|
|
549
|
+
throw new Error(`Unsupported account kind for signing: ${accountRecord.kind}`);
|
|
524
550
|
}
|
|
525
551
|
|
|
526
552
|
// src/kaspa-sdk-keygen.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/accounts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"hash-wasm": "^4.12.0",
|
|
20
|
-
"@hardkas/artifacts": "0.
|
|
21
|
-
"@hardkas/localnet": "0.
|
|
22
|
-
"@hardkas/config": "0.
|
|
23
|
-
"@hardkas/core": "0.
|
|
20
|
+
"@hardkas/artifacts": "0.7.0-alpha",
|
|
21
|
+
"@hardkas/localnet": "0.7.0-alpha",
|
|
22
|
+
"@hardkas/config": "0.7.0-alpha",
|
|
23
|
+
"@hardkas/core": "0.7.0-alpha"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"tsup": "^8.3.5",
|