@clawlabz/clawnetwork-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/dist/client.d.ts +78 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +186 -0
- package/dist/client.js.map +1 -0
- package/dist/hash.d.ts +13 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +23 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/rpc.d.ts +33 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +47 -0
- package/dist/rpc.js.map +1 -0
- package/dist/serialization.d.ts +26 -0
- package/dist/serialization.d.ts.map +1 -0
- package/dist/serialization.js +155 -0
- package/dist/serialization.js.map +1 -0
- package/dist/types.d.ts +106 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/dist/wallet.d.ts +30 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +64 -0
- package/dist/wallet.js.map +1 -0
- package/package.json +45 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { RpcClient } from './rpc.js';
|
|
2
|
+
import { TxType } from './types.js';
|
|
3
|
+
import type { ClawClientConfig, AgentIdentity, TokenDef, ReputationAttestation, ServiceEntry, BlockInfo, TransactionReceipt, AgentRegisterParams, TokenTransferParams, TokenCreateParams, TokenMintTransferParams, ReputationAttestParams, ServiceRegisterParams } from './types.js';
|
|
4
|
+
declare class AgentModule {
|
|
5
|
+
private rpc;
|
|
6
|
+
private sendTx;
|
|
7
|
+
constructor(rpc: RpcClient, sendTx: (txType: TxType, payload: Uint8Array) => Promise<string>);
|
|
8
|
+
/** Register an agent on-chain. Returns the tx hash. */
|
|
9
|
+
register(params: AgentRegisterParams): Promise<string>;
|
|
10
|
+
/** Look up an agent by address (hex). */
|
|
11
|
+
get(address: string): Promise<AgentIdentity | null>;
|
|
12
|
+
}
|
|
13
|
+
declare class TokenModule {
|
|
14
|
+
private rpc;
|
|
15
|
+
private sendTx;
|
|
16
|
+
constructor(rpc: RpcClient, sendTx: (txType: TxType, payload: Uint8Array) => Promise<string>);
|
|
17
|
+
/** Create a new custom token. Returns tx hash. */
|
|
18
|
+
create(params: TokenCreateParams): Promise<string>;
|
|
19
|
+
/** Transfer a custom token. Returns tx hash. */
|
|
20
|
+
transfer(params: TokenMintTransferParams): Promise<string>;
|
|
21
|
+
/** Get custom token balance. */
|
|
22
|
+
getBalance(address: string, tokenId: string): Promise<bigint>;
|
|
23
|
+
/** Get token definition info. */
|
|
24
|
+
getInfo(tokenId: string): Promise<TokenDef | null>;
|
|
25
|
+
}
|
|
26
|
+
declare class ReputationModule {
|
|
27
|
+
private rpc;
|
|
28
|
+
private sendTx;
|
|
29
|
+
constructor(rpc: RpcClient, sendTx: (txType: TxType, payload: Uint8Array) => Promise<string>);
|
|
30
|
+
/** Submit a reputation attestation. Returns tx hash. */
|
|
31
|
+
attest(params: ReputationAttestParams): Promise<string>;
|
|
32
|
+
/** Get all reputation attestations for an address. */
|
|
33
|
+
get(address: string): Promise<ReputationAttestation[]>;
|
|
34
|
+
}
|
|
35
|
+
declare class ServiceModule {
|
|
36
|
+
private rpc;
|
|
37
|
+
private sendTx;
|
|
38
|
+
constructor(rpc: RpcClient, sendTx: (txType: TxType, payload: Uint8Array) => Promise<string>);
|
|
39
|
+
/** Register a service. Returns tx hash. */
|
|
40
|
+
register(params: ServiceRegisterParams): Promise<string>;
|
|
41
|
+
/** Search services, optionally by type. */
|
|
42
|
+
search(filter?: {
|
|
43
|
+
serviceType?: string;
|
|
44
|
+
}): Promise<ServiceEntry[]>;
|
|
45
|
+
}
|
|
46
|
+
declare class BlockModule {
|
|
47
|
+
private rpc;
|
|
48
|
+
constructor(rpc: RpcClient);
|
|
49
|
+
/** Get the latest block number (height). */
|
|
50
|
+
getLatest(): Promise<number>;
|
|
51
|
+
/** Get a block by height. */
|
|
52
|
+
getByNumber(height: number): Promise<BlockInfo | null>;
|
|
53
|
+
}
|
|
54
|
+
export declare class ClawClient {
|
|
55
|
+
private rpc;
|
|
56
|
+
private wallet?;
|
|
57
|
+
readonly agent: AgentModule;
|
|
58
|
+
readonly token: TokenModule;
|
|
59
|
+
readonly reputation: ReputationModule;
|
|
60
|
+
readonly service: ServiceModule;
|
|
61
|
+
readonly block: BlockModule;
|
|
62
|
+
constructor(config?: ClawClientConfig);
|
|
63
|
+
/** Transfer native CLW tokens. Returns tx hash. */
|
|
64
|
+
transfer(params: TokenTransferParams): Promise<string>;
|
|
65
|
+
/** Get native CLW balance for an address (hex). */
|
|
66
|
+
getBalance(address: string): Promise<bigint>;
|
|
67
|
+
/** Get the current nonce for an address (hex). */
|
|
68
|
+
getNonce(address: string): Promise<number>;
|
|
69
|
+
/** Get a transaction receipt by hash (hex). */
|
|
70
|
+
getTransactionReceipt(txHash: string): Promise<TransactionReceipt | null>;
|
|
71
|
+
/**
|
|
72
|
+
* Build a signed transaction and submit it via RPC.
|
|
73
|
+
* Automatically fetches the current nonce.
|
|
74
|
+
*/
|
|
75
|
+
private buildAndSendTx;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAmB,MAAM,UAAU,CAAC;AAYtD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,EAEV,gBAAgB,EAEhB,aAAa,EACb,QAAQ,EACR,qBAAqB,EACrB,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACtB,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AAC;IAKlD,kDAAkD;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD,+CAA+C;IACzC,qBAAqB,CACzB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IASrC;;;OAGG;YACW,cAAc;CA4B7B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// ClawNetwork SDK — ClawClient (high-level API)
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
import { RpcClient, DEFAULT_RPC_URL } from './rpc.js';
|
|
5
|
+
import { toHex, fromHex } from './wallet.js';
|
|
6
|
+
import { signableBytes, serializeTransaction, encodeAgentRegisterPayload, encodeTokenTransferPayload, encodeTokenCreatePayload, encodeTokenMintTransferPayload, encodeReputationAttestPayload, encodeServiceRegisterPayload, } from './serialization.js';
|
|
7
|
+
import { TxType } from './types.js';
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Helpers
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
function requireWallet(wallet) {
|
|
12
|
+
if (!wallet)
|
|
13
|
+
throw new Error('Wallet is required for signing transactions');
|
|
14
|
+
return wallet;
|
|
15
|
+
}
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Sub-modules exposed as client.agent, client.token, etc.
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
class AgentModule {
|
|
20
|
+
rpc;
|
|
21
|
+
sendTx;
|
|
22
|
+
constructor(rpc, sendTx) {
|
|
23
|
+
this.rpc = rpc;
|
|
24
|
+
this.sendTx = sendTx;
|
|
25
|
+
}
|
|
26
|
+
/** Register an agent on-chain. Returns the tx hash. */
|
|
27
|
+
async register(params) {
|
|
28
|
+
const payload = encodeAgentRegisterPayload(params.name, params.metadata);
|
|
29
|
+
return this.sendTx(TxType.AgentRegister, payload);
|
|
30
|
+
}
|
|
31
|
+
/** Look up an agent by address (hex). */
|
|
32
|
+
async get(address) {
|
|
33
|
+
return this.rpc.call('clw_getAgent', [address]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class TokenModule {
|
|
37
|
+
rpc;
|
|
38
|
+
sendTx;
|
|
39
|
+
constructor(rpc, sendTx) {
|
|
40
|
+
this.rpc = rpc;
|
|
41
|
+
this.sendTx = sendTx;
|
|
42
|
+
}
|
|
43
|
+
/** Create a new custom token. Returns tx hash. */
|
|
44
|
+
async create(params) {
|
|
45
|
+
const payload = encodeTokenCreatePayload(params.name, params.symbol, params.decimals, params.totalSupply);
|
|
46
|
+
return this.sendTx(TxType.TokenCreate, payload);
|
|
47
|
+
}
|
|
48
|
+
/** Transfer a custom token. Returns tx hash. */
|
|
49
|
+
async transfer(params) {
|
|
50
|
+
const payload = encodeTokenMintTransferPayload(fromHex(params.tokenId), fromHex(params.to), params.amount);
|
|
51
|
+
return this.sendTx(TxType.TokenMintTransfer, payload);
|
|
52
|
+
}
|
|
53
|
+
/** Get custom token balance. */
|
|
54
|
+
async getBalance(address, tokenId) {
|
|
55
|
+
const result = await this.rpc.call('clw_getTokenBalance', [
|
|
56
|
+
address,
|
|
57
|
+
tokenId,
|
|
58
|
+
]);
|
|
59
|
+
return BigInt(result);
|
|
60
|
+
}
|
|
61
|
+
/** Get token definition info. */
|
|
62
|
+
async getInfo(tokenId) {
|
|
63
|
+
return this.rpc.call('clw_getTokenInfo', [tokenId]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class ReputationModule {
|
|
67
|
+
rpc;
|
|
68
|
+
sendTx;
|
|
69
|
+
constructor(rpc, sendTx) {
|
|
70
|
+
this.rpc = rpc;
|
|
71
|
+
this.sendTx = sendTx;
|
|
72
|
+
}
|
|
73
|
+
/** Submit a reputation attestation. Returns tx hash. */
|
|
74
|
+
async attest(params) {
|
|
75
|
+
const payload = encodeReputationAttestPayload(fromHex(params.to), params.category, params.score, params.platform, params.memo);
|
|
76
|
+
return this.sendTx(TxType.ReputationAttest, payload);
|
|
77
|
+
}
|
|
78
|
+
/** Get all reputation attestations for an address. */
|
|
79
|
+
async get(address) {
|
|
80
|
+
return this.rpc.call('clw_getReputation', [
|
|
81
|
+
address,
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
class ServiceModule {
|
|
86
|
+
rpc;
|
|
87
|
+
sendTx;
|
|
88
|
+
constructor(rpc, sendTx) {
|
|
89
|
+
this.rpc = rpc;
|
|
90
|
+
this.sendTx = sendTx;
|
|
91
|
+
}
|
|
92
|
+
/** Register a service. Returns tx hash. */
|
|
93
|
+
async register(params) {
|
|
94
|
+
const payload = encodeServiceRegisterPayload(params.serviceType, params.description, fromHex(params.priceToken), params.priceAmount, params.endpoint, params.active);
|
|
95
|
+
return this.sendTx(TxType.ServiceRegister, payload);
|
|
96
|
+
}
|
|
97
|
+
/** Search services, optionally by type. */
|
|
98
|
+
async search(filter) {
|
|
99
|
+
const params = filter?.serviceType
|
|
100
|
+
? [filter.serviceType]
|
|
101
|
+
: [];
|
|
102
|
+
return this.rpc.call('clw_getServices', params);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
class BlockModule {
|
|
106
|
+
rpc;
|
|
107
|
+
constructor(rpc) {
|
|
108
|
+
this.rpc = rpc;
|
|
109
|
+
}
|
|
110
|
+
/** Get the latest block number (height). */
|
|
111
|
+
async getLatest() {
|
|
112
|
+
return this.rpc.call('clw_blockNumber');
|
|
113
|
+
}
|
|
114
|
+
/** Get a block by height. */
|
|
115
|
+
async getByNumber(height) {
|
|
116
|
+
return this.rpc.call('clw_getBlockByNumber', [height]);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// ClawClient
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
export class ClawClient {
|
|
123
|
+
rpc;
|
|
124
|
+
wallet;
|
|
125
|
+
agent;
|
|
126
|
+
token;
|
|
127
|
+
reputation;
|
|
128
|
+
service;
|
|
129
|
+
block;
|
|
130
|
+
constructor(config = {}) {
|
|
131
|
+
this.rpc = new RpcClient(config.rpcUrl ?? DEFAULT_RPC_URL);
|
|
132
|
+
this.wallet = config.wallet;
|
|
133
|
+
const sendTx = this.buildAndSendTx.bind(this);
|
|
134
|
+
this.agent = new AgentModule(this.rpc, sendTx);
|
|
135
|
+
this.token = new TokenModule(this.rpc, sendTx);
|
|
136
|
+
this.reputation = new ReputationModule(this.rpc, sendTx);
|
|
137
|
+
this.service = new ServiceModule(this.rpc, sendTx);
|
|
138
|
+
this.block = new BlockModule(this.rpc);
|
|
139
|
+
}
|
|
140
|
+
// --- Top-level convenience methods ---
|
|
141
|
+
/** Transfer native CLW tokens. Returns tx hash. */
|
|
142
|
+
async transfer(params) {
|
|
143
|
+
const payload = encodeTokenTransferPayload(fromHex(params.to), params.amount);
|
|
144
|
+
return this.buildAndSendTx(TxType.TokenTransfer, payload);
|
|
145
|
+
}
|
|
146
|
+
/** Get native CLW balance for an address (hex). */
|
|
147
|
+
async getBalance(address) {
|
|
148
|
+
const result = await this.rpc.call('clw_getBalance', [address]);
|
|
149
|
+
return BigInt(result);
|
|
150
|
+
}
|
|
151
|
+
/** Get the current nonce for an address (hex). */
|
|
152
|
+
async getNonce(address) {
|
|
153
|
+
return this.rpc.call('clw_getNonce', [address]);
|
|
154
|
+
}
|
|
155
|
+
/** Get a transaction receipt by hash (hex). */
|
|
156
|
+
async getTransactionReceipt(txHash) {
|
|
157
|
+
return this.rpc.call('clw_getTransactionReceipt', [txHash]);
|
|
158
|
+
}
|
|
159
|
+
// --- Internal ---
|
|
160
|
+
/**
|
|
161
|
+
* Build a signed transaction and submit it via RPC.
|
|
162
|
+
* Automatically fetches the current nonce.
|
|
163
|
+
*/
|
|
164
|
+
async buildAndSendTx(txType, payload) {
|
|
165
|
+
const wallet = requireWallet(this.wallet);
|
|
166
|
+
// Fetch current nonce and increment
|
|
167
|
+
const currentNonce = await this.getNonce(wallet.address);
|
|
168
|
+
const nonce = BigInt(currentNonce + 1);
|
|
169
|
+
// Build unsigned transaction
|
|
170
|
+
const tx = {
|
|
171
|
+
txType,
|
|
172
|
+
from: wallet.publicKey,
|
|
173
|
+
nonce,
|
|
174
|
+
payload,
|
|
175
|
+
signature: new Uint8Array(64), // placeholder
|
|
176
|
+
};
|
|
177
|
+
// Sign
|
|
178
|
+
const msg = signableBytes(tx);
|
|
179
|
+
tx.signature = await wallet.sign(msg);
|
|
180
|
+
// Serialize and send
|
|
181
|
+
const serialized = serializeTransaction(tx);
|
|
182
|
+
const hex = toHex(serialized);
|
|
183
|
+
return this.rpc.call('clw_sendTransaction', [hex]);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gDAAgD;AAChD,8EAA8E;AAE9E,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,8BAA8B,EAC9B,6BAA6B,EAC7B,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAmBpC,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,SAAS,aAAa,CAAC,MAA8B;IACnD,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC5E,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,8EAA8E;AAC9E,0DAA0D;AAC1D,8EAA8E;AAE9E,MAAM,WAAW;IA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ACzB,MAAc;QAEd,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAClB,2BAA2B,EAC3B,CAAC,MAAM,CAAC,CACT,CAAC;IACJ,CAAC;IAED,mBAAmB;IAEnB;;;OAGG;IACK,KAAK,CAAC,cAAc,CAC1B,MAAc,EACd,OAAmB;QAEnB,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE1C,oCAAoC;QACpC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACzD,MAAM,KAAK,GAAG,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QAEvC,6BAA6B;QAC7B,MAAM,EAAE,GAAgB;YACtB,MAAM;YACN,IAAI,EAAE,MAAM,CAAC,SAAS;YACtB,KAAK;YACL,OAAO;YACP,SAAS,EAAE,IAAI,UAAU,CAAC,EAAE,CAAC,EAAE,cAAc;SAC9C,CAAC;QAEF,OAAO;QACP,MAAM,GAAG,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;QAC9B,EAAE,CAAC,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEtC,qBAAqB;QACrB,MAAM,UAAU,GAAG,oBAAoB,CAAC,EAAE,CAAC,CAAC;QAC5C,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAS,qBAAqB,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF"}
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Transaction } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compute the transaction hash: blake3(borsh_serialize(tx)).
|
|
4
|
+
*
|
|
5
|
+
* Returns the 32-byte hash as a Uint8Array.
|
|
6
|
+
* Matches `Transaction::hash()` in Rust.
|
|
7
|
+
*/
|
|
8
|
+
export declare function transactionHash(tx: Transaction): Uint8Array;
|
|
9
|
+
/**
|
|
10
|
+
* Compute the transaction hash and return it as a hex string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function transactionHashHex(tx: Transaction): string;
|
|
13
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,UAAU,CAG3D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,WAAW,GAAG,MAAM,CAE1D"}
|
package/dist/hash.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// ClawNetwork SDK — blake3 transaction hashing
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
import { blake3 } from '@noble/hashes/blake3.js';
|
|
5
|
+
import { serializeTransaction } from './serialization.js';
|
|
6
|
+
import { toHex } from './wallet.js';
|
|
7
|
+
/**
|
|
8
|
+
* Compute the transaction hash: blake3(borsh_serialize(tx)).
|
|
9
|
+
*
|
|
10
|
+
* Returns the 32-byte hash as a Uint8Array.
|
|
11
|
+
* Matches `Transaction::hash()` in Rust.
|
|
12
|
+
*/
|
|
13
|
+
export function transactionHash(tx) {
|
|
14
|
+
const serialized = serializeTransaction(tx);
|
|
15
|
+
return blake3(serialized);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Compute the transaction hash and return it as a hex string.
|
|
19
|
+
*/
|
|
20
|
+
export function transactionHashHex(tx) {
|
|
21
|
+
return toHex(transactionHash(tx));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+CAA+C;AAC/C,8EAA8E;AAE9E,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,EAAe;IAC7C,MAAM,UAAU,GAAG,oBAAoB,CAAC,EAAE,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,EAAe;IAChD,OAAO,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Wallet, toHex, fromHex } from './wallet.js';
|
|
2
|
+
export { ClawClient } from './client.js';
|
|
3
|
+
export { RpcClient, RpcError, DEFAULT_RPC_URL } from './rpc.js';
|
|
4
|
+
export { TxType } from './types.js';
|
|
5
|
+
export type { Transaction, ClawClientConfig, WalletLike, AgentIdentity, TokenDef, ReputationAttestation, ServiceEntry, BlockInfo, TransactionReceipt, AgentRegisterParams, TokenTransferParams, TokenCreateParams, TokenMintTransferParams, ReputationAttestParams, ServiceRegisterParams, } from './types.js';
|
|
6
|
+
export { signableBytes, serializeTransaction, encodeAgentRegisterPayload, encodeTokenTransferPayload, encodeTokenCreatePayload, encodeTokenMintTransferPayload, encodeReputationAttestPayload, encodeServiceRegisterPayload, } from './serialization.js';
|
|
7
|
+
export { transactionHash, transactionHashHex } from './hash.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGhE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,QAAQ,EACR,qBAAqB,EACrB,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,8BAA8B,EAC9B,6BAA6B,EAC7B,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @clawlabz/clawnetwork-sdk — Main entry point
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Core classes
|
|
5
|
+
export { Wallet, toHex, fromHex } from './wallet.js';
|
|
6
|
+
export { ClawClient } from './client.js';
|
|
7
|
+
export { RpcClient, RpcError, DEFAULT_RPC_URL } from './rpc.js';
|
|
8
|
+
// Types
|
|
9
|
+
export { TxType } from './types.js';
|
|
10
|
+
// Serialization (for advanced usage / testing)
|
|
11
|
+
export { signableBytes, serializeTransaction, encodeAgentRegisterPayload, encodeTokenTransferPayload, encodeTokenCreatePayload, encodeTokenMintTransferPayload, encodeReputationAttestPayload, encodeServiceRegisterPayload, } from './serialization.js';
|
|
12
|
+
// Hashing (for advanced usage / testing)
|
|
13
|
+
export { transactionHash, transactionHashHex } from './hash.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+CAA+C;AAC/C,8EAA8E;AAE9E,eAAe;AACf,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhE,QAAQ;AACR,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAmBpC,+CAA+C;AAC/C,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,8BAA8B,EAC9B,6BAA6B,EAC7B,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAE5B,yCAAyC;AACzC,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const DEFAULT_RPC_URL = "http://localhost:9710";
|
|
2
|
+
export interface JsonRpcRequest {
|
|
3
|
+
jsonrpc: '2.0';
|
|
4
|
+
id: number;
|
|
5
|
+
method: string;
|
|
6
|
+
params: unknown[];
|
|
7
|
+
}
|
|
8
|
+
export interface JsonRpcResponse<T = unknown> {
|
|
9
|
+
jsonrpc: '2.0';
|
|
10
|
+
id: number;
|
|
11
|
+
result?: T;
|
|
12
|
+
error?: {
|
|
13
|
+
code: number;
|
|
14
|
+
message: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare class RpcError extends Error {
|
|
18
|
+
code: number;
|
|
19
|
+
constructor(code: number, message: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Low-level JSON-RPC 2.0 client. Uses native `fetch` — no dependencies.
|
|
23
|
+
*/
|
|
24
|
+
export declare class RpcClient {
|
|
25
|
+
private url;
|
|
26
|
+
private nextId;
|
|
27
|
+
constructor(url?: string);
|
|
28
|
+
/**
|
|
29
|
+
* Send a JSON-RPC 2.0 request and return the result.
|
|
30
|
+
*/
|
|
31
|
+
call<T = unknown>(method: string, params?: unknown[]): Promise<T>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,0BAA0B,CAAC;AAEvD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C;AAED,qBAAa,QAAS,SAAQ,KAAK;IAExB,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM;CAKlB;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,MAAM,CAAK;gBAEP,GAAG,GAAE,MAAwB;IAIzC;;OAEG;IACG,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CA6B5E"}
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// ClawNetwork SDK — JSON-RPC 2.0 client (zero-dependency, uses native fetch)
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
export const DEFAULT_RPC_URL = 'http://localhost:9710';
|
|
5
|
+
export class RpcError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
constructor(code, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.name = 'RpcError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Low-level JSON-RPC 2.0 client. Uses native `fetch` — no dependencies.
|
|
15
|
+
*/
|
|
16
|
+
export class RpcClient {
|
|
17
|
+
url;
|
|
18
|
+
nextId = 1;
|
|
19
|
+
constructor(url = DEFAULT_RPC_URL) {
|
|
20
|
+
this.url = url;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Send a JSON-RPC 2.0 request and return the result.
|
|
24
|
+
*/
|
|
25
|
+
async call(method, params = []) {
|
|
26
|
+
const body = {
|
|
27
|
+
jsonrpc: '2.0',
|
|
28
|
+
id: this.nextId++,
|
|
29
|
+
method,
|
|
30
|
+
params,
|
|
31
|
+
};
|
|
32
|
+
const response = await fetch(this.url, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'Content-Type': 'application/json' },
|
|
35
|
+
body: JSON.stringify(body),
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new RpcError(-32000, `HTTP ${response.status}: ${response.statusText}`);
|
|
39
|
+
}
|
|
40
|
+
const json = (await response.json());
|
|
41
|
+
if (json.error) {
|
|
42
|
+
throw new RpcError(json.error.code, json.error.message);
|
|
43
|
+
}
|
|
44
|
+
return json.result;
|
|
45
|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,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAuB,CAAC;QAE3D,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1D,CAAC;QAED,OAAO,IAAI,CAAC,MAAW,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Transaction } from './types.js';
|
|
2
|
+
export declare function encodeAgentRegisterPayload(name: string, metadata: Record<string, string>): Uint8Array;
|
|
3
|
+
export declare function encodeTokenTransferPayload(to: Uint8Array, amount: bigint): Uint8Array;
|
|
4
|
+
export declare function encodeTokenCreatePayload(name: string, symbol: string, decimals: number, totalSupply: bigint): Uint8Array;
|
|
5
|
+
export declare function encodeTokenMintTransferPayload(tokenId: Uint8Array, to: Uint8Array, amount: bigint): Uint8Array;
|
|
6
|
+
export declare function encodeReputationAttestPayload(to: Uint8Array, category: string, score: number, platform: string, memo: string): Uint8Array;
|
|
7
|
+
export declare function encodeServiceRegisterPayload(serviceType: string, description: string, priceToken: Uint8Array, priceAmount: bigint, endpoint: string, active: boolean): Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Compute the signable bytes for a transaction:
|
|
10
|
+
* tx_type(1) || from(32) || nonce(8 LE) || payload(raw, no length prefix)
|
|
11
|
+
*
|
|
12
|
+
* This matches `Transaction::signable_bytes()` in Rust.
|
|
13
|
+
*/
|
|
14
|
+
export declare function signableBytes(tx: Transaction): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Borsh-serialize a full Transaction struct.
|
|
17
|
+
*
|
|
18
|
+
* Layout (matches Rust `BorshSerialize` derive on Transaction):
|
|
19
|
+
* tx_type: u8 (enum discriminant)
|
|
20
|
+
* from: [u8; 32]
|
|
21
|
+
* nonce: u64 LE
|
|
22
|
+
* payload: Vec<u8> (4-byte LE length + data)
|
|
23
|
+
* signature: [u8; 64]
|
|
24
|
+
*/
|
|
25
|
+
export declare function serializeTransaction(tx: Transaction): Uint8Array;
|
|
26
|
+
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAqE9C,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,UAAU,CAKZ;AAED,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,UAAU,EACd,MAAM,EAAE,MAAM,GACb,UAAU,CAKZ;AAED,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,UAAU,CAOZ;AAED,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,UAAU,EACnB,EAAE,EAAE,UAAU,EACd,MAAM,EAAE,MAAM,GACb,UAAU,CAMZ;AAED,wBAAgB,6BAA6B,CAC3C,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,UAAU,CAQZ;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,GACd,UAAU,CASZ;AAID;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,WAAW,GAAG,UAAU,CAOzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,WAAW,GAAG,UAAU,CAQhE"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// ClawNetwork SDK — Borsh serialization (byte-compatible with Rust `borsh`)
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
//
|
|
5
|
+
// We use manual borsh encoding to guarantee exact byte-level compatibility
|
|
6
|
+
// with the Rust crate. The `borsh` npm package's schema API can be fragile
|
|
7
|
+
// across versions, so we encode directly.
|
|
8
|
+
//
|
|
9
|
+
// Borsh spec reference:
|
|
10
|
+
// string = 4-byte LE length + UTF-8 bytes
|
|
11
|
+
// u8 = 1 byte
|
|
12
|
+
// i16 = 2 bytes LE (signed)
|
|
13
|
+
// u64 = 8 bytes LE
|
|
14
|
+
// u128 = 16 bytes LE
|
|
15
|
+
// [u8; N] = N raw bytes (no prefix)
|
|
16
|
+
// Vec<u8> = 4-byte LE length + raw bytes
|
|
17
|
+
// bool = 1 byte (0 or 1)
|
|
18
|
+
// BTreeMap<String,String> = 4-byte LE count + repeated (key, value) pairs
|
|
19
|
+
// (Rust BTreeMap serializes in sorted-key order)
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// ---- Primitive writers ----
|
|
22
|
+
function writeU8(buf, v) {
|
|
23
|
+
buf.push(v & 0xff);
|
|
24
|
+
}
|
|
25
|
+
function writeU16LE(buf, v) {
|
|
26
|
+
buf.push(v & 0xff, (v >> 8) & 0xff);
|
|
27
|
+
}
|
|
28
|
+
function writeI16LE(buf, v) {
|
|
29
|
+
// Reinterpret as unsigned 16-bit for LE encoding
|
|
30
|
+
const u = v < 0 ? v + 0x10000 : v;
|
|
31
|
+
writeU16LE(buf, u);
|
|
32
|
+
}
|
|
33
|
+
function writeU32LE(buf, v) {
|
|
34
|
+
buf.push(v & 0xff, (v >> 8) & 0xff, (v >> 16) & 0xff, (v >> 24) & 0xff);
|
|
35
|
+
}
|
|
36
|
+
function writeU64LE(buf, v) {
|
|
37
|
+
const lo = Number(v & 0xffffffffn);
|
|
38
|
+
const hi = Number((v >> 32n) & 0xffffffffn);
|
|
39
|
+
writeU32LE(buf, lo);
|
|
40
|
+
writeU32LE(buf, hi);
|
|
41
|
+
}
|
|
42
|
+
function writeU128LE(buf, v) {
|
|
43
|
+
writeU64LE(buf, v & 0xffffffffffffffffn);
|
|
44
|
+
writeU64LE(buf, (v >> 64n) & 0xffffffffffffffffn);
|
|
45
|
+
}
|
|
46
|
+
function writeFixedBytes(buf, bytes) {
|
|
47
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
48
|
+
buf.push(bytes[i]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function writeString(buf, s) {
|
|
52
|
+
const encoded = new TextEncoder().encode(s);
|
|
53
|
+
writeU32LE(buf, encoded.length);
|
|
54
|
+
writeFixedBytes(buf, encoded);
|
|
55
|
+
}
|
|
56
|
+
function writeVecU8(buf, data) {
|
|
57
|
+
writeU32LE(buf, data.length);
|
|
58
|
+
writeFixedBytes(buf, data);
|
|
59
|
+
}
|
|
60
|
+
function writeBool(buf, v) {
|
|
61
|
+
buf.push(v ? 1 : 0);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Write a BTreeMap<String, String> in Rust BTreeMap borsh order (sorted keys).
|
|
65
|
+
*/
|
|
66
|
+
function writeStringMap(buf, map) {
|
|
67
|
+
const keys = Object.keys(map).sort(); // BTreeMap = sorted
|
|
68
|
+
writeU32LE(buf, keys.length);
|
|
69
|
+
for (const key of keys) {
|
|
70
|
+
writeString(buf, key);
|
|
71
|
+
writeString(buf, map[key]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// ---- Payload encoders ----
|
|
75
|
+
export function encodeAgentRegisterPayload(name, metadata) {
|
|
76
|
+
const buf = [];
|
|
77
|
+
writeString(buf, name);
|
|
78
|
+
writeStringMap(buf, metadata);
|
|
79
|
+
return new Uint8Array(buf);
|
|
80
|
+
}
|
|
81
|
+
export function encodeTokenTransferPayload(to, amount) {
|
|
82
|
+
const buf = [];
|
|
83
|
+
writeFixedBytes(buf, to); // [u8; 32]
|
|
84
|
+
writeU128LE(buf, amount);
|
|
85
|
+
return new Uint8Array(buf);
|
|
86
|
+
}
|
|
87
|
+
export function encodeTokenCreatePayload(name, symbol, decimals, totalSupply) {
|
|
88
|
+
const buf = [];
|
|
89
|
+
writeString(buf, name);
|
|
90
|
+
writeString(buf, symbol);
|
|
91
|
+
writeU8(buf, decimals);
|
|
92
|
+
writeU128LE(buf, totalSupply);
|
|
93
|
+
return new Uint8Array(buf);
|
|
94
|
+
}
|
|
95
|
+
export function encodeTokenMintTransferPayload(tokenId, to, amount) {
|
|
96
|
+
const buf = [];
|
|
97
|
+
writeFixedBytes(buf, tokenId); // [u8; 32]
|
|
98
|
+
writeFixedBytes(buf, to); // [u8; 32]
|
|
99
|
+
writeU128LE(buf, amount);
|
|
100
|
+
return new Uint8Array(buf);
|
|
101
|
+
}
|
|
102
|
+
export function encodeReputationAttestPayload(to, category, score, platform, memo) {
|
|
103
|
+
const buf = [];
|
|
104
|
+
writeFixedBytes(buf, to); // [u8; 32]
|
|
105
|
+
writeString(buf, category);
|
|
106
|
+
writeI16LE(buf, score);
|
|
107
|
+
writeString(buf, platform);
|
|
108
|
+
writeString(buf, memo);
|
|
109
|
+
return new Uint8Array(buf);
|
|
110
|
+
}
|
|
111
|
+
export function encodeServiceRegisterPayload(serviceType, description, priceToken, priceAmount, endpoint, active) {
|
|
112
|
+
const buf = [];
|
|
113
|
+
writeString(buf, serviceType);
|
|
114
|
+
writeString(buf, description);
|
|
115
|
+
writeFixedBytes(buf, priceToken); // [u8; 32]
|
|
116
|
+
writeU128LE(buf, priceAmount);
|
|
117
|
+
writeString(buf, endpoint);
|
|
118
|
+
writeBool(buf, active);
|
|
119
|
+
return new Uint8Array(buf);
|
|
120
|
+
}
|
|
121
|
+
// ---- Transaction serialization ----
|
|
122
|
+
/**
|
|
123
|
+
* Compute the signable bytes for a transaction:
|
|
124
|
+
* tx_type(1) || from(32) || nonce(8 LE) || payload(raw, no length prefix)
|
|
125
|
+
*
|
|
126
|
+
* This matches `Transaction::signable_bytes()` in Rust.
|
|
127
|
+
*/
|
|
128
|
+
export function signableBytes(tx) {
|
|
129
|
+
const buf = [];
|
|
130
|
+
writeU8(buf, tx.txType);
|
|
131
|
+
writeFixedBytes(buf, tx.from);
|
|
132
|
+
writeU64LE(buf, tx.nonce);
|
|
133
|
+
writeFixedBytes(buf, tx.payload); // raw bytes, no Vec prefix
|
|
134
|
+
return new Uint8Array(buf);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Borsh-serialize a full Transaction struct.
|
|
138
|
+
*
|
|
139
|
+
* Layout (matches Rust `BorshSerialize` derive on Transaction):
|
|
140
|
+
* tx_type: u8 (enum discriminant)
|
|
141
|
+
* from: [u8; 32]
|
|
142
|
+
* nonce: u64 LE
|
|
143
|
+
* payload: Vec<u8> (4-byte LE length + data)
|
|
144
|
+
* signature: [u8; 64]
|
|
145
|
+
*/
|
|
146
|
+
export function serializeTransaction(tx) {
|
|
147
|
+
const buf = [];
|
|
148
|
+
writeU8(buf, tx.txType);
|
|
149
|
+
writeFixedBytes(buf, tx.from);
|
|
150
|
+
writeU64LE(buf, tx.nonce);
|
|
151
|
+
writeVecU8(buf, tx.payload); // Vec<u8> with length prefix
|
|
152
|
+
writeFixedBytes(buf, tx.signature); // [u8; 64] fixed
|
|
153
|
+
return new Uint8Array(buf);
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.js","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,0CAA0C;AAC1C,EAAE;AACF,wBAAwB;AACxB,6CAA6C;AAC7C,qBAAqB;AACrB,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M,CAAC,CAAC;IACxB,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAC9B,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;IAC1B,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B;IAC7D,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAe;IAClD,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;IACxB,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAC9B,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;IAC1B,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B;IAC1D,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB;IACrD,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/** Transaction type discriminator (matches Rust TxType enum). */
|
|
2
|
+
export declare enum TxType {
|
|
3
|
+
AgentRegister = 0,
|
|
4
|
+
TokenTransfer = 1,
|
|
5
|
+
TokenCreate = 2,
|
|
6
|
+
TokenMintTransfer = 3,
|
|
7
|
+
ReputationAttest = 4,
|
|
8
|
+
ServiceRegister = 5
|
|
9
|
+
}
|
|
10
|
+
/** A signed transaction on ClawNetwork. */
|
|
11
|
+
export interface Transaction {
|
|
12
|
+
txType: TxType;
|
|
13
|
+
from: Uint8Array;
|
|
14
|
+
nonce: bigint;
|
|
15
|
+
payload: Uint8Array;
|
|
16
|
+
signature: Uint8Array;
|
|
17
|
+
}
|
|
18
|
+
export interface AgentRegisterParams {
|
|
19
|
+
name: string;
|
|
20
|
+
metadata: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
export interface TokenTransferParams {
|
|
23
|
+
to: string;
|
|
24
|
+
amount: bigint;
|
|
25
|
+
}
|
|
26
|
+
export interface TokenCreateParams {
|
|
27
|
+
name: string;
|
|
28
|
+
symbol: string;
|
|
29
|
+
decimals: number;
|
|
30
|
+
totalSupply: bigint;
|
|
31
|
+
}
|
|
32
|
+
export interface TokenMintTransferParams {
|
|
33
|
+
tokenId: string;
|
|
34
|
+
to: string;
|
|
35
|
+
amount: bigint;
|
|
36
|
+
}
|
|
37
|
+
export interface ReputationAttestParams {
|
|
38
|
+
to: string;
|
|
39
|
+
category: string;
|
|
40
|
+
score: number;
|
|
41
|
+
platform: string;
|
|
42
|
+
memo: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ServiceRegisterParams {
|
|
45
|
+
serviceType: string;
|
|
46
|
+
description: string;
|
|
47
|
+
priceToken: string;
|
|
48
|
+
priceAmount: bigint;
|
|
49
|
+
endpoint: string;
|
|
50
|
+
active: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface AgentIdentity {
|
|
53
|
+
address: string;
|
|
54
|
+
name: string;
|
|
55
|
+
metadata: Record<string, string>;
|
|
56
|
+
registered_at: number;
|
|
57
|
+
}
|
|
58
|
+
export interface TokenDef {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
symbol: string;
|
|
62
|
+
decimals: number;
|
|
63
|
+
total_supply: string;
|
|
64
|
+
issuer: string;
|
|
65
|
+
}
|
|
66
|
+
export interface ReputationAttestation {
|
|
67
|
+
from: string;
|
|
68
|
+
to: string;
|
|
69
|
+
category: string;
|
|
70
|
+
score: number;
|
|
71
|
+
platform: string;
|
|
72
|
+
memo: string;
|
|
73
|
+
block_height: number;
|
|
74
|
+
}
|
|
75
|
+
export interface ServiceEntry {
|
|
76
|
+
provider: string;
|
|
77
|
+
service_type: string;
|
|
78
|
+
description: string;
|
|
79
|
+
price_token: string;
|
|
80
|
+
price_amount: string;
|
|
81
|
+
endpoint: string;
|
|
82
|
+
active: boolean;
|
|
83
|
+
}
|
|
84
|
+
export interface BlockInfo {
|
|
85
|
+
height: number;
|
|
86
|
+
prev_hash: string;
|
|
87
|
+
timestamp: number;
|
|
88
|
+
validator: string;
|
|
89
|
+
transactions: unknown[];
|
|
90
|
+
state_root: string;
|
|
91
|
+
hash: string;
|
|
92
|
+
}
|
|
93
|
+
export interface TransactionReceipt {
|
|
94
|
+
blockHeight: number;
|
|
95
|
+
transactionIndex: number;
|
|
96
|
+
}
|
|
97
|
+
export interface ClawClientConfig {
|
|
98
|
+
rpcUrl?: string;
|
|
99
|
+
wallet?: WalletLike;
|
|
100
|
+
}
|
|
101
|
+
export interface WalletLike {
|
|
102
|
+
publicKey: Uint8Array;
|
|
103
|
+
address: string;
|
|
104
|
+
sign(message: Uint8Array): Promise<Uint8Array>;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,iEAAiE;AACjE,oBAAY,MAAM;IAChB,aAAa,IAAI;IACjB,aAAa,IAAI;IACjB,WAAW,IAAI;IACf,iBAAiB,IAAI;IACrB,gBAAgB,IAAI;IACpB,eAAe,IAAI;CACpB;AAED,2CAA2C;AAC3C,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,UAAU,CAAC;IACpB,SAAS,EAAE,UAAU,CAAC;CACvB;AAID,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM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AE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAID,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,UAAU,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAChD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// ClawNetwork SDK — Type definitions
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
/** Transaction type discriminator (matches Rust TxType enum). */
|
|
5
|
+
export var TxType;
|
|
6
|
+
(function (TxType) {
|
|
7
|
+
TxType[TxType["AgentRegister"] = 0] = "AgentRegister";
|
|
8
|
+
TxType[TxType["TokenTransfer"] = 1] = "TokenTransfer";
|
|
9
|
+
TxType[TxType["TokenCreate"] = 2] = "TokenCreate";
|
|
10
|
+
TxType[TxType["TokenMintTransfer"] = 3] = "TokenMintTransfer";
|
|
11
|
+
TxType[TxType["ReputationAttest"] = 4] = "ReputationAttest";
|
|
12
|
+
TxType[TxType["ServiceRegister"] = 5] = "ServiceRegister";
|
|
13
|
+
})(TxType || (TxType = {}));
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,qCAAqC;AACrC,8EAA8E;AAE9E,iEAAiE;AACjE,MAAM,CAAN,IAAY,MAOX;AAPD,WAAY,MAAM;IAChB,qDAAiB,CAAA;IACjB,qDAAiB,CAAA;IACjB,iDAAe,CAAA;IACf,6DAAqB,CAAA;IACrB,2DAAoB,CAAA;IACpB,yDAAmB,CAAA;AACrB,CAAC,EAPW,MAAM,KAAN,MAAM,QAOjB"}
|
package/dist/wallet.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { WalletLike } from './types.js';
|
|
2
|
+
/** Hex-encode a Uint8Array. */
|
|
3
|
+
export declare function toHex(bytes: Uint8Array): string;
|
|
4
|
+
/** Decode a hex string to Uint8Array. */
|
|
5
|
+
export declare function fromHex(hex: string): Uint8Array;
|
|
6
|
+
/**
|
|
7
|
+
* Ed25519 wallet for ClawNetwork.
|
|
8
|
+
*
|
|
9
|
+
* Compatible with Rust `ed25519-dalek` crate signatures.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Wallet implements WalletLike {
|
|
12
|
+
/** 32-byte Ed25519 private key (seed). */
|
|
13
|
+
readonly privateKey: Uint8Array;
|
|
14
|
+
/** 32-byte Ed25519 public key. */
|
|
15
|
+
readonly publicKey: Uint8Array;
|
|
16
|
+
/** Hex-encoded public key (= on-chain address). */
|
|
17
|
+
readonly address: string;
|
|
18
|
+
private constructor();
|
|
19
|
+
/** Generate a new random wallet. */
|
|
20
|
+
static generate(): Wallet;
|
|
21
|
+
/** Restore a wallet from a 32-byte hex private key. */
|
|
22
|
+
static fromPrivateKey(hexOrBytes: string | Uint8Array): Wallet;
|
|
23
|
+
/** Sign a message, returning a 64-byte Ed25519 signature. */
|
|
24
|
+
sign(message: Uint8Array): Promise<Uint8Array>;
|
|
25
|
+
/** Synchronous sign (convenience). */
|
|
26
|
+
signSync(message: Uint8Array): Uint8Array;
|
|
27
|
+
/** Verify a signature against a message and public key. */
|
|
28
|
+
static verify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,+BAA+B;AAC/B,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAI/C;AAED,yCAAyC;AACzC,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAO/C;AAED;;;;GAIG;AACH,qBAAa,MAAO,YAAW,UAAU;IACvC,0CAA0C;IAC1C,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,kCAAkC;IAClC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,OAAO;IAMP,oCAAoC;IACpC,MAAM,CAAC,QAAQ,IAAI,MAAM;IAKzB,uDAAuD;IACvD,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM;IAS9D,6DAA6D;IACvD,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAIpD,sCAAsC;IACtC,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU;IAIzC,2DAA2D;IAC3D,MAAM,CAAC,MAAM,CACX,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,UAAU,GACpB,OAAO;CAGX"}
|
package/dist/wallet.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// ClawNetwork SDK — Wallet (Ed25519 key management and signing)
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
5
|
+
/** Hex-encode a Uint8Array. */
|
|
6
|
+
export function toHex(bytes) {
|
|
7
|
+
return Array.from(bytes)
|
|
8
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
9
|
+
.join('');
|
|
10
|
+
}
|
|
11
|
+
/** Decode a hex string to Uint8Array. */
|
|
12
|
+
export function fromHex(hex) {
|
|
13
|
+
if (hex.length % 2 !== 0)
|
|
14
|
+
throw new Error('Invalid hex string (odd length)');
|
|
15
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
16
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
17
|
+
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
18
|
+
}
|
|
19
|
+
return bytes;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Ed25519 wallet for ClawNetwork.
|
|
23
|
+
*
|
|
24
|
+
* Compatible with Rust `ed25519-dalek` crate signatures.
|
|
25
|
+
*/
|
|
26
|
+
export class Wallet {
|
|
27
|
+
/** 32-byte Ed25519 private key (seed). */
|
|
28
|
+
privateKey;
|
|
29
|
+
/** 32-byte Ed25519 public key. */
|
|
30
|
+
publicKey;
|
|
31
|
+
/** Hex-encoded public key (= on-chain address). */
|
|
32
|
+
address;
|
|
33
|
+
constructor(privateKey) {
|
|
34
|
+
this.privateKey = privateKey;
|
|
35
|
+
this.publicKey = ed25519.getPublicKey(privateKey);
|
|
36
|
+
this.address = toHex(this.publicKey);
|
|
37
|
+
}
|
|
38
|
+
/** Generate a new random wallet. */
|
|
39
|
+
static generate() {
|
|
40
|
+
const privKey = ed25519.utils.randomPrivateKey();
|
|
41
|
+
return new Wallet(privKey);
|
|
42
|
+
}
|
|
43
|
+
/** Restore a wallet from a 32-byte hex private key. */
|
|
44
|
+
static fromPrivateKey(hexOrBytes) {
|
|
45
|
+
const bytes = typeof hexOrBytes === 'string' ? fromHex(hexOrBytes) : hexOrBytes;
|
|
46
|
+
if (bytes.length !== 32) {
|
|
47
|
+
throw new Error(`Private key must be 32 bytes, got ${bytes.length}`);
|
|
48
|
+
}
|
|
49
|
+
return new Wallet(bytes);
|
|
50
|
+
}
|
|
51
|
+
/** Sign a message, returning a 64-byte Ed25519 signature. */
|
|
52
|
+
async sign(message) {
|
|
53
|
+
return ed25519.sign(message, this.privateKey);
|
|
54
|
+
}
|
|
55
|
+
/** Synchronous sign (convenience). */
|
|
56
|
+
signSync(message) {
|
|
57
|
+
return ed25519.sign(message, this.privateKey);
|
|
58
|
+
}
|
|
59
|
+
/** Verify a signature against a message and public key. */
|
|
60
|
+
static verify(signature, message, publicKey) {
|
|
61
|
+
return ed25519.verify(signature, message, publicKey);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gEAAgE;AAChE,8EAA8E;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGhD,+BAA+B;AAC/B,MAAM,UAAU,KAAK,CAAC,KAAiB;IACrC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;SACrB,GAAG,CA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C;IAED,uDAAuD;IACvD,MAAM,CAAC,cAAc,CAAC,UAA+B;QACnD,MAAM,KAAK,GACT,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;QACpE,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,qCAAqC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED,6DAA6D;IAC7D,KAAK,CAAC,IAAI,CAAC,OAAmB;QAC5B,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAChD,CAAC;IAED,sCAAsC;IACtC,QAAQ,CAAC,OAAmB;QAC1B,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAChD,CAAC;IAED,2DAA2D;IAC3D,MAAM,CAAC,MAAM,CACX,SAAqB,EACrB,OAAmB,EACnB,SAAqB;QAErB,OAAO,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACvD,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clawlabz/clawnetwork-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for ClawNetwork — AI agent blockchain",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:watch": "vitest",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@noble/curves": "^1.8.1",
|
|
25
|
+
"@noble/hashes": "^2.0.1",
|
|
26
|
+
"borsh": "^2.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^22.0.0",
|
|
30
|
+
"typescript": "^5.7.0",
|
|
31
|
+
"vitest": "^3.0.0"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"clawnetwork",
|
|
35
|
+
"blockchain",
|
|
36
|
+
"ai-agent",
|
|
37
|
+
"sdk",
|
|
38
|
+
"ed25519"
|
|
39
|
+
],
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/ClawLabz/claw-network"
|
|
44
|
+
}
|
|
45
|
+
}
|