@hardkas/accounts 0.3.0-alpha → 0.4.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 +47 -20
- package/dist/index.js +93 -42
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -110,6 +110,24 @@ declare function listHardkasAccounts(config?: HardkasConfig): HardkasAccount[];
|
|
|
110
110
|
declare function resolveHardkasAccountAddress(accountOrAddress: string, config?: HardkasConfig): string;
|
|
111
111
|
declare function describeAccount(account: HardkasAccount): Record<string, unknown>;
|
|
112
112
|
|
|
113
|
+
interface EvmExportResult {
|
|
114
|
+
address: `0x${string}`;
|
|
115
|
+
privateKey?: `0x${string}`;
|
|
116
|
+
isSecret: boolean;
|
|
117
|
+
networkId: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Validates and prepares an account for EVM export.
|
|
121
|
+
*
|
|
122
|
+
* SECURITY CONSTRAINT:
|
|
123
|
+
* - Only explicit EVM/L2 accounts are exported.
|
|
124
|
+
* - No derivation from Kaspa L1 keys in this PR.
|
|
125
|
+
* - Fails on mainnet/testnet.
|
|
126
|
+
*/
|
|
127
|
+
declare function prepareEvmAccountExport(account: HardkasAccount, networkId: string, options?: {
|
|
128
|
+
includeSecret?: boolean;
|
|
129
|
+
}): Promise<EvmExportResult>;
|
|
130
|
+
|
|
113
131
|
declare function getRequiredEnv(name: string): string;
|
|
114
132
|
|
|
115
133
|
/**
|
|
@@ -153,6 +171,34 @@ declare function loadKaspaWasm(): Promise<any>;
|
|
|
153
171
|
*/
|
|
154
172
|
declare function getKaspaSigningBackendStatus(): Promise<KaspaSigningBackendStatus>;
|
|
155
173
|
|
|
174
|
+
interface GeneratedKaspaDevAccount {
|
|
175
|
+
readonly address: string;
|
|
176
|
+
readonly publicKey?: string;
|
|
177
|
+
readonly privateKey: string;
|
|
178
|
+
readonly mnemonic?: string;
|
|
179
|
+
}
|
|
180
|
+
interface KaspaKeyGenerator {
|
|
181
|
+
generateAccount(options?: {
|
|
182
|
+
readonly networkId?: "simnet" | "testnet-10" | "mainnet";
|
|
183
|
+
}): Promise<GeneratedKaspaDevAccount>;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Placeholder implementation for Kaspa key generation.
|
|
187
|
+
* This ensures we don't implement custom crypto logic and wait for a verified SDK integration.
|
|
188
|
+
*/
|
|
189
|
+
declare class UnsupportedKaspaKeyGenerator implements KaspaKeyGenerator {
|
|
190
|
+
generateAccount(): Promise<GeneratedKaspaDevAccount>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interface CreateKaspaWalletOptions {
|
|
194
|
+
networkId?: "simnet" | "testnet-10" | "mainnet";
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Generates a new Kaspa L1 developer wallet.
|
|
198
|
+
* Strictly separate from EVM/L2 identities.
|
|
199
|
+
*/
|
|
200
|
+
declare function createLocalKaspaWallet(options?: CreateKaspaWalletOptions): Promise<GeneratedKaspaDevAccount>;
|
|
201
|
+
|
|
156
202
|
/**
|
|
157
203
|
* Real Kaspa signer using the official WASM SDK.
|
|
158
204
|
* Only works if the 'kaspa' package is installed.
|
|
@@ -257,25 +303,6 @@ declare class KaspaSdkRealTxSigner implements RealTxSigner {
|
|
|
257
303
|
sign(input: RealTxSigningInput): Promise<RealTxSigningResult>;
|
|
258
304
|
}
|
|
259
305
|
|
|
260
|
-
interface GeneratedKaspaDevAccount {
|
|
261
|
-
readonly address: string;
|
|
262
|
-
readonly publicKey?: string;
|
|
263
|
-
readonly privateKey: string;
|
|
264
|
-
readonly mnemonic?: string;
|
|
265
|
-
}
|
|
266
|
-
interface KaspaKeyGenerator {
|
|
267
|
-
generateAccount(options?: {
|
|
268
|
-
readonly networkId?: "simnet" | "testnet-10" | "mainnet";
|
|
269
|
-
}): Promise<GeneratedKaspaDevAccount>;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Placeholder implementation for Kaspa key generation.
|
|
273
|
-
* This ensures we don't implement custom crypto logic and wait for a verified SDK integration.
|
|
274
|
-
*/
|
|
275
|
-
declare class UnsupportedKaspaKeyGenerator implements KaspaKeyGenerator {
|
|
276
|
-
generateAccount(): Promise<GeneratedKaspaDevAccount>;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
306
|
interface KaspaSdkKeyGeneratorOptions {
|
|
280
307
|
readonly networkId?: "simnet" | "testnet-10" | "mainnet";
|
|
281
308
|
readonly sdkLoader?: () => Promise<any>;
|
|
@@ -338,4 +365,4 @@ declare class KeystoreManager {
|
|
|
338
365
|
static saveEncryptedKeystore(filePath: string, keystore: EncryptedKeystoreV2): Promise<void>;
|
|
339
366
|
}
|
|
340
367
|
|
|
341
|
-
export { type EncryptedKeystoreV2, type GeneratedKaspaDevAccount, type HardkasAccount, type HardkasAccountKind, type HardkasBaseAccount, type HardkasEvmPrivateKeyAccount, type HardkasExternalWalletAccount, type HardkasKaspaPrivateKeyAccount, type HardkasSigner, type HardkasSignerKind, type HardkasSimulatedAccount, type HardkasTxPlanSigner, type KaspaKeyGenerator, KaspaSdkKeyGenerator, type KaspaSdkKeyGeneratorOptions, KaspaSdkRealTxSigner, type KaspaSdkRealTxSignerOptions, type KaspaSigningBackendStatus, KaspaWasmPrivateKeySigner, type KeystoreCipherParams, type KeystoreKdfParams, KeystoreManager, type KeystorePayload, type KeystoreUnlockResult, type RealAccountStore, type RealDevAccount, type RealTxSigner, type RealTxSigningInput, type RealTxSigningResult, type ResolveAccountOptions, type SignTxPlanInput, type SignTxPlanResult, SimulatedSigner, SimulatedTxPlanSigner, UnsupportedKaspaKeyGenerator, UnsupportedRealKaspaSigner, UnsupportedRealTxSigner, assertSigningNetworkAllowed, createEmptyRealAccountStore, describeAccount, getDefaultRealAccountsPath, getKaspaSigningBackendStatus, getRealDevAccount, getRequiredEnv, importRealDevAccount, listHardkasAccounts, listRealDevAccounts, loadKaspaWasm, loadOrCreateRealAccountStore, loadRealAccountStore, loadRealAccountStoreSync, removeRealDevAccount, resolveHardkasAccount, resolveHardkasAccountAddress, resolveRealAccountOrAddress, saveRealAccountStore, signTxPlanArtifact, validateAccountName, validateAddressPrefix };
|
|
368
|
+
export { type CreateKaspaWalletOptions, type EncryptedKeystoreV2, type EvmExportResult, type GeneratedKaspaDevAccount, type HardkasAccount, type HardkasAccountKind, type HardkasBaseAccount, type HardkasEvmPrivateKeyAccount, type HardkasExternalWalletAccount, type HardkasKaspaPrivateKeyAccount, type HardkasSigner, type HardkasSignerKind, type HardkasSimulatedAccount, type HardkasTxPlanSigner, type KaspaKeyGenerator, KaspaSdkKeyGenerator, type KaspaSdkKeyGeneratorOptions, KaspaSdkRealTxSigner, type KaspaSdkRealTxSignerOptions, type KaspaSigningBackendStatus, KaspaWasmPrivateKeySigner, type KeystoreCipherParams, type KeystoreKdfParams, KeystoreManager, type KeystorePayload, type KeystoreUnlockResult, type RealAccountStore, type RealDevAccount, type RealTxSigner, type RealTxSigningInput, type RealTxSigningResult, type ResolveAccountOptions, type SignTxPlanInput, type SignTxPlanResult, SimulatedSigner, SimulatedTxPlanSigner, UnsupportedKaspaKeyGenerator, UnsupportedRealKaspaSigner, UnsupportedRealTxSigner, assertSigningNetworkAllowed, createEmptyRealAccountStore, createLocalKaspaWallet, describeAccount, getDefaultRealAccountsPath, getKaspaSigningBackendStatus, getRealDevAccount, getRequiredEnv, importRealDevAccount, listHardkasAccounts, listRealDevAccounts, loadKaspaWasm, loadOrCreateRealAccountStore, loadRealAccountStore, loadRealAccountStoreSync, prepareEvmAccountExport, removeRealDevAccount, resolveHardkasAccount, resolveHardkasAccountAddress, resolveRealAccountOrAddress, saveRealAccountStore, signTxPlanArtifact, validateAccountName, validateAddressPrefix };
|
package/dist/index.js
CHANGED
|
@@ -263,6 +263,47 @@ function describeAccount(account) {
|
|
|
263
263
|
return desc;
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
+
// src/evm-export.ts
|
|
267
|
+
async function prepareEvmAccountExport(account, networkId, options = {}) {
|
|
268
|
+
if (networkId === "mainnet" || networkId.startsWith("testnet")) {
|
|
269
|
+
throw new Error(`EVM account export is NOT allowed on network "${networkId}" for security reasons.`);
|
|
270
|
+
}
|
|
271
|
+
if (networkId !== "simnet" && networkId !== "localnet") {
|
|
272
|
+
throw new Error(`EVM account export is only supported on local development networks (simnet, localnet).`);
|
|
273
|
+
}
|
|
274
|
+
if (account.kind !== "evm-private-key") {
|
|
275
|
+
throw new Error(`Account "${account.name}" is not an EVM/L2 account (kind: ${account.kind}). Only explicit EVM accounts can be exported.`);
|
|
276
|
+
}
|
|
277
|
+
if (!account.address || !account.address.startsWith("0x")) {
|
|
278
|
+
throw new Error(`Account "${account.name}" does not have a valid EVM address.`);
|
|
279
|
+
}
|
|
280
|
+
const result = {
|
|
281
|
+
address: account.address,
|
|
282
|
+
isSecret: false,
|
|
283
|
+
networkId
|
|
284
|
+
};
|
|
285
|
+
if (options.includeSecret) {
|
|
286
|
+
let privateKey;
|
|
287
|
+
if (account.kind === "evm-private-key") {
|
|
288
|
+
if (account.privateKeyEnv) {
|
|
289
|
+
privateKey = process.env[account.privateKeyEnv];
|
|
290
|
+
if (!privateKey) {
|
|
291
|
+
throw new Error(`Private key environment variable "${account.privateKeyEnv}" is not set.`);
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
privateKey = account.privateKey;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (privateKey) {
|
|
298
|
+
result.privateKey = privateKey.startsWith("0x") ? privateKey : `0x${privateKey}`;
|
|
299
|
+
result.isSecret = true;
|
|
300
|
+
} else {
|
|
301
|
+
throw new Error(`Private key for account "${account.name}" could not be retrieved.`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
|
|
266
307
|
// src/env.ts
|
|
267
308
|
function getRequiredEnv(name) {
|
|
268
309
|
const value = process.env[name];
|
|
@@ -482,6 +523,56 @@ async function signTxPlanArtifact(input) {
|
|
|
482
523
|
throw new Error(`Unsupported account kind for signing: ${account.kind}`);
|
|
483
524
|
}
|
|
484
525
|
|
|
526
|
+
// src/kaspa-sdk-keygen.ts
|
|
527
|
+
var KaspaSdkKeyGenerator = class {
|
|
528
|
+
networkId;
|
|
529
|
+
sdkLoader;
|
|
530
|
+
constructor(options) {
|
|
531
|
+
this.networkId = options?.networkId || "simnet";
|
|
532
|
+
const rawLoader = options?.sdkLoader || (async () => {
|
|
533
|
+
return await import("kaspa");
|
|
534
|
+
});
|
|
535
|
+
this.sdkLoader = async () => {
|
|
536
|
+
try {
|
|
537
|
+
return await rawLoader();
|
|
538
|
+
} catch (e) {
|
|
539
|
+
throw new Error(
|
|
540
|
+
"Kaspa SDK key generation dependency is not installed. Install/configure the supported Kaspa WASM SDK adapter. Use 'hardkas accounts real import' to add accounts manually for now."
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
async generateAccount(options) {
|
|
546
|
+
const sdk = await this.sdkLoader();
|
|
547
|
+
const network = options?.networkId || this.networkId;
|
|
548
|
+
try {
|
|
549
|
+
if (typeof sdk.PrivateKey === "function") {
|
|
550
|
+
const privKey = new sdk.PrivateKey();
|
|
551
|
+
const pubKey = privKey.toPublicKey();
|
|
552
|
+
const address = pubKey.toAddress(network).toString();
|
|
553
|
+
const privateKeyStr = privKey.toString();
|
|
554
|
+
const publicKeyStr = pubKey.toString();
|
|
555
|
+
return {
|
|
556
|
+
address,
|
|
557
|
+
publicKey: publicKeyStr,
|
|
558
|
+
privateKey: privateKeyStr
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
throw new Error("Loaded Kaspa SDK does not expose expected PrivateKey constructor.");
|
|
562
|
+
} catch (e) {
|
|
563
|
+
throw new Error(`Failed to generate account using SDK: ${e instanceof Error ? e.message : String(e)}`);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
// src/kaspa-wallet.ts
|
|
569
|
+
async function createLocalKaspaWallet(options) {
|
|
570
|
+
const keygen = new KaspaSdkKeyGenerator({
|
|
571
|
+
networkId: options?.networkId || "simnet"
|
|
572
|
+
});
|
|
573
|
+
return await keygen.generateAccount();
|
|
574
|
+
}
|
|
575
|
+
|
|
485
576
|
// src/real-signer.ts
|
|
486
577
|
var UnsupportedRealTxSigner = class {
|
|
487
578
|
async sign() {
|
|
@@ -572,48 +663,6 @@ var UnsupportedKaspaKeyGenerator = class {
|
|
|
572
663
|
}
|
|
573
664
|
};
|
|
574
665
|
|
|
575
|
-
// src/kaspa-sdk-keygen.ts
|
|
576
|
-
var KaspaSdkKeyGenerator = class {
|
|
577
|
-
networkId;
|
|
578
|
-
sdkLoader;
|
|
579
|
-
constructor(options) {
|
|
580
|
-
this.networkId = options?.networkId || "simnet";
|
|
581
|
-
const rawLoader = options?.sdkLoader || (async () => {
|
|
582
|
-
return await import("kaspa");
|
|
583
|
-
});
|
|
584
|
-
this.sdkLoader = async () => {
|
|
585
|
-
try {
|
|
586
|
-
return await rawLoader();
|
|
587
|
-
} catch (e) {
|
|
588
|
-
throw new Error(
|
|
589
|
-
"Kaspa SDK key generation dependency is not installed. Install/configure the supported Kaspa WASM SDK adapter. Use 'hardkas accounts real import' to add accounts manually for now."
|
|
590
|
-
);
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
async generateAccount(options) {
|
|
595
|
-
const sdk = await this.sdkLoader();
|
|
596
|
-
const network = options?.networkId || this.networkId;
|
|
597
|
-
try {
|
|
598
|
-
if (typeof sdk.PrivateKey === "function") {
|
|
599
|
-
const privKey = new sdk.PrivateKey();
|
|
600
|
-
const pubKey = privKey.toPublicKey();
|
|
601
|
-
const address = pubKey.toAddress(network).toString();
|
|
602
|
-
const privateKeyStr = privKey.toString();
|
|
603
|
-
const publicKeyStr = pubKey.toString();
|
|
604
|
-
return {
|
|
605
|
-
address,
|
|
606
|
-
publicKey: publicKeyStr,
|
|
607
|
-
privateKey: privateKeyStr
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
throw new Error("Loaded Kaspa SDK does not expose expected PrivateKey constructor.");
|
|
611
|
-
} catch (e) {
|
|
612
|
-
throw new Error(`Failed to generate account using SDK: ${e instanceof Error ? e.message : String(e)}`);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
};
|
|
616
|
-
|
|
617
666
|
// src/keystore.ts
|
|
618
667
|
import fs3 from "fs";
|
|
619
668
|
import path3 from "path";
|
|
@@ -783,6 +832,7 @@ export {
|
|
|
783
832
|
UnsupportedRealTxSigner,
|
|
784
833
|
assertSigningNetworkAllowed,
|
|
785
834
|
createEmptyRealAccountStore,
|
|
835
|
+
createLocalKaspaWallet,
|
|
786
836
|
describeAccount,
|
|
787
837
|
getDefaultRealAccountsPath,
|
|
788
838
|
getKaspaSigningBackendStatus,
|
|
@@ -795,6 +845,7 @@ export {
|
|
|
795
845
|
loadOrCreateRealAccountStore,
|
|
796
846
|
loadRealAccountStore,
|
|
797
847
|
loadRealAccountStoreSync,
|
|
848
|
+
prepareEvmAccountExport,
|
|
798
849
|
removeRealDevAccount,
|
|
799
850
|
resolveHardkasAccount,
|
|
800
851
|
resolveHardkasAccountAddress,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/accounts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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/
|
|
22
|
-
"@hardkas/
|
|
23
|
-
"@hardkas/
|
|
20
|
+
"@hardkas/artifacts": "0.4.0-alpha",
|
|
21
|
+
"@hardkas/core": "0.4.0-alpha",
|
|
22
|
+
"@hardkas/config": "0.4.0-alpha",
|
|
23
|
+
"@hardkas/localnet": "0.4.0-alpha"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"tsup": "^8.3.5",
|