@hardkas/sdk 0.7.6-alpha → 0.7.7-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 CHANGED
@@ -30,6 +30,24 @@ declare class HardkasAccounts {
30
30
  sompi: bigint;
31
31
  formatted: string;
32
32
  }>;
33
+ /**
34
+ * Alias for getBalance.
35
+ */
36
+ balance(accountNameOrAddress: string): Promise<{
37
+ sompi: bigint;
38
+ formatted: string;
39
+ }>;
40
+ /**
41
+ * Lists all configured account names.
42
+ */
43
+ list(): Promise<string[]>;
44
+ /**
45
+ * Funds an account from another account (defaults to 'default' account).
46
+ */
47
+ fund(accountNameOrAddress: string, options?: {
48
+ from?: string;
49
+ amount?: string | bigint;
50
+ }): Promise<any>;
33
51
  }
34
52
 
35
53
  /**
@@ -73,6 +91,14 @@ declare class HardkasTx {
73
91
  receipt: TxReceiptArtifact;
74
92
  receiptPath: string;
75
93
  }>;
94
+ /**
95
+ * Explicitly appends a signature to a partially signed transaction.
96
+ */
97
+ appendSignature(plan: SignedTxArtifact, account?: HardkasAccount | string): Promise<SignedTxArtifact>;
98
+ /**
99
+ * Fetches the current status of a transaction by ID.
100
+ */
101
+ status(txId: string): Promise<any>;
76
102
  }
77
103
 
78
104
  /**
@@ -217,6 +243,14 @@ declare class HardkasArtifactsManager {
217
243
  * Reads an artifact by path or ID/hash from the workspace.
218
244
  */
219
245
  read(id: string): Promise<any>;
246
+ /**
247
+ * Alias for read().
248
+ */
249
+ get(id: string): Promise<any>;
250
+ /**
251
+ * Lists all artifacts in the workspace.
252
+ */
253
+ list(): Promise<any[]>;
220
254
  }
221
255
 
222
256
  interface WorkflowRunOptions {
package/dist/index.js CHANGED
@@ -40,6 +40,36 @@ var HardkasAccounts = class {
40
40
  formatted: formatSompi(sompi)
41
41
  };
42
42
  }
43
+ /**
44
+ * Alias for getBalance.
45
+ */
46
+ async balance(accountNameOrAddress) {
47
+ return this.getBalance(accountNameOrAddress);
48
+ }
49
+ /**
50
+ * Lists all configured account names.
51
+ */
52
+ async list() {
53
+ return Object.keys(this.sdk.config.config.accounts || {});
54
+ }
55
+ /**
56
+ * Funds an account from another account (defaults to 'default' account).
57
+ */
58
+ async fund(accountNameOrAddress, options) {
59
+ const from = options?.from || "default";
60
+ const amount = options?.amount || "1000000000";
61
+ const plan = await this.sdk.tx.plan({
62
+ from,
63
+ to: accountNameOrAddress,
64
+ amount
65
+ });
66
+ const signed = await this.sdk.tx.sign(plan, from);
67
+ if (this.sdk.network === "simulated") {
68
+ return this.sdk.tx.simulate(signed);
69
+ } else {
70
+ return this.sdk.tx.send(signed);
71
+ }
72
+ }
43
73
  };
44
74
 
45
75
  // src/tx.ts
@@ -78,6 +108,9 @@ var HardkasTx = class {
78
108
  if (!toAccount.address)
79
109
  throw new Error(`To account ${toAccount.name} has no address.`);
80
110
  const amountSompi = typeof options.amount === "string" ? parseKasToSompi(options.amount) : typeof options.amount === "number" ? BigInt(options.amount) : options.amount;
111
+ if (amountSompi === 0n) {
112
+ throw new Error("Kaspa value-transfer outputs require amount > 0.\nFor metadata/notary/DID marker transactions use --amount 1.\nFuture: hardkas tx anchor.");
113
+ }
81
114
  let builderUtxos = [];
82
115
  if (this.sdk.network === "simulated") {
83
116
  const { loadOrCreateLocalnetState, getSpendableUtxos } = await import("@hardkas/localnet");
@@ -160,6 +193,9 @@ var HardkasTx = class {
160
193
  "Cannot append signature to an already completed signed transaction."
161
194
  );
162
195
  }
196
+ if (options?.append === void 0 && plan.status === "partially_signed") {
197
+ options = { ...options, append: true };
198
+ }
163
199
  if (!options?.append) {
164
200
  throw new Error(
165
201
  "Input file is a partially signed transaction. Use the --append flag to add your signature."
@@ -247,7 +283,12 @@ var HardkasTx = class {
247
283
  if (!signerAddress) {
248
284
  throw new Error(`Signer account '${resolvedAccount.name}' has no address.`);
249
285
  }
250
- const requiredSigners = options?.requiredSigners || [signerAddress];
286
+ const requiredSignersList = options?.requiredSigners || [signerAddress];
287
+ const requiredSigners = [];
288
+ for (const r of requiredSignersList) {
289
+ const acc = await this.sdk.accounts.resolve(r);
290
+ requiredSigners.push(acc.address || r);
291
+ }
251
292
  if (!requiredSigners.includes(signerAddress)) {
252
293
  throw new Error(
253
294
  `Signer '${signerAddress}' is not an authorized signer for this transaction.`
@@ -514,6 +555,23 @@ var HardkasTx = class {
514
555
  receiptPath
515
556
  };
516
557
  }
558
+ /**
559
+ * Explicitly appends a signature to a partially signed transaction.
560
+ */
561
+ async appendSignature(plan, account) {
562
+ return this.sign(plan, account, { append: true });
563
+ }
564
+ /**
565
+ * Fetches the current status of a transaction by ID.
566
+ */
567
+ async status(txId) {
568
+ const isLocal = txId.startsWith("simulated-");
569
+ if (isLocal) {
570
+ return { status: "simulated_confirmed" };
571
+ }
572
+ const result = await this.sdk.rpc.getTransaction(txId);
573
+ return result;
574
+ }
517
575
  };
518
576
 
519
577
  // src/l2.ts
@@ -1019,6 +1077,33 @@ var HardkasArtifactsManager = class {
1019
1077
  }
1020
1078
  return readArtifact(filePath);
1021
1079
  }
1080
+ /**
1081
+ * Alias for read().
1082
+ */
1083
+ async get(id) {
1084
+ return this.read(id);
1085
+ }
1086
+ /**
1087
+ * Lists all artifacts in the workspace.
1088
+ */
1089
+ async list() {
1090
+ if (!fs3.existsSync(this.workspace.artifactsDir)) {
1091
+ return [];
1092
+ }
1093
+ const { readArtifact } = await import("@hardkas/artifacts");
1094
+ const files = fs3.readdirSync(this.workspace.artifactsDir);
1095
+ const artifacts = [];
1096
+ for (const file of files) {
1097
+ if (file.endsWith(".json")) {
1098
+ try {
1099
+ const artifact = await readArtifact(path3.join(this.workspace.artifactsDir, file));
1100
+ artifacts.push(artifact);
1101
+ } catch (e) {
1102
+ }
1103
+ }
1104
+ }
1105
+ return artifacts;
1106
+ }
1022
1107
  };
1023
1108
 
1024
1109
  // src/workflow.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardkas/sdk",
3
- "version": "0.7.6-alpha",
3
+ "version": "0.7.7-alpha",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -23,23 +23,23 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@hardkas/config": "0.7.6-alpha",
27
- "@hardkas/artifacts": "0.7.6-alpha",
28
- "@hardkas/accounts": "0.7.6-alpha",
29
- "@hardkas/core": "0.7.6-alpha",
30
- "@hardkas/l2": "0.7.6-alpha",
31
- "@hardkas/simulator": "0.7.6-alpha",
32
- "@hardkas/localnet": "0.7.6-alpha",
33
- "@hardkas/query": "0.7.6-alpha",
34
- "@hardkas/tx-builder": "0.7.6-alpha",
35
- "@hardkas/wallet-adapter": "0.7.6-alpha",
36
- "@hardkas/kaspa-rpc": "0.7.6-alpha"
26
+ "@hardkas/artifacts": "0.7.7-alpha",
27
+ "@hardkas/accounts": "0.7.7-alpha",
28
+ "@hardkas/core": "0.7.7-alpha",
29
+ "@hardkas/kaspa-rpc": "0.7.7-alpha",
30
+ "@hardkas/localnet": "0.7.7-alpha",
31
+ "@hardkas/query": "0.7.7-alpha",
32
+ "@hardkas/config": "0.7.7-alpha",
33
+ "@hardkas/simulator": "0.7.7-alpha",
34
+ "@hardkas/tx-builder": "0.7.7-alpha",
35
+ "@hardkas/l2": "0.7.7-alpha",
36
+ "@hardkas/wallet-adapter": "0.7.7-alpha"
37
37
  },
38
38
  "devDependencies": {
39
39
  "tsup": "^8.3.5",
40
40
  "typescript": "^5.7.2",
41
41
  "vitest": "^2.1.8",
42
- "@hardkas/query-store": "0.7.6-alpha"
42
+ "@hardkas/query-store": "0.7.7-alpha"
43
43
  },
44
44
  "license": "MIT",
45
45
  "author": "Javier Rodriguez",