@hardkas/sdk 0.1.0
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/LICENSE +21 -0
- package/dist/index.d.ts +160 -0
- package/dist/index.js +338 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Javier Rodriguez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as _hardkas_config from '@hardkas/config';
|
|
2
|
+
import { LoadedHardkasConfig } from '@hardkas/config';
|
|
3
|
+
import { KaspaRpcClient } from '@hardkas/kaspa-rpc';
|
|
4
|
+
import { NetworkId } from '@hardkas/core';
|
|
5
|
+
export { ArtifactId, HardkasError, KaspaAddress, LineageId, NetworkId, SOMPI_PER_KAS, TxId, formatSompi, parseKasToSompi } from '@hardkas/core';
|
|
6
|
+
import { TxPlanArtifact, SignedTxArtifact, TxReceiptArtifact } from '@hardkas/artifacts';
|
|
7
|
+
export { ARTIFACT_SCHEMAS, HARDKAS_VERSION, SignedTxArtifact, TxPlanArtifact, TxReceiptArtifact, TxTraceArtifact, createTxPlanArtifact, writeArtifact } from '@hardkas/artifacts';
|
|
8
|
+
import { HardkasAccount } from '@hardkas/accounts';
|
|
9
|
+
export { signTxPlanArtifact } from '@hardkas/accounts';
|
|
10
|
+
import { L2NetworkProfile } from '@hardkas/l2';
|
|
11
|
+
export { buildPaymentPlan } from '@hardkas/tx-builder';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* HardKAS Accounts Module
|
|
15
|
+
* @alpha
|
|
16
|
+
*/
|
|
17
|
+
declare class HardkasAccounts {
|
|
18
|
+
private sdk;
|
|
19
|
+
constructor(sdk: Hardkas);
|
|
20
|
+
/**
|
|
21
|
+
* Resolves an account by name or address.
|
|
22
|
+
*/
|
|
23
|
+
resolve(nameOrAddress: string): Promise<HardkasAccount>;
|
|
24
|
+
/**
|
|
25
|
+
* Fetches the balance for an account.
|
|
26
|
+
*/
|
|
27
|
+
getBalance(accountNameOrAddress: string): Promise<{
|
|
28
|
+
sompi: bigint;
|
|
29
|
+
formatted: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* HardKAS Transaction Module
|
|
35
|
+
* @alpha
|
|
36
|
+
*/
|
|
37
|
+
declare class HardkasTx {
|
|
38
|
+
private sdk;
|
|
39
|
+
constructor(sdk: Hardkas);
|
|
40
|
+
/**
|
|
41
|
+
* Plans a transaction.
|
|
42
|
+
*/
|
|
43
|
+
plan(options: {
|
|
44
|
+
from: string | HardkasAccount;
|
|
45
|
+
to: string | HardkasAccount;
|
|
46
|
+
amount: string | bigint;
|
|
47
|
+
feeRate?: bigint;
|
|
48
|
+
}): Promise<TxPlanArtifact>;
|
|
49
|
+
/**
|
|
50
|
+
* Signs a transaction plan.
|
|
51
|
+
*/
|
|
52
|
+
sign(plan: TxPlanArtifact, account?: HardkasAccount | string): Promise<SignedTxArtifact>;
|
|
53
|
+
/**
|
|
54
|
+
* Sends a signed transaction.
|
|
55
|
+
*/
|
|
56
|
+
send(signed: SignedTxArtifact): Promise<TxReceiptArtifact>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* HardKAS L2 Module
|
|
61
|
+
* @alpha
|
|
62
|
+
*/
|
|
63
|
+
declare class HardkasL2 {
|
|
64
|
+
/**
|
|
65
|
+
* Lists all available L2 network profiles.
|
|
66
|
+
*/
|
|
67
|
+
listProfiles(): readonly L2NetworkProfile[];
|
|
68
|
+
/**
|
|
69
|
+
* Gets a specific L2 network profile by name.
|
|
70
|
+
*/
|
|
71
|
+
getProfile(name: string): L2NetworkProfile | null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* HardKAS Operational Query Module
|
|
76
|
+
*
|
|
77
|
+
* Note: readEvents, correlate, and correlation types were removed from
|
|
78
|
+
* @hardkas/query. These will be re-implemented when the query API stabilizes.
|
|
79
|
+
* @alpha
|
|
80
|
+
*/
|
|
81
|
+
declare class HardkasQuery {
|
|
82
|
+
private sdk;
|
|
83
|
+
private _engine;
|
|
84
|
+
constructor(sdk: Hardkas);
|
|
85
|
+
/**
|
|
86
|
+
* Internal lazy-loaded query engine.
|
|
87
|
+
*/
|
|
88
|
+
private getEngine;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* HardKAS Localnet Simulation Module
|
|
93
|
+
*/
|
|
94
|
+
declare class HardkasLocalnet {
|
|
95
|
+
private sdk;
|
|
96
|
+
constructor(sdk: Hardkas);
|
|
97
|
+
/**
|
|
98
|
+
* Status check for the localnet simulation.
|
|
99
|
+
*/
|
|
100
|
+
isAlive(): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* Future: control localnet process/container from here.
|
|
103
|
+
*/
|
|
104
|
+
start(): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface TaskArgs {
|
|
108
|
+
[key: string]: string | boolean | undefined;
|
|
109
|
+
}
|
|
110
|
+
interface TaskContext {
|
|
111
|
+
hardkas: Hardkas;
|
|
112
|
+
args: TaskArgs;
|
|
113
|
+
}
|
|
114
|
+
type TaskAction = (ctx: TaskContext) => Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Defines a new HardKAS task.
|
|
117
|
+
* Used in hardkas.config.ts to extend CLI functionality.
|
|
118
|
+
*/
|
|
119
|
+
declare const defineTask: {
|
|
120
|
+
(name: string, action: TaskAction): void;
|
|
121
|
+
(name: string, description: string, action: TaskAction): void;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
interface HardkasOptions {
|
|
125
|
+
cwd?: string;
|
|
126
|
+
configPath?: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* HardKAS SDK - Main Entry Point
|
|
130
|
+
*
|
|
131
|
+
* Provides a high-level facade for interacting with the Kaspa ecosystem.
|
|
132
|
+
* Acts as a DI container and coordinator.
|
|
133
|
+
*/
|
|
134
|
+
declare class Hardkas {
|
|
135
|
+
readonly config: LoadedHardkasConfig;
|
|
136
|
+
readonly accounts: HardkasAccounts;
|
|
137
|
+
readonly tx: HardkasTx;
|
|
138
|
+
readonly l2: HardkasL2;
|
|
139
|
+
readonly query: HardkasQuery;
|
|
140
|
+
readonly localnet: HardkasLocalnet;
|
|
141
|
+
readonly rpc: KaspaRpcClient;
|
|
142
|
+
private constructor();
|
|
143
|
+
private resolveRpcUrl;
|
|
144
|
+
/**
|
|
145
|
+
* Opens a HardKAS project in the given directory.
|
|
146
|
+
*/
|
|
147
|
+
static open(dirOrOptions?: string | HardkasOptions): Promise<Hardkas>;
|
|
148
|
+
/**
|
|
149
|
+
* Alias for open(). Used in most examples.
|
|
150
|
+
*/
|
|
151
|
+
static create(dirOrOptions?: string | HardkasOptions): Promise<Hardkas>;
|
|
152
|
+
/**
|
|
153
|
+
* Current active network name.
|
|
154
|
+
*/
|
|
155
|
+
get network(): NetworkId;
|
|
156
|
+
get sdkConfig(): _hardkas_config.HardkasConfig;
|
|
157
|
+
get cwd(): string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { Hardkas, HardkasAccounts, HardkasL2, HardkasLocalnet, type HardkasOptions, HardkasQuery, HardkasTx, type TaskArgs, type TaskContext, defineTask };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { loadHardkasConfig as loadConfig } from "@hardkas/config";
|
|
3
|
+
import { JsonWrpcKaspaClient } from "@hardkas/kaspa-rpc";
|
|
4
|
+
|
|
5
|
+
// src/accounts.ts
|
|
6
|
+
import {
|
|
7
|
+
resolveHardkasAccount
|
|
8
|
+
} from "@hardkas/accounts";
|
|
9
|
+
import { formatSompi } from "@hardkas/core";
|
|
10
|
+
var HardkasAccounts = class {
|
|
11
|
+
constructor(sdk) {
|
|
12
|
+
this.sdk = sdk;
|
|
13
|
+
}
|
|
14
|
+
sdk;
|
|
15
|
+
/**
|
|
16
|
+
* Resolves an account by name or address.
|
|
17
|
+
*/
|
|
18
|
+
async resolve(nameOrAddress) {
|
|
19
|
+
return resolveHardkasAccount({
|
|
20
|
+
nameOrAddress,
|
|
21
|
+
config: this.sdk.config.config
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fetches the balance for an account.
|
|
26
|
+
*/
|
|
27
|
+
async getBalance(accountNameOrAddress) {
|
|
28
|
+
const account = await this.resolve(accountNameOrAddress);
|
|
29
|
+
if (!account.address) throw new Error(`Account ${accountNameOrAddress} has no address`);
|
|
30
|
+
const { balanceSompi } = await this.sdk.rpc.getBalanceByAddress(account.address);
|
|
31
|
+
const sompi = BigInt(balanceSompi);
|
|
32
|
+
return {
|
|
33
|
+
sompi,
|
|
34
|
+
formatted: formatSompi(sompi)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/tx.ts
|
|
40
|
+
import {
|
|
41
|
+
buildPaymentPlan
|
|
42
|
+
} from "@hardkas/tx-builder";
|
|
43
|
+
import {
|
|
44
|
+
HARDKAS_VERSION,
|
|
45
|
+
getBroadcastableSignedTransaction,
|
|
46
|
+
writeArtifact,
|
|
47
|
+
getDefaultReceiptPath,
|
|
48
|
+
createTxPlanArtifact,
|
|
49
|
+
calculateContentHash
|
|
50
|
+
} from "@hardkas/artifacts";
|
|
51
|
+
import { signTxPlanArtifact } from "@hardkas/accounts";
|
|
52
|
+
import { parseKasToSompi } from "@hardkas/core";
|
|
53
|
+
var HardkasTx = class {
|
|
54
|
+
constructor(sdk) {
|
|
55
|
+
this.sdk = sdk;
|
|
56
|
+
}
|
|
57
|
+
sdk;
|
|
58
|
+
/**
|
|
59
|
+
* Plans a transaction.
|
|
60
|
+
*/
|
|
61
|
+
async plan(options) {
|
|
62
|
+
const fromAccount = typeof options.from === "string" ? await this.sdk.accounts.resolve(options.from) : options.from;
|
|
63
|
+
const toAccount = typeof options.to === "string" ? await this.sdk.accounts.resolve(options.to) : options.to;
|
|
64
|
+
if (!fromAccount.address) throw new Error(`From account ${fromAccount.name} has no address.`);
|
|
65
|
+
if (!toAccount.address) throw new Error(`To account ${toAccount.name} has no address.`);
|
|
66
|
+
const amountSompi = typeof options.amount === "string" ? parseKasToSompi(options.amount) : options.amount;
|
|
67
|
+
const rpcUtxos = await this.sdk.rpc.getUtxosByAddress(fromAccount.address);
|
|
68
|
+
const builderUtxos = rpcUtxos.map((u) => ({
|
|
69
|
+
outpoint: {
|
|
70
|
+
transactionId: u.outpoint.transactionId,
|
|
71
|
+
index: u.outpoint.index
|
|
72
|
+
},
|
|
73
|
+
address: u.address,
|
|
74
|
+
amountSompi: u.amountSompi,
|
|
75
|
+
scriptPublicKey: u.scriptPublicKey || ""
|
|
76
|
+
}));
|
|
77
|
+
const builderPlan = buildPaymentPlan({
|
|
78
|
+
fromAddress: fromAccount.address,
|
|
79
|
+
availableUtxos: builderUtxos,
|
|
80
|
+
outputs: [{
|
|
81
|
+
address: toAccount.address,
|
|
82
|
+
amountSompi
|
|
83
|
+
}],
|
|
84
|
+
feeRateSompiPerMass: options.feeRate ?? 1n
|
|
85
|
+
});
|
|
86
|
+
return createTxPlanArtifact({
|
|
87
|
+
networkId: this.sdk.network,
|
|
88
|
+
mode: "simulated",
|
|
89
|
+
from: {
|
|
90
|
+
input: fromAccount.name || fromAccount.address,
|
|
91
|
+
address: fromAccount.address,
|
|
92
|
+
accountName: fromAccount.name
|
|
93
|
+
},
|
|
94
|
+
to: {
|
|
95
|
+
input: toAccount.name || toAccount.address,
|
|
96
|
+
address: toAccount.address
|
|
97
|
+
},
|
|
98
|
+
amountSompi,
|
|
99
|
+
plan: builderPlan
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Signs a transaction plan.
|
|
104
|
+
*/
|
|
105
|
+
async sign(plan, account) {
|
|
106
|
+
let resolvedAccount;
|
|
107
|
+
if (typeof account === "string") {
|
|
108
|
+
resolvedAccount = await this.sdk.accounts.resolve(account);
|
|
109
|
+
} else if (account) {
|
|
110
|
+
resolvedAccount = account;
|
|
111
|
+
} else {
|
|
112
|
+
if (!plan.from.accountName) throw new Error("Plan does not specify an account name and no account was provided for signing.");
|
|
113
|
+
resolvedAccount = await this.sdk.accounts.resolve(plan.from.accountName);
|
|
114
|
+
}
|
|
115
|
+
return signTxPlanArtifact({
|
|
116
|
+
planArtifact: plan,
|
|
117
|
+
account: resolvedAccount,
|
|
118
|
+
config: this.sdk.config.config
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Sends a signed transaction.
|
|
123
|
+
*/
|
|
124
|
+
async send(signed) {
|
|
125
|
+
const broadcastable = getBroadcastableSignedTransaction(signed);
|
|
126
|
+
const result = await this.sdk.rpc.submitTransaction(broadcastable.rawTransaction);
|
|
127
|
+
const txId = result.transactionId;
|
|
128
|
+
if (!txId) throw new Error("Broadcast failed: RPC returned no transaction ID.");
|
|
129
|
+
const receipt = {
|
|
130
|
+
schema: "hardkas.txReceipt",
|
|
131
|
+
hardkasVersion: HARDKAS_VERSION,
|
|
132
|
+
version: "1.0.0-alpha",
|
|
133
|
+
networkId: signed.networkId,
|
|
134
|
+
mode: signed.mode,
|
|
135
|
+
status: "accepted",
|
|
136
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
137
|
+
txId,
|
|
138
|
+
from: {
|
|
139
|
+
address: signed.from.address
|
|
140
|
+
},
|
|
141
|
+
to: {
|
|
142
|
+
address: signed.to.address
|
|
143
|
+
},
|
|
144
|
+
amountSompi: String(signed.amountSompi),
|
|
145
|
+
feeSompi: String(signed.estimatedFeeSompi || "0")
|
|
146
|
+
};
|
|
147
|
+
receipt.contentHash = calculateContentHash(receipt);
|
|
148
|
+
const receiptPath = getDefaultReceiptPath(txId, this.sdk.config.cwd);
|
|
149
|
+
await writeArtifact(receiptPath, receipt);
|
|
150
|
+
return {
|
|
151
|
+
...receipt,
|
|
152
|
+
receiptPath
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/l2.ts
|
|
158
|
+
import {
|
|
159
|
+
listL2Profiles,
|
|
160
|
+
getL2Profile
|
|
161
|
+
} from "@hardkas/l2";
|
|
162
|
+
var HardkasL2 = class {
|
|
163
|
+
/**
|
|
164
|
+
* Lists all available L2 network profiles.
|
|
165
|
+
*/
|
|
166
|
+
listProfiles() {
|
|
167
|
+
return listL2Profiles();
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Gets a specific L2 network profile by name.
|
|
171
|
+
*/
|
|
172
|
+
getProfile(name) {
|
|
173
|
+
return getL2Profile(name);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/query.ts
|
|
178
|
+
var HardkasQuery = class {
|
|
179
|
+
constructor(sdk) {
|
|
180
|
+
this.sdk = sdk;
|
|
181
|
+
}
|
|
182
|
+
sdk;
|
|
183
|
+
_engine = null;
|
|
184
|
+
/**
|
|
185
|
+
* Internal lazy-loaded query engine.
|
|
186
|
+
*/
|
|
187
|
+
async getEngine() {
|
|
188
|
+
if (this._engine) return this._engine;
|
|
189
|
+
const { QueryEngine } = await import("@hardkas/query");
|
|
190
|
+
this._engine = new QueryEngine({
|
|
191
|
+
artifactDir: this.sdk.config.cwd
|
|
192
|
+
});
|
|
193
|
+
return this._engine;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/localnet.ts
|
|
198
|
+
var HardkasLocalnet = class {
|
|
199
|
+
constructor(sdk) {
|
|
200
|
+
this.sdk = sdk;
|
|
201
|
+
}
|
|
202
|
+
sdk;
|
|
203
|
+
/**
|
|
204
|
+
* Status check for the localnet simulation.
|
|
205
|
+
*/
|
|
206
|
+
async isAlive() {
|
|
207
|
+
try {
|
|
208
|
+
const info = await this.sdk.rpc.getInfo();
|
|
209
|
+
return info.isSynced === true;
|
|
210
|
+
} catch {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Future: control localnet process/container from here.
|
|
216
|
+
*/
|
|
217
|
+
async start() {
|
|
218
|
+
console.log("Localnet control via SDK is not yet implemented.");
|
|
219
|
+
console.log("Please use 'hardkas localnet' CLI command.");
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// src/tasks.ts
|
|
224
|
+
var TaskRegistry = class {
|
|
225
|
+
tasks = /* @__PURE__ */ new Map();
|
|
226
|
+
defineTask(name, descriptionOrAction, action) {
|
|
227
|
+
let description;
|
|
228
|
+
let finalAction;
|
|
229
|
+
if (typeof descriptionOrAction === "string") {
|
|
230
|
+
description = descriptionOrAction;
|
|
231
|
+
finalAction = action;
|
|
232
|
+
} else {
|
|
233
|
+
finalAction = descriptionOrAction;
|
|
234
|
+
}
|
|
235
|
+
this.tasks.set(name, {
|
|
236
|
+
name,
|
|
237
|
+
description,
|
|
238
|
+
action: finalAction
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
getTask(name) {
|
|
242
|
+
return this.tasks.get(name);
|
|
243
|
+
}
|
|
244
|
+
getTasks() {
|
|
245
|
+
return Array.from(this.tasks.values());
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var taskRegistry = new TaskRegistry();
|
|
249
|
+
var defineTask = taskRegistry.defineTask.bind(taskRegistry);
|
|
250
|
+
|
|
251
|
+
// src/index.ts
|
|
252
|
+
import { buildPaymentPlan as buildPaymentPlan2 } from "@hardkas/tx-builder";
|
|
253
|
+
import { signTxPlanArtifact as signTxPlanArtifact2 } from "@hardkas/accounts";
|
|
254
|
+
import {
|
|
255
|
+
writeArtifact as writeArtifact2,
|
|
256
|
+
createTxPlanArtifact as createTxPlanArtifact2,
|
|
257
|
+
ARTIFACT_SCHEMAS,
|
|
258
|
+
HARDKAS_VERSION as HARDKAS_VERSION2
|
|
259
|
+
} from "@hardkas/artifacts";
|
|
260
|
+
import {
|
|
261
|
+
SOMPI_PER_KAS,
|
|
262
|
+
HardkasError,
|
|
263
|
+
parseKasToSompi as parseKasToSompi2,
|
|
264
|
+
formatSompi as formatSompi2
|
|
265
|
+
} from "@hardkas/core";
|
|
266
|
+
var Hardkas = class _Hardkas {
|
|
267
|
+
constructor(config, rpc) {
|
|
268
|
+
this.config = config;
|
|
269
|
+
this.rpc = rpc || new JsonWrpcKaspaClient({
|
|
270
|
+
rpcUrl: this.resolveRpcUrl()
|
|
271
|
+
});
|
|
272
|
+
this.accounts = new HardkasAccounts(this);
|
|
273
|
+
this.tx = new HardkasTx(this);
|
|
274
|
+
this.l2 = new HardkasL2();
|
|
275
|
+
this.query = new HardkasQuery(this);
|
|
276
|
+
this.localnet = new HardkasLocalnet(this);
|
|
277
|
+
}
|
|
278
|
+
config;
|
|
279
|
+
accounts;
|
|
280
|
+
tx;
|
|
281
|
+
l2;
|
|
282
|
+
query;
|
|
283
|
+
localnet;
|
|
284
|
+
rpc;
|
|
285
|
+
resolveRpcUrl() {
|
|
286
|
+
const networkId = this.config.config.defaultNetwork || "simnet";
|
|
287
|
+
const target = this.config.config.networks?.[networkId];
|
|
288
|
+
if (target && (target.kind === "kaspa-rpc" || target.kind === "igra" || target.kind === "kaspa-node")) {
|
|
289
|
+
return target.rpcUrl || "ws://127.0.0.1:18210";
|
|
290
|
+
}
|
|
291
|
+
return "ws://127.0.0.1:18210";
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Opens a HardKAS project in the given directory.
|
|
295
|
+
*/
|
|
296
|
+
static async open(dirOrOptions = ".") {
|
|
297
|
+
const options = typeof dirOrOptions === "string" ? { cwd: dirOrOptions } : dirOrOptions;
|
|
298
|
+
const loaded = await loadConfig(options);
|
|
299
|
+
return new _Hardkas(loaded);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Alias for open(). Used in most examples.
|
|
303
|
+
*/
|
|
304
|
+
static async create(dirOrOptions = ".") {
|
|
305
|
+
return this.open(dirOrOptions);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Current active network name.
|
|
309
|
+
*/
|
|
310
|
+
get network() {
|
|
311
|
+
return this.sdkConfig.defaultNetwork || "simnet";
|
|
312
|
+
}
|
|
313
|
+
get sdkConfig() {
|
|
314
|
+
return this.config.config;
|
|
315
|
+
}
|
|
316
|
+
get cwd() {
|
|
317
|
+
return this.config.cwd;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
export {
|
|
321
|
+
ARTIFACT_SCHEMAS,
|
|
322
|
+
HARDKAS_VERSION2 as HARDKAS_VERSION,
|
|
323
|
+
Hardkas,
|
|
324
|
+
HardkasAccounts,
|
|
325
|
+
HardkasError,
|
|
326
|
+
HardkasL2,
|
|
327
|
+
HardkasLocalnet,
|
|
328
|
+
HardkasQuery,
|
|
329
|
+
HardkasTx,
|
|
330
|
+
SOMPI_PER_KAS,
|
|
331
|
+
buildPaymentPlan2 as buildPaymentPlan,
|
|
332
|
+
createTxPlanArtifact2 as createTxPlanArtifact,
|
|
333
|
+
defineTask,
|
|
334
|
+
formatSompi2 as formatSompi,
|
|
335
|
+
parseKasToSompi2 as parseKasToSompi,
|
|
336
|
+
signTxPlanArtifact2 as signTxPlanArtifact,
|
|
337
|
+
writeArtifact2 as writeArtifact
|
|
338
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hardkas/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"README.md",
|
|
8
|
+
"LICENSE"
|
|
9
|
+
],
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@hardkas/accounts": "0.1.0",
|
|
17
|
+
"@hardkas/artifacts": "0.1.0",
|
|
18
|
+
"@hardkas/kaspa-rpc": "0.1.0",
|
|
19
|
+
"@hardkas/config": "0.1.0",
|
|
20
|
+
"@hardkas/query": "0.1.0",
|
|
21
|
+
"@hardkas/core": "0.1.0",
|
|
22
|
+
"@hardkas/l2": "0.1.0",
|
|
23
|
+
"@hardkas/simulator": "0.1.0",
|
|
24
|
+
"@hardkas/tx-builder": "0.1.0",
|
|
25
|
+
"@hardkas/wallet-adapter": "0.1.0",
|
|
26
|
+
"@hardkas/localnet": "0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"tsup": "^8.3.5",
|
|
30
|
+
"typescript": "^5.7.2",
|
|
31
|
+
"vitest": "^2.1.8"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"author": "Javier Rodriguez",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/jrodrg92/Hardkas.git",
|
|
38
|
+
"directory": "packages/sdk"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/jrodrg92/Hardkas/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/jrodrg92/Hardkas/tree/main/packages/sdk#readme",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"lint": "eslint ."
|
|
49
|
+
}
|
|
50
|
+
}
|