@warganetwork/sdk 0.0.0-stage → 1.4.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,38 @@
1
+ /**
2
+ * Real-world example: Lock & Release UMKM order payment via MerchantEscrow.vy (ethers v6).
3
+ *
4
+ * Requires: npm install ethers github:Faang21/warga-sdk
5
+ */
6
+ import { ethers } from "ethers";
7
+ import { WARGA_MAINNET, CONTRACTS, ABIS, parseWrg } from "@warganetwork/sdk";
8
+
9
+ export async function runEscrowExample({ buyerPrivateKey, operatorPrivateKey, merchantAddress, orderCode, amountIdr }) {
10
+ const provider = new ethers.JsonRpcProvider(WARGA_MAINNET.rpcUrls.default.http[0], {
11
+ name: WARGA_MAINNET.name,
12
+ chainId: WARGA_MAINNET.id,
13
+ });
14
+
15
+ const buyer = new ethers.Wallet(buyerPrivateKey, provider);
16
+ const operator = new ethers.Wallet(operatorPrivateKey, provider);
17
+
18
+ const idr = new ethers.Contract(CONTRACTS.IDRToken, ABIS.IDRToken, buyer);
19
+ const escrowAsBuyer = new ethers.Contract(CONTRACTS.MerchantEscrow, ABIS.MerchantEscrow, buyer);
20
+ const escrowAsOperator = new ethers.Contract(CONTRACTS.MerchantEscrow, ABIS.MerchantEscrow, operator);
21
+
22
+ const orderId = ethers.id(orderCode); // bytes32 deterministic hash
23
+ const amountWei = parseWrg(amountIdr);
24
+
25
+ // 1. Approve exact order amount (never unlimited approval)
26
+ const approveTx = await idr.approve(CONTRACTS.MerchantEscrow, amountWei);
27
+ await approveTx.wait(1);
28
+
29
+ // 2. Buyer locks funds into MerchantEscrow
30
+ const lockTx = await escrowAsBuyer.lock_order(orderId, merchantAddress, amountWei);
31
+ await lockTx.wait(1);
32
+
33
+ // 3. After delivery confirmation, escrow operator releases funds to merchant
34
+ const releaseTx = await escrowAsOperator.release_escrow(orderId);
35
+ const receipt = await releaseTx.wait(1);
36
+
37
+ return { orderId, releaseTxHash: receipt.hash };
38
+ }
@@ -0,0 +1,10 @@
1
+ [profile.default]
2
+ src = "src"
3
+ out = "out"
4
+ libs = ["lib"]
5
+ evm_version = "cancun"
6
+
7
+ [rpc_endpoints]
8
+ warga_mainnet = "https://warganetwork.org/rpc"
9
+ warga_testnet = "https://warganetwork.org/rpc/testnet"
10
+ arbitrum_one = "https://arb1.arbitrum.io/rpc"
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Sample Hardhat configuration for Warga Network L1 (Chain ID 882026),
3
+ * Warga Network Testnet (Chain ID 2027), and Arbitrum One (Chain ID 42161).
4
+ *
5
+ * Set DEPLOYER_PRIVATE_KEY in your local .env (NEVER commit real private keys).
6
+ */
7
+ export default {
8
+ networks: {
9
+ wargaMainnet: {
10
+ url: "https://warganetwork.org/rpc",
11
+ chainId: 882026,
12
+ accounts: process.env.DEPLOYER_PRIVATE_KEY ? [process.env.DEPLOYER_PRIVATE_KEY] : [],
13
+ gasPrice: 1000000000, // 1 Gwei
14
+ },
15
+ wargaTestnet: {
16
+ url: "https://warganetwork.org/rpc/testnet",
17
+ chainId: 2027,
18
+ accounts: process.env.DEPLOYER_PRIVATE_KEY ? [process.env.DEPLOYER_PRIVATE_KEY] : [],
19
+ },
20
+ arbitrumOne: {
21
+ url: process.env.ARBITRUM_RPC_URL || "https://arb1.arbitrum.io/rpc",
22
+ chainId: 42161,
23
+ accounts: process.env.DEPLOYER_PRIVATE_KEY ? [process.env.DEPLOYER_PRIVATE_KEY] : [],
24
+ },
25
+ },
26
+ etherscan: {
27
+ apiKey: {
28
+ wargaMainnet: "warga-public",
29
+ },
30
+ customChains: [
31
+ {
32
+ network: "wargaMainnet",
33
+ chainId: 882026,
34
+ urls: {
35
+ apiURL: "https://warganetwork.org/api/warganetwork/explorer",
36
+ browserURL: "https://warganetwork.org/explorer",
37
+ },
38
+ },
39
+ ],
40
+ },
41
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Real-world example: Verify ERC-5192 Soulbound KYC Badge & Mint Badge (minter role)
3
+ * on MerchantKYCBadgeNFT.vy (ethers v6).
4
+ *
5
+ * Requires: npm install ethers github:Faang21/warga-sdk
6
+ */
7
+ import { ethers } from "ethers";
8
+ import { WARGA_MAINNET, CONTRACTS, ABIS } from "@warganetwork/sdk";
9
+
10
+ const ERC5192_INTERFACE_ID = "0xb45a3c0e";
11
+
12
+ export async function verifyMerchantBadge(tokenId) {
13
+ const provider = new ethers.JsonRpcProvider(WARGA_MAINNET.rpcUrls.default.http[0], WARGA_MAINNET.id);
14
+ const sbt = new ethers.Contract(CONTRACTS.MerchantKYCBadgeNFT, ABIS.MerchantKYCBadgeNFT, provider);
15
+
16
+ const [isErc5192, isLocked, owner, uri] = await Promise.all([
17
+ sbt.supportsInterface(ERC5192_INTERFACE_ID),
18
+ sbt.locked(tokenId),
19
+ sbt.ownerOf(tokenId),
20
+ sbt.tokenURI(tokenId),
21
+ ]);
22
+
23
+ return { isErc5192, isLocked, owner, uri };
24
+ }
25
+
26
+ export async function mintMerchantBadge({ minterPrivateKey, merchantAddress, storeId, storeName, kycSha256Hex, metadataUri }) {
27
+ const provider = new ethers.JsonRpcProvider(WARGA_MAINNET.rpcUrls.default.http[0], WARGA_MAINNET.id);
28
+ const minter = new ethers.Wallet(minterPrivateKey, provider);
29
+ const sbt = new ethers.Contract(CONTRACTS.MerchantKYCBadgeNFT, ABIS.MerchantKYCBadgeNFT, minter);
30
+
31
+ // Stores SHA-256 hash only on-chain (zero raw PII / UU PDP compliant)
32
+ const tx = await sbt.mintBadge(merchantAddress, storeId, storeName, kycSha256Hex, metadataUri);
33
+ const receipt = await tx.wait(1);
34
+ return { txHash: receipt.hash };
35
+ }
@@ -0,0 +1,29 @@
1
+ import crypto from "node:crypto";
2
+
3
+ /**
4
+ * Constant-time HMAC-SHA256 webhook signature verifier for UMKM merchant integrations.
5
+ * Prevents timing side-channel attacks and rejects forged webhook callbacks.
6
+ */
7
+ export function verifyWebhookSignature(rawBody, signatureHex, webhookSecret) {
8
+ if (!rawBody || !signatureHex || !webhookSecret) return false;
9
+ const expected = crypto
10
+ .createHmac("sha256", String(webhookSecret))
11
+ .update(typeof rawBody === "string" ? rawBody : JSON.stringify(rawBody))
12
+ .digest("hex");
13
+
14
+ const cleanSig = String(signatureHex).trim().toLowerCase().replace(/^sha256=/, "");
15
+ if (cleanSig.length !== expected.length || !/^[0-9a-f]+$/.test(cleanSig)) {
16
+ return false;
17
+ }
18
+ return crypto.timingSafeEqual(Buffer.from(cleanSig, "hex"), Buffer.from(expected, "hex"));
19
+ }
20
+
21
+ /**
22
+ * Helper to generate an HMAC-SHA256 signature for local testing.
23
+ */
24
+ export function signWebhookPayload(rawBody, webhookSecret) {
25
+ return crypto
26
+ .createHmac("sha256", String(webhookSecret))
27
+ .update(typeof rawBody === "string" ? rawBody : JSON.stringify(rawBody))
28
+ .digest("hex");
29
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Real NIST FIPS 204 (ML-DSA-65 / CRYSTALS-Dilithium3) Post-Quantum Signing & Verification Example
3
+ * Works in modern browsers and Node.js >= 18 using audited @noble/post-quantum.
4
+ *
5
+ * Install: npm install @noble/post-quantum github:Faang21/warga-sdk
6
+ */
7
+ import { ml_dsa65 } from "@noble/post-quantum/ml-dsa.js";
8
+ import { WargaClient } from "@warganetwork/sdk";
9
+
10
+ /**
11
+ * 1. Generate a local NIST FIPS 204 ML-DSA-65 keypair, sign a message, and verify locally.
12
+ */
13
+ export function localMLDSA65Demo(message = "Warga Network L1 Post-Quantum Attestation") {
14
+ const { publicKey, secretKey } = ml_dsa65.keygen();
15
+ const msgBytes = new TextEncoder().encode(message);
16
+ const signature = ml_dsa65.sign(msgBytes, secretKey);
17
+ const isValid = ml_dsa65.verify(signature, msgBytes, publicKey);
18
+
19
+ return {
20
+ standard: "NIST FIPS 204 (ML-DSA-65)",
21
+ publicKeyBytes: publicKey.length, // 1,952 bytes
22
+ signatureBytes: signature.length, // 3,309 bytes
23
+ isValid,
24
+ };
25
+ }
26
+
27
+ /**
28
+ * 2. Fetch a live ML-DSA-65 attestation from Warga Network L1 and independently verify it locally!
29
+ */
30
+ export async function verifyLiveWargaAttestation() {
31
+ const client = new WargaClient();
32
+ const [pubkeyRes, attRes] = await Promise.all([
33
+ client.getPqcPubKey(),
34
+ client.getPqcAttestation(),
35
+ ]);
36
+
37
+ const hexToBytes = (hex) => {
38
+ const clean = hex.replace(/^0x/i, "");
39
+ const out = new Uint8Array(clean.length / 2);
40
+ for (let i = 0; i < out.length; i++) out[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
41
+ return out;
42
+ };
43
+
44
+ const pubKeyBytes = hexToBytes(pubkeyRes.publicKeyHex);
45
+ const sigBytes = hexToBytes(attRes.signatureHex);
46
+ const msgBytes = new TextEncoder().encode(attRes.message);
47
+
48
+ const verifiedLocally = ml_dsa65.verify(sigBytes, msgBytes, pubKeyBytes);
49
+ return {
50
+ message: attRes.message,
51
+ fingerprint: pubkeyRes.fingerprintSha256,
52
+ verifiedLocally,
53
+ };
54
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Real-world example: Quote & execute constant-product (x * y = k) swap on WargaSwapV3Pool.vy
3
+ * with strict slippage protection (ethers v6).
4
+ *
5
+ * Requires: npm install ethers github:Faang21/warga-sdk
6
+ */
7
+ import { ethers } from "ethers";
8
+ import { WARGA_MAINNET, CONTRACTS, ABIS, parseWrg, formatWrg } from "@warganetwork/sdk";
9
+
10
+ export async function quoteAndSwap({ traderPrivateKey, tokenInAddress, amountInHuman, slippageBps = 50 }) {
11
+ const provider = new ethers.JsonRpcProvider(WARGA_MAINNET.rpcUrls.default.http[0], WARGA_MAINNET.id);
12
+ const trader = new ethers.Wallet(traderPrivateKey, provider);
13
+
14
+ const pool = new ethers.Contract(CONTRACTS.WargaSwapV3Pool, ABIS.WargaSwapV3Pool, trader);
15
+ const tokenIn = new ethers.Contract(tokenInAddress, ABIS.WargaCoin, trader);
16
+
17
+ const amountInWei = parseWrg(amountInHuman);
18
+
19
+ // 1. Read pool reserves & exact on-chain output quote
20
+ const [r0, r1] = await pool.get_reserves();
21
+ const quotedOut = await pool.get_amount_out(tokenInAddress, amountInWei);
22
+
23
+ // 2. Apply slippage tolerance (e.g., 50 bps = 0.50%)
24
+ const minAmountOut = (quotedOut * BigInt(10000 - slippageBps)) / 10000n;
25
+
26
+ // 3. Approve exact swap input & execute swap
27
+ const appTx = await tokenIn.approve(CONTRACTS.WargaSwapV3Pool, amountInWei);
28
+ await appTx.wait(1);
29
+
30
+ const swapTx = await pool.swap(tokenInAddress, amountInWei, minAmountOut, trader.address);
31
+ const receipt = await swapTx.wait(1);
32
+
33
+ return {
34
+ reservesBefore: [formatWrg(r0), formatWrg(r1)],
35
+ quotedOut: formatWrg(quotedOut),
36
+ minAmountOut: formatWrg(minAmountOut),
37
+ txHash: receipt.hash,
38
+ };
39
+ }
@@ -0,0 +1,233 @@
1
+ openapi: 3.0.3
2
+ info:
3
+ title: Warga Network Layer-1 Public API & JSON-RPC Specification
4
+ version: 1.0.0
5
+ description: >
6
+ Verified public endpoints for Warga Network Layer-1 (Chain ID 882026),
7
+ WargaScan Explorer, and Anti-Scam / Hash-Based Quantum Commitment telemetry.
8
+ Import this file directly into Postman, Insomnia, or Swagger UI.
9
+ contact:
10
+ name: PT UMKM RUMAHAN DIGITAL
11
+ url: https://warganetwork.org/developer
12
+ license:
13
+ name: MIT
14
+ url: https://github.com/Faang21/warga-sdk/blob/main/LICENSE
15
+
16
+ servers:
17
+ - url: https://warganetwork.org
18
+ description: Warga Network Production Gateway (Chain ID 882026)
19
+
20
+ paths:
21
+ /rpc:
22
+ post:
23
+ summary: EVM JSON-RPC 2.0 Endpoint (Chain ID 882026)
24
+ operationId: jsonRpcCall
25
+ tags: [JSON-RPC]
26
+ requestBody:
27
+ required: true
28
+ content:
29
+ application/json:
30
+ schema:
31
+ type: object
32
+ required: [jsonrpc, id, method]
33
+ properties:
34
+ jsonrpc:
35
+ type: string
36
+ example: "2.0"
37
+ id:
38
+ type: integer
39
+ example: 1
40
+ method:
41
+ type: string
42
+ enum:
43
+ - eth_chainId
44
+ - eth_blockNumber
45
+ - eth_gasPrice
46
+ - eth_getBalance
47
+ - eth_getTransactionCount
48
+ - eth_call
49
+ - eth_estimateGas
50
+ - eth_sendRawTransaction
51
+ example: eth_blockNumber
52
+ params:
53
+ type: array
54
+ items: {}
55
+ example: []
56
+ responses:
57
+ "200":
58
+ description: JSON-RPC 2.0 result or error object
59
+ content:
60
+ application/json:
61
+ schema:
62
+ type: object
63
+ properties:
64
+ jsonrpc:
65
+ type: string
66
+ example: "2.0"
67
+ id:
68
+ type: integer
69
+ result:
70
+ nullable: true
71
+ error:
72
+ type: object
73
+ nullable: true
74
+
75
+ /api/warganetwork/explorer/overview:
76
+ get:
77
+ summary: Live Explorer Overview (Latest Blocks, Stats & Transactions)
78
+ operationId: getExplorerOverview
79
+ tags: [Explorer]
80
+ parameters:
81
+ - name: limit
82
+ in: query
83
+ required: false
84
+ schema:
85
+ type: integer
86
+ minimum: 1
87
+ maximum: 100
88
+ default: 10
89
+ responses:
90
+ "200":
91
+ description: Explorer summary payload
92
+ content:
93
+ application/json:
94
+ schema:
95
+ type: object
96
+ properties:
97
+ success:
98
+ type: boolean
99
+ data:
100
+ type: object
101
+
102
+ /api/warganetwork/explorer/lookup:
103
+ get:
104
+ summary: Lookup Wallet Address, Transaction Hash, or Block Number
105
+ operationId: explorerLookup
106
+ tags: [Explorer]
107
+ parameters:
108
+ - name: q
109
+ in: query
110
+ required: true
111
+ description: 0x address, 0x tx hash, or numeric block height
112
+ schema:
113
+ type: string
114
+ example: "0x2cba461c86d314195b5d8e99c93d551fd4f74435"
115
+ responses:
116
+ "200":
117
+ description: Lookup result
118
+ content:
119
+ application/json:
120
+ schema:
121
+ type: object
122
+ properties:
123
+ success:
124
+ type: boolean
125
+ data:
126
+ type: object
127
+
128
+ /api/pqc/status:
129
+ get:
130
+ summary: Backend Hash-Based Quantum Commitment & Vault Status
131
+ operationId: getPqcStatus
132
+ tags: [Security]
133
+ responses:
134
+ "200":
135
+ description: Security telemetry status
136
+ content:
137
+ application/json:
138
+ schema:
139
+ type: object
140
+ properties:
141
+ success:
142
+ type: boolean
143
+ quantum_active:
144
+ type: boolean
145
+ scheme:
146
+ type: string
147
+ components:
148
+ type: object
149
+
150
+ /api/pqc/scan-tx:
151
+ post:
152
+ summary: Anti-Scam & Drainer Heuristic Transaction Scanner
153
+ operationId: scanTransaction
154
+ tags: [Security]
155
+ requestBody:
156
+ required: true
157
+ content:
158
+ application/json:
159
+ schema:
160
+ type: object
161
+ properties:
162
+ to:
163
+ type: string
164
+ example: "0x71c7656ec7ab88b098defb751b7401b5f6d8976f"
165
+ data:
166
+ type: string
167
+ description: Hex-encoded calldata to inspect for unlimited approve or setApprovalForAll drainers
168
+ example: "0x095ea7b30000000000000000000000001111111111111111111111111111111111111111ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
169
+ responses:
170
+ "200":
171
+ description: Risk analysis response
172
+ content:
173
+ application/json:
174
+ schema:
175
+ type: object
176
+ properties:
177
+ success:
178
+ type: boolean
179
+ analysis:
180
+ type: object
181
+ properties:
182
+ isSafe:
183
+ type: boolean
184
+ riskLevel:
185
+ type: string
186
+ enum: [LOW, MEDIUM, HIGH, CRITICAL]
187
+ drainerDetected:
188
+ type: boolean
189
+ reasons:
190
+ type: array
191
+ items:
192
+ type: string
193
+
194
+ /api/pqc/pubkey:
195
+ get:
196
+ summary: Live NIST FIPS 204 (ML-DSA-65) Authority Public Key (1,952 bytes)
197
+ operationId: getPqcPubKey
198
+ tags: [Post-Quantum]
199
+ responses:
200
+ "200":
201
+ description: ML-DSA-65 public key metadata and hex string
202
+
203
+ /api/pqc/attestation:
204
+ get:
205
+ summary: Live NIST FIPS 204 (ML-DSA-65) Signed Chain Attestation (3,309-byte signature)
206
+ operationId: getPqcAttestation
207
+ tags: [Post-Quantum]
208
+ responses:
209
+ "200":
210
+ description: Freshly signed ML-DSA-65 attestation payload
211
+
212
+ /api/pqc/verify:
213
+ post:
214
+ summary: Verify a NIST FIPS 204 (ML-DSA-65) Lattice Signature
215
+ operationId: verifyMLDSA65
216
+ tags: [Post-Quantum]
217
+ requestBody:
218
+ required: true
219
+ content:
220
+ application/json:
221
+ schema:
222
+ type: object
223
+ required: [message, signature_hex]
224
+ properties:
225
+ message:
226
+ type: string
227
+ signature_hex:
228
+ type: string
229
+ public_key_hex:
230
+ type: string
231
+ responses:
232
+ "200":
233
+ description: Boolean cryptographic verification result
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
1
  {
2
2
  "name": "@warganetwork/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.4.0",
4
+ "description": "Browser-native, zero-dependency JS/TS client SDK (ESM + CJS) and verified Vyper 0.4.3 contract ABIs for Warga Network Layer-1 (Chain ID 882026) and WargaPay Web3.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.cjs",
8
+ "module": "./src/index.js",
9
+ "browser": "./src/index.js",
10
+ "types": "./src/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./src/index.d.ts",
14
+ "browser": "./src/index.js",
15
+ "import": "./src/index.js",
16
+ "require": "./dist/index.cjs"
17
+ },
18
+ "./abis": {
19
+ "import": "./src/abis/index.js"
20
+ },
21
+ "./helpers": {
22
+ "import": "./src/helpers.js"
23
+ },
24
+ "./tokenlist": "./tokenlist/warga.tokenlist.json"
25
+ },
26
+ "peerDependencies": {
27
+ "ethers": "^6.0.0",
28
+ "viem": "^2.0.0"
29
+ },
30
+ "peerDependenciesMeta": {
31
+ "ethers": { "optional": true },
32
+ "viem": { "optional": true }
33
+ },
34
+ "files": [
35
+ "src/",
36
+ "dist/",
37
+ "assets/",
38
+ "tokenlist/",
39
+ "openapi/",
40
+ "examples/",
41
+ "README.md",
42
+ "CHANGELOG.md",
43
+ "LICENSE"
44
+ ],
45
+ "scripts": {
46
+ "build": "node scripts/build-cjs.mjs",
47
+ "test": "node --test test/sdk.test.js",
48
+ "test:live": "WARGA_LIVE_TEST=1 node --test test/sdk.test.js"
49
+ },
50
+ "keywords": [
51
+ "warga-network",
52
+ "wargapay",
53
+ "ethereum",
54
+ "evm",
55
+ "vyper",
56
+ "arbitrum",
57
+ "web3",
58
+ "sdk",
59
+ "browser",
60
+ "umkm",
61
+ "indonesia"
62
+ ],
63
+ "author": "PT UMKM RUMAHAN DIGITAL",
64
+ "license": "MIT",
65
+ "engines": {
66
+ "node": ">=18.0.0"
67
+ },
68
+ "repository": {
69
+ "type": "git",
70
+ "url": "https://github.com/Faang21/warga-sdk.git"
71
+ },
72
+ "homepage": "https://warganetwork.org/developer",
73
+ "bugs": {
74
+ "url": "https://github.com/Faang21/warga-sdk/issues"
75
+ }
76
+ }