@sahyadrinet/web3.js 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.
@@ -0,0 +1,110 @@
1
+ type Hash = Uint8Array;
2
+ type PublicKey = Uint8Array;
3
+ type SecretKey = Uint8Array;
4
+ type Signature = Uint8Array;
5
+ type Address = string;
6
+ type TransactionId = string;
7
+ interface KeyPair {
8
+ publicKey: PublicKey;
9
+ secretKey: SecretKey;
10
+ }
11
+ interface RpcConfig {
12
+ url?: string;
13
+ timeout?: number;
14
+ }
15
+ interface BalanceResult {
16
+ address: Address;
17
+ balance: string;
18
+ nonce: number;
19
+ }
20
+ interface SubmitTxResult {
21
+ transactionId: TransactionId;
22
+ accepted: boolean;
23
+ }
24
+
25
+ declare class DomainHasher {
26
+ private init;
27
+ constructor(domain: string);
28
+ hash(data: Uint8Array): Uint8Array;
29
+ clone(): DomainHasher;
30
+ }
31
+ declare const TxHash: DomainHasher;
32
+ declare const TxID: DomainHasher;
33
+ declare const TxSigningHash: DomainHasher;
34
+ declare const BlockHash: DomainHasher;
35
+ declare const MerkleHash: DomainHasher;
36
+ declare function sha3(data: Uint8Array): Uint8Array;
37
+ declare function shake256Bytes(data: Uint8Array, len: number): Uint8Array;
38
+ declare function shake128Bytes(data: Uint8Array, len: number): Uint8Array;
39
+ declare function shake256Digest(data: Uint8Array, outputLen: number): Uint8Array;
40
+
41
+ declare function pubkeyToAddress(pk: Uint8Array, testnet?: boolean): string;
42
+ declare function isValidAddress(addr: string, testnet?: boolean): boolean;
43
+ declare function addressToScriptPubkey(addr: string): Uint8Array;
44
+
45
+ declare function keypair(): {
46
+ publicKey: Uint8Array;
47
+ secretKey: Uint8Array;
48
+ };
49
+ declare function sign(secretKey: Uint8Array, message: Uint8Array): Uint8Array;
50
+ declare function verify(publicKey: Uint8Array, signature: Uint8Array, message: Uint8Array): boolean;
51
+
52
+ declare class Wallet {
53
+ private rpc;
54
+ publicKey: Uint8Array;
55
+ secretKey: Uint8Array;
56
+ address: string;
57
+ balance: number;
58
+ nonce: number;
59
+ constructor(rpcUrl?: string);
60
+ connect(): Promise<void>;
61
+ create(): void;
62
+ getBalance(): Promise<number>;
63
+ send(to: string, amountKana: number): Promise<string>;
64
+ }
65
+
66
+ declare class RpcClient {
67
+ private url;
68
+ private ws;
69
+ private connected;
70
+ constructor(url?: string);
71
+ connect(): Promise<void>;
72
+ isConnected(): boolean;
73
+ call(method: string, params: any): Promise<any>;
74
+ getBalance(address: string): Promise<number>;
75
+ submitTransaction(tx: any): Promise<string>;
76
+ }
77
+
78
+ interface DidDocument {
79
+ id: string;
80
+ controller: string;
81
+ publicKeyHex: string;
82
+ created: number;
83
+ services: Array<{
84
+ type: string;
85
+ endpoint: string;
86
+ }>;
87
+ }
88
+ declare function createDid(address: string, publicKeyHex: string): DidDocument;
89
+ declare function addService(doc: DidDocument, type: string, endpoint: string): DidDocument;
90
+
91
+ declare class Storage {
92
+ private store;
93
+ set(key: string, value: any): void;
94
+ get<T>(key: string): T | null;
95
+ remove(key: string): void;
96
+ clear(): void;
97
+ }
98
+
99
+ interface AccountTransaction {
100
+ sender: string;
101
+ receiver: string;
102
+ amount: number;
103
+ fee: number;
104
+ nonce: number;
105
+ payload: string;
106
+ signature: string;
107
+ }
108
+ declare function createTransaction(sender: string, receiver: string, amountKana: number, nonce: number, publicKeyHex: string): AccountTransaction;
109
+
110
+ export { type Address, type BalanceResult, BlockHash, DomainHasher, type Hash, type KeyPair, MerkleHash, type PublicKey, RpcClient, type RpcConfig, type SecretKey, type Signature, Storage, type SubmitTxResult, type TransactionId, TxHash, TxID, TxSigningHash, Wallet, addService, addressToScriptPubkey, createDid, createTransaction, isValidAddress, keypair, pubkeyToAddress, sha3, shake128Bytes, shake256Bytes, shake256Digest, sign, verify };
package/dist/index.js ADDED
@@ -0,0 +1,315 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/index.ts
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ BlockHash: () => BlockHash,
33
+ DomainHasher: () => DomainHasher,
34
+ MerkleHash: () => MerkleHash,
35
+ RpcClient: () => RpcClient,
36
+ Storage: () => Storage,
37
+ TxHash: () => TxHash,
38
+ TxID: () => TxID,
39
+ TxSigningHash: () => TxSigningHash,
40
+ Wallet: () => Wallet,
41
+ addService: () => addService,
42
+ addressToScriptPubkey: () => addressToScriptPubkey,
43
+ createDid: () => createDid,
44
+ createTransaction: () => createTransaction,
45
+ isValidAddress: () => isValidAddress,
46
+ keypair: () => keypair,
47
+ pubkeyToAddress: () => pubkeyToAddress,
48
+ sha3: () => sha3,
49
+ shake128Bytes: () => shake128Bytes,
50
+ shake256Bytes: () => shake256Bytes,
51
+ shake256Digest: () => shake256Digest,
52
+ sign: () => sign,
53
+ verify: () => verify
54
+ });
55
+ module.exports = __toCommonJS(index_exports);
56
+
57
+ // src/sha3.ts
58
+ var import_sha3 = require("@noble/hashes/sha3");
59
+ var DomainHasher = class _DomainHasher {
60
+ constructor(domain) {
61
+ this.init = new Uint8Array((0, import_sha3.sha3_256)(new TextEncoder().encode(domain)));
62
+ }
63
+ hash(data) {
64
+ const h = import_sha3.sha3_256.create();
65
+ h.update(this.init);
66
+ h.update(data);
67
+ return new Uint8Array(h.digest());
68
+ }
69
+ clone() {
70
+ const d = new _DomainHasher("");
71
+ d.init = new Uint8Array(this.init);
72
+ return d;
73
+ }
74
+ };
75
+ var TxHash = new DomainHasher("TransactionHash");
76
+ var TxID = new DomainHasher("TransactionID");
77
+ var TxSigningHash = new DomainHasher("TransactionSigningHash");
78
+ var BlockHash = new DomainHasher("BlockHash");
79
+ var MerkleHash = new DomainHasher("MerkleBranchHash");
80
+ function sha3(data) {
81
+ return new Uint8Array((0, import_sha3.sha3_256)(data));
82
+ }
83
+ function shake256Bytes(data, len) {
84
+ return new Uint8Array((0, import_sha3.shake256)(data, { dkLen: len }));
85
+ }
86
+ function shake128Bytes(data, len) {
87
+ return new Uint8Array((0, import_sha3.shake128)(data, { dkLen: len }));
88
+ }
89
+ function shake256Digest(data, outputLen) {
90
+ return new Uint8Array((0, import_sha3.shake256)(data, { dkLen: outputLen }));
91
+ }
92
+
93
+ // src/address.ts
94
+ var _bech32 = __toESM(require("bech32"));
95
+ var bech32 = _bech32;
96
+ var PREFIX_MAIN = "csm";
97
+ var PREFIX_TEST = "csmtest";
98
+ function pubkeyToHash(pk) {
99
+ return sha3(pk).slice(0, 20);
100
+ }
101
+ function pubkeyToAddress(pk, testnet = false) {
102
+ const hash = pubkeyToHash(pk);
103
+ const words = bech32.toWords(hash);
104
+ return bech32.encode(testnet ? PREFIX_TEST : PREFIX_MAIN, words);
105
+ }
106
+ function isValidAddress(addr, testnet = false) {
107
+ try {
108
+ const { prefix, words } = bech32.decode(addr);
109
+ if (prefix !== (testnet ? PREFIX_TEST : PREFIX_MAIN)) return false;
110
+ const data = bech32.fromWords(words);
111
+ return data.length === 20;
112
+ } catch {
113
+ return false;
114
+ }
115
+ }
116
+ function addressToScriptPubkey(addr) {
117
+ const { words } = bech32.decode(addr);
118
+ const data = bech32.fromWords(words);
119
+ const script = new Uint8Array(22);
120
+ script[0] = 20;
121
+ script.set(data, 1);
122
+ script[21] = 172;
123
+ return script;
124
+ }
125
+
126
+ // src/dilithium/index.ts
127
+ var import_ml_dsa = require("@noble/post-quantum/ml-dsa.js");
128
+ function keypair() {
129
+ const keys = import_ml_dsa.ml_dsa65.keygen();
130
+ return {
131
+ publicKey: keys.publicKey,
132
+ secretKey: keys.secretKey
133
+ };
134
+ }
135
+ function sign(secretKey, message) {
136
+ return import_ml_dsa.ml_dsa65.sign(message, secretKey);
137
+ }
138
+ function verify(publicKey, signature, message) {
139
+ return import_ml_dsa.ml_dsa65.verify(signature, message, publicKey);
140
+ }
141
+
142
+ // src/rpc/client.ts
143
+ var RpcClient = class {
144
+ constructor(url = "ws://127.0.0.1:27110") {
145
+ this.ws = null;
146
+ this.connected = false;
147
+ this.url = url;
148
+ }
149
+ async connect() {
150
+ return new Promise((resolve, reject) => {
151
+ this.ws = new WebSocket(this.url);
152
+ this.ws.onopen = () => {
153
+ this.connected = true;
154
+ resolve();
155
+ };
156
+ this.ws.onerror = (e) => reject(e);
157
+ });
158
+ }
159
+ isConnected() {
160
+ return this.connected;
161
+ }
162
+ async call(method, params) {
163
+ return new Promise((resolve, reject) => {
164
+ if (!this.ws || !this.connected) {
165
+ reject("Not connected");
166
+ return;
167
+ }
168
+ const id = Date.now();
169
+ const handler = (e) => {
170
+ const data = JSON.parse(e.data);
171
+ if (data.id === id) {
172
+ this.ws.removeEventListener("message", handler);
173
+ resolve(data.result || data);
174
+ }
175
+ };
176
+ this.ws.addEventListener("message", handler);
177
+ this.ws.send(JSON.stringify({ jsonrpc: "2.0", id, method, params }));
178
+ });
179
+ }
180
+ async getBalance(address) {
181
+ const result = await this.call("getBalanceByAddress", { address });
182
+ return result?.balance || 0;
183
+ }
184
+ async submitTransaction(tx) {
185
+ const result = await this.call("submitAccountTransaction", tx);
186
+ return result?.transactionId || "";
187
+ }
188
+ };
189
+
190
+ // src/wallet/index.ts
191
+ var Wallet = class {
192
+ constructor(rpcUrl = "ws://127.0.0.1:27110") {
193
+ this.publicKey = new Uint8Array(1952);
194
+ this.secretKey = new Uint8Array(4032);
195
+ this.address = "";
196
+ this.balance = 0;
197
+ this.nonce = 0;
198
+ this.rpc = new RpcClient(rpcUrl);
199
+ }
200
+ async connect() {
201
+ await this.rpc.connect();
202
+ }
203
+ create() {
204
+ const { publicKey, secretKey } = keypair();
205
+ this.publicKey = publicKey;
206
+ this.secretKey = secretKey;
207
+ this.address = pubkeyToAddress(publicKey);
208
+ }
209
+ async getBalance() {
210
+ this.balance = await this.rpc.getBalance(this.address);
211
+ return this.balance;
212
+ }
213
+ async send(to, amountKana) {
214
+ const payload = Buffer.from(this.publicKey).toString("hex");
215
+ const txData = `${this.address}:${to}:${amountKana}:${this.nonce}`;
216
+ const signature = sign(this.secretKey, new TextEncoder().encode(txData));
217
+ const sigHex = Buffer.from(signature).toString("hex");
218
+ const tx = {
219
+ sender: this.address,
220
+ receiver: to,
221
+ amount: amountKana,
222
+ fee: 1e3,
223
+ nonce: this.nonce,
224
+ payload,
225
+ signature: sigHex
226
+ };
227
+ const txId = await this.rpc.submitTransaction(tx);
228
+ this.nonce++;
229
+ return txId;
230
+ }
231
+ };
232
+
233
+ // src/did/index.ts
234
+ function createDid(address, publicKeyHex) {
235
+ const did = `did:sahyadri:${address}`;
236
+ return {
237
+ id: did,
238
+ controller: address,
239
+ publicKeyHex,
240
+ created: Math.floor(Date.now() / 1e3),
241
+ services: []
242
+ };
243
+ }
244
+ function addService(doc, type, endpoint) {
245
+ doc.services.push({ type, endpoint });
246
+ return doc;
247
+ }
248
+
249
+ // src/storage/index.ts
250
+ var Storage = class {
251
+ constructor() {
252
+ this.store = /* @__PURE__ */ new Map();
253
+ }
254
+ set(key, value) {
255
+ this.store.set(key, JSON.stringify(value));
256
+ if (typeof localStorage !== "undefined") {
257
+ localStorage.setItem(key, JSON.stringify(value));
258
+ }
259
+ }
260
+ get(key) {
261
+ const value = this.store.get(key) || (typeof localStorage !== "undefined" ? localStorage.getItem(key) : null);
262
+ return value ? JSON.parse(value) : null;
263
+ }
264
+ remove(key) {
265
+ this.store.delete(key);
266
+ if (typeof localStorage !== "undefined") {
267
+ localStorage.removeItem(key);
268
+ }
269
+ }
270
+ clear() {
271
+ this.store.clear();
272
+ if (typeof localStorage !== "undefined") {
273
+ localStorage.clear();
274
+ }
275
+ }
276
+ };
277
+
278
+ // src/tx/transaction.ts
279
+ function createTransaction(sender, receiver, amountKana, nonce, publicKeyHex) {
280
+ const fee = 1e3;
281
+ return {
282
+ sender,
283
+ receiver,
284
+ amount: amountKana,
285
+ fee,
286
+ nonce,
287
+ payload: publicKeyHex,
288
+ signature: ""
289
+ };
290
+ }
291
+ // Annotate the CommonJS export names for ESM import in node:
292
+ 0 && (module.exports = {
293
+ BlockHash,
294
+ DomainHasher,
295
+ MerkleHash,
296
+ RpcClient,
297
+ Storage,
298
+ TxHash,
299
+ TxID,
300
+ TxSigningHash,
301
+ Wallet,
302
+ addService,
303
+ addressToScriptPubkey,
304
+ createDid,
305
+ createTransaction,
306
+ isValidAddress,
307
+ keypair,
308
+ pubkeyToAddress,
309
+ sha3,
310
+ shake128Bytes,
311
+ shake256Bytes,
312
+ shake256Digest,
313
+ sign,
314
+ verify
315
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,258 @@
1
+ // src/sha3.ts
2
+ import { sha3_256, shake256, shake128 } from "@noble/hashes/sha3";
3
+ var DomainHasher = class _DomainHasher {
4
+ constructor(domain) {
5
+ this.init = new Uint8Array(sha3_256(new TextEncoder().encode(domain)));
6
+ }
7
+ hash(data) {
8
+ const h = sha3_256.create();
9
+ h.update(this.init);
10
+ h.update(data);
11
+ return new Uint8Array(h.digest());
12
+ }
13
+ clone() {
14
+ const d = new _DomainHasher("");
15
+ d.init = new Uint8Array(this.init);
16
+ return d;
17
+ }
18
+ };
19
+ var TxHash = new DomainHasher("TransactionHash");
20
+ var TxID = new DomainHasher("TransactionID");
21
+ var TxSigningHash = new DomainHasher("TransactionSigningHash");
22
+ var BlockHash = new DomainHasher("BlockHash");
23
+ var MerkleHash = new DomainHasher("MerkleBranchHash");
24
+ function sha3(data) {
25
+ return new Uint8Array(sha3_256(data));
26
+ }
27
+ function shake256Bytes(data, len) {
28
+ return new Uint8Array(shake256(data, { dkLen: len }));
29
+ }
30
+ function shake128Bytes(data, len) {
31
+ return new Uint8Array(shake128(data, { dkLen: len }));
32
+ }
33
+ function shake256Digest(data, outputLen) {
34
+ return new Uint8Array(shake256(data, { dkLen: outputLen }));
35
+ }
36
+
37
+ // src/address.ts
38
+ import * as _bech32 from "bech32";
39
+ var bech32 = _bech32;
40
+ var PREFIX_MAIN = "csm";
41
+ var PREFIX_TEST = "csmtest";
42
+ function pubkeyToHash(pk) {
43
+ return sha3(pk).slice(0, 20);
44
+ }
45
+ function pubkeyToAddress(pk, testnet = false) {
46
+ const hash = pubkeyToHash(pk);
47
+ const words = bech32.toWords(hash);
48
+ return bech32.encode(testnet ? PREFIX_TEST : PREFIX_MAIN, words);
49
+ }
50
+ function isValidAddress(addr, testnet = false) {
51
+ try {
52
+ const { prefix, words } = bech32.decode(addr);
53
+ if (prefix !== (testnet ? PREFIX_TEST : PREFIX_MAIN)) return false;
54
+ const data = bech32.fromWords(words);
55
+ return data.length === 20;
56
+ } catch {
57
+ return false;
58
+ }
59
+ }
60
+ function addressToScriptPubkey(addr) {
61
+ const { words } = bech32.decode(addr);
62
+ const data = bech32.fromWords(words);
63
+ const script = new Uint8Array(22);
64
+ script[0] = 20;
65
+ script.set(data, 1);
66
+ script[21] = 172;
67
+ return script;
68
+ }
69
+
70
+ // src/dilithium/index.ts
71
+ import { ml_dsa65 } from "@noble/post-quantum/ml-dsa.js";
72
+ function keypair() {
73
+ const keys = ml_dsa65.keygen();
74
+ return {
75
+ publicKey: keys.publicKey,
76
+ secretKey: keys.secretKey
77
+ };
78
+ }
79
+ function sign(secretKey, message) {
80
+ return ml_dsa65.sign(message, secretKey);
81
+ }
82
+ function verify(publicKey, signature, message) {
83
+ return ml_dsa65.verify(signature, message, publicKey);
84
+ }
85
+
86
+ // src/rpc/client.ts
87
+ var RpcClient = class {
88
+ constructor(url = "ws://127.0.0.1:27110") {
89
+ this.ws = null;
90
+ this.connected = false;
91
+ this.url = url;
92
+ }
93
+ async connect() {
94
+ return new Promise((resolve, reject) => {
95
+ this.ws = new WebSocket(this.url);
96
+ this.ws.onopen = () => {
97
+ this.connected = true;
98
+ resolve();
99
+ };
100
+ this.ws.onerror = (e) => reject(e);
101
+ });
102
+ }
103
+ isConnected() {
104
+ return this.connected;
105
+ }
106
+ async call(method, params) {
107
+ return new Promise((resolve, reject) => {
108
+ if (!this.ws || !this.connected) {
109
+ reject("Not connected");
110
+ return;
111
+ }
112
+ const id = Date.now();
113
+ const handler = (e) => {
114
+ const data = JSON.parse(e.data);
115
+ if (data.id === id) {
116
+ this.ws.removeEventListener("message", handler);
117
+ resolve(data.result || data);
118
+ }
119
+ };
120
+ this.ws.addEventListener("message", handler);
121
+ this.ws.send(JSON.stringify({ jsonrpc: "2.0", id, method, params }));
122
+ });
123
+ }
124
+ async getBalance(address) {
125
+ const result = await this.call("getBalanceByAddress", { address });
126
+ return result?.balance || 0;
127
+ }
128
+ async submitTransaction(tx) {
129
+ const result = await this.call("submitAccountTransaction", tx);
130
+ return result?.transactionId || "";
131
+ }
132
+ };
133
+
134
+ // src/wallet/index.ts
135
+ var Wallet = class {
136
+ constructor(rpcUrl = "ws://127.0.0.1:27110") {
137
+ this.publicKey = new Uint8Array(1952);
138
+ this.secretKey = new Uint8Array(4032);
139
+ this.address = "";
140
+ this.balance = 0;
141
+ this.nonce = 0;
142
+ this.rpc = new RpcClient(rpcUrl);
143
+ }
144
+ async connect() {
145
+ await this.rpc.connect();
146
+ }
147
+ create() {
148
+ const { publicKey, secretKey } = keypair();
149
+ this.publicKey = publicKey;
150
+ this.secretKey = secretKey;
151
+ this.address = pubkeyToAddress(publicKey);
152
+ }
153
+ async getBalance() {
154
+ this.balance = await this.rpc.getBalance(this.address);
155
+ return this.balance;
156
+ }
157
+ async send(to, amountKana) {
158
+ const payload = Buffer.from(this.publicKey).toString("hex");
159
+ const txData = `${this.address}:${to}:${amountKana}:${this.nonce}`;
160
+ const signature = sign(this.secretKey, new TextEncoder().encode(txData));
161
+ const sigHex = Buffer.from(signature).toString("hex");
162
+ const tx = {
163
+ sender: this.address,
164
+ receiver: to,
165
+ amount: amountKana,
166
+ fee: 1e3,
167
+ nonce: this.nonce,
168
+ payload,
169
+ signature: sigHex
170
+ };
171
+ const txId = await this.rpc.submitTransaction(tx);
172
+ this.nonce++;
173
+ return txId;
174
+ }
175
+ };
176
+
177
+ // src/did/index.ts
178
+ function createDid(address, publicKeyHex) {
179
+ const did = `did:sahyadri:${address}`;
180
+ return {
181
+ id: did,
182
+ controller: address,
183
+ publicKeyHex,
184
+ created: Math.floor(Date.now() / 1e3),
185
+ services: []
186
+ };
187
+ }
188
+ function addService(doc, type, endpoint) {
189
+ doc.services.push({ type, endpoint });
190
+ return doc;
191
+ }
192
+
193
+ // src/storage/index.ts
194
+ var Storage = class {
195
+ constructor() {
196
+ this.store = /* @__PURE__ */ new Map();
197
+ }
198
+ set(key, value) {
199
+ this.store.set(key, JSON.stringify(value));
200
+ if (typeof localStorage !== "undefined") {
201
+ localStorage.setItem(key, JSON.stringify(value));
202
+ }
203
+ }
204
+ get(key) {
205
+ const value = this.store.get(key) || (typeof localStorage !== "undefined" ? localStorage.getItem(key) : null);
206
+ return value ? JSON.parse(value) : null;
207
+ }
208
+ remove(key) {
209
+ this.store.delete(key);
210
+ if (typeof localStorage !== "undefined") {
211
+ localStorage.removeItem(key);
212
+ }
213
+ }
214
+ clear() {
215
+ this.store.clear();
216
+ if (typeof localStorage !== "undefined") {
217
+ localStorage.clear();
218
+ }
219
+ }
220
+ };
221
+
222
+ // src/tx/transaction.ts
223
+ function createTransaction(sender, receiver, amountKana, nonce, publicKeyHex) {
224
+ const fee = 1e3;
225
+ return {
226
+ sender,
227
+ receiver,
228
+ amount: amountKana,
229
+ fee,
230
+ nonce,
231
+ payload: publicKeyHex,
232
+ signature: ""
233
+ };
234
+ }
235
+ export {
236
+ BlockHash,
237
+ DomainHasher,
238
+ MerkleHash,
239
+ RpcClient,
240
+ Storage,
241
+ TxHash,
242
+ TxID,
243
+ TxSigningHash,
244
+ Wallet,
245
+ addService,
246
+ addressToScriptPubkey,
247
+ createDid,
248
+ createTransaction,
249
+ isValidAddress,
250
+ keypair,
251
+ pubkeyToAddress,
252
+ sha3,
253
+ shake128Bytes,
254
+ shake256Bytes,
255
+ shake256Digest,
256
+ sign,
257
+ verify
258
+ };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@sahyadrinet/web3.js",
3
+ "version": "0.1.0",
4
+ "description": "Sahyadri L1 Blockchain SDK - Post-Quantum Secure Web3 Library",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsup src/index.ts --format cjs,esm --dts",
17
+ "test": "npx tsx test-full.ts"
18
+ },
19
+ "keywords": [
20
+ "sahyadri",
21
+ "blockchain",
22
+ "web3",
23
+ "post-quantum",
24
+ "dilithium",
25
+ "ml-dsa",
26
+ "crypto"
27
+ ],
28
+ "author": "Sahyadri Network",
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "@noble/hashes": "^2.0.0",
32
+ "@noble/post-quantum": "^0.7.1",
33
+ "@scure/base": "^1.1.7"
34
+ },
35
+ "devDependencies": {
36
+ "tsx": "^4.19.0",
37
+ "tsup": "^8.3.5",
38
+ "typescript": "^5.6.2"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/sahyadrinet/sahyadri-sdk.git"
43
+ }
44
+ }