@nyontra/sdk 0.0.0-stage → 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 ADDED
@@ -0,0 +1,22 @@
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2024 Nyontra
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,142 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @nyontra/sdk — JavaScript / TypeScript
2
+
3
+ Official SDK for the [Nyontra developer portal](../../docs/README.md). Local
4
+ secp256k1 key management, canonical transaction signing, and an HTTP client for
5
+ the **Nyontra Dev Portal Backend (gateway)** — the single entry point through
6
+ which all developer traffic flows.
7
+
8
+ The gateway authenticates your project with an API key, applies rate limits, and
9
+ proxies requests to the Nyontra core network. You never need to talk to the core
10
+ directly.
11
+
12
+ ```bash
13
+ npm install @nyontra/sdk ethers
14
+ ```
15
+
16
+ (`ethers` is the SDK's only runtime dependency.)
17
+
18
+ ## Quickstart
19
+
20
+ ```ts
21
+ import { Account, NyontraClient } from "@nyontra/sdk";
22
+
23
+ // 1. Keys are generated locally — the private key never leaves your machine.
24
+ const account = Account.generate();
25
+ console.log(account.address, account.mnemonic); // back these up!
26
+
27
+ // 2. Connect to the dev-portal gateway with your project API key.
28
+ // Get your key from the Dev Portal dashboard (create a project → copy x-api-key).
29
+ const client = new NyontraClient({
30
+ gatewayUrl: "https://api.nyontra.com, // your api URL
31
+ apiKey: "nyon_sk_your_api_key_here", // from the Dev Portal
32
+ });
33
+
34
+ // 3. Transfer — nonce fetched automatically, signing local, one POST.
35
+ const result = await client.transfer(account, {
36
+ to: "0x2222222222222222222222222222222222222222",
37
+ amount: 100,
38
+ data: { memo: "invoice #42" }, // optional JSON memo, locked into the chain
39
+ });
40
+ console.log(result.hash, result.replication.quorum);
41
+ ```
42
+
43
+ ## Accounts (key management)
44
+
45
+ ```ts
46
+ const fresh = Account.generate(); // random + BIP-39 mnemonic
47
+ const fromKey = Account.fromPrivateKey("0x..."); // 0x-prefixed (or bare) hex key
48
+ const fromPhrase = Account.fromMnemonic("word1 word2 ... word12");
49
+
50
+ fresh.address; // EIP-55 checksummed 0x address
51
+ fresh.privateKey; // 0x + 64 hex — keep secret!
52
+ fresh.mnemonic; // phrase or null (raw-key imports)
53
+ fresh.export(); // { address, privateKey, mnemonic? }
54
+ ```
55
+
56
+ Keys are standard secp256k1/EIP-55 — importable into MetaMask, ethers, viem,
57
+ or hardware wallets.
58
+
59
+ ## Transactions
60
+
61
+ `signTx(account, input)` validates locally, builds the exact canonical
62
+ message, signs EIP-191, and returns the wire object the gateway forwards to
63
+ core:
64
+
65
+ ```ts
66
+ import { signTx, buildTransferTx } from "@nyontra/sdk";
67
+
68
+ const nonce = await client.getNonce(account.address); // must be exact
69
+
70
+ const signed = await signTx(account, {
71
+ type: "TRANSFER", // TRANSFER | UPDATE_NAME | SET_PERMISSIONS
72
+ to: "0x2222...2222", // required for TRANSFER/SET_PERMISSIONS
73
+ amount: 100, // non-negative integer (number or string)
74
+ nonce, // next account nonce
75
+ data: { any: "json" }, // optional memo, ≤ 256 chars canonical JSON
76
+ });
77
+ await client.broadcast(signed);
78
+ ```
79
+
80
+ Notes:
81
+ - `amount` must be an **integer** — use strings for values > 2^53.
82
+ - `nonce` must equal the account's current nonce exactly; a `403 "nonce
83
+ mismatch"` means a concurrent tx took the slot — refetch and retry.
84
+ - Re-broadcasting the identical signed tx is safe (idempotent on
85
+ `(sender, nonce)`) — retry freely after network timeouts.
86
+ - `timestamp` on the signed object is informational only (not signed).
87
+
88
+ Other tx types use the same helper — e.g. rename:
89
+ `signTx(account, { type: "UPDATE_NAME", payload: "new-name", nonce })`.
90
+
91
+ ## Client (HTTP)
92
+
93
+ ```ts
94
+ const client = new NyontraClient({
95
+ gatewayUrl: "https://api.nyontra.com, // your api URL
96
+ apiKey: "nyon_sk_your_api_key_here", // required by api
97
+ requester: account.address, // optional X-Nyontra-Requester for reads
98
+ });
99
+ ```
100
+
101
+ | Method | Gateway endpoint | Notes |
102
+ |---|---|---|
103
+ | `transfer(account, {to, amount, data?, nonce?})` | `POST /api/rest/v1/tx/broadcast` | fetches nonce → signs → broadcasts |
104
+ | `broadcast(signedTx)` | `POST /api/rest/v1/tx/broadcast` | pre-signed tx |
105
+ | `getAccount(address)` | `GET /api/rest/v1/account/:address` | includes `nonce`, `balance`, `permissions` |
106
+ | `getBalance(address)` | `GET /api/rest/v1/balance/:address` | number |
107
+ | `getNonce(address)` | via `GET /api/rest/v1/account/:address` | next tx nonce |
108
+ | `getTxStatus(hash)` | `GET /api/rest/v1/tx/status/:hash` | `{status: "confirmed" \| "not_found", data?}` |
109
+ | `getHistory(address, {limit?, as?})` | `GET /api/rest/v1/history/:address` | needs self/VIEW_ALL_HISTORY requester |
110
+ | `getBlockCurrent()` | `GET /api/rest/v1/block/current` | chain tip |
111
+ | `getHealth()` | `GET /api/rest/v1/health` | plain text |
112
+
113
+ Non-2xx responses throw `NyontraApiError` with `.status` (400 structural,
114
+ 403 signature/state, 409 retryable race, 501 unknown type) and parsed `.body`.
115
+
116
+ ## Example script
117
+
118
+ ```bash
119
+ NYONTRA_PRIVATE_KEY=0x... npx tsx examples/transfer.ts 0xRecipient 100
120
+ ```
121
+
122
+ See [`examples/transfer.ts`](./examples/transfer.ts).
123
+
124
+ ## Development
125
+
126
+ ```bash
127
+ npm install
128
+ npm run build # tsc → dist/ (ESM + .d.ts)
129
+ npm test # vitest — golden signing vectors + client mocks
130
+ npm run typecheck
131
+ ```
132
+
133
+ `test/signing.test.ts` pins the canonical message format with golden vectors
134
+ derived from `core/src/lib/signature.ts`; signatures are verified with viem
135
+ (`verifyMessage`) exactly as core verifies them. Breaking those vectors breaks
136
+ production signatures — they are the compatibility contract.
137
+
138
+ ## Links
139
+
140
+ - Dev Portal (create projects, get API keys): portal
141
+ - Gateway backend (API reference, rate limits): api
142
+ - Full docs: [docs/](../../docs/README.md)
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Keypair generation and management — secp256k1, Ethereum-compatible, so keys
3
+ * interoperate with any standard tooling (ethers, viem, MetaMask, hardware
4
+ * wallets). Signatures are EIP-191 personal messages, verified by core.
5
+ *
6
+ * The private key never leaves the process: signing happens locally via
7
+ * Account.signMessage(), and only the signature is ever sent over HTTP.
8
+ */
9
+ /** Exported key material. Store `privateKey` (or `mnemonic`) securely! */
10
+ export interface Keypair {
11
+ /** EIP-55 checksummed address (0x + 40 hex). Core compares case-insensitively. */
12
+ address: string;
13
+ /** 0x-prefixed 32-byte hex private key. */
14
+ privateKey: string;
15
+ /** BIP-39 mnemonic phrase (present when generated via Account.generate() or fromMnemonic()). */
16
+ mnemonic?: string;
17
+ }
18
+ /**
19
+ * A Nyontra signing account. Wraps an ethers v6 wallet; addresses are the
20
+ * checksummed form and lowercase themselves transparently at sign time.
21
+ */
22
+ export declare class Account {
23
+ private readonly wallet;
24
+ private constructor();
25
+ /** EIP-55 checksummed address. */
26
+ get address(): string;
27
+ /** 0x-prefixed private key. Keep secret. */
28
+ get privateKey(): string;
29
+ /** BIP-39 mnemonic phrase, or null when the account was imported from a raw key. */
30
+ get mnemonic(): string | null;
31
+ /** Generate a fresh random account (returns its mnemonic — back it up). */
32
+ static generate(): Account;
33
+ /** Import from a 0x-prefixed (or bare) 32-byte hex private key. */
34
+ static fromPrivateKey(privateKey: string): Account;
35
+ /** Import from a BIP-39 mnemonic phrase. */
36
+ static fromMnemonic(phrase: string): Account;
37
+ /**
38
+ * Sign an arbitrary message with EIP-191 personal-message prefixing
39
+ * ("\x19Ethereum Signed Message:\n" + len + message). This is exactly what
40
+ * core's verifyMessage() expects for transaction signatures — the SDK uses
41
+ * it internally; exposed as an escape hatch for custom/governance flows.
42
+ */
43
+ signMessage(message: string): Promise<string>;
44
+ /** Export the key material as a plain object. */
45
+ export(): Keypair;
46
+ }
47
+ //# sourceMappingURL=account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,0EAA0E;AAC1E,MAAM,WAAW,OAAO;IACtB,kFAAkF;IAClF,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,gGAAgG;IAChG,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;IAE/C,OAAO;IAIP,kCAAkC;IAClC,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,4CAA4C;IAC5C,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,oFAAoF;IACpF,IAAI,QAAQ,IAAI,MAAM,GAAG,IAAI,CAE5B;IAED,2EAA2E;IAC3E,MAAM,CAAC,QAAQ,IAAI,OAAO;IAI1B,mEAAmE;IACnE,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAMlD,4CAA4C;IAC5C,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI5C;;;;;OAKG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI7C,iDAAiD;IACjD,MAAM,IAAI,OAAO;CAKlB"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Keypair generation and management — secp256k1, Ethereum-compatible, so keys
3
+ * interoperate with any standard tooling (ethers, viem, MetaMask, hardware
4
+ * wallets). Signatures are EIP-191 personal messages, verified by core.
5
+ *
6
+ * The private key never leaves the process: signing happens locally via
7
+ * Account.signMessage(), and only the signature is ever sent over HTTP.
8
+ */
9
+ import { Wallet, HDNodeWallet } from "ethers";
10
+ /**
11
+ * A Nyontra signing account. Wraps an ethers v6 wallet; addresses are the
12
+ * checksummed form and lowercase themselves transparently at sign time.
13
+ */
14
+ export class Account {
15
+ wallet;
16
+ constructor(wallet) {
17
+ this.wallet = wallet;
18
+ }
19
+ /** EIP-55 checksummed address. */
20
+ get address() {
21
+ return this.wallet.address;
22
+ }
23
+ /** 0x-prefixed private key. Keep secret. */
24
+ get privateKey() {
25
+ return this.wallet.privateKey;
26
+ }
27
+ /** BIP-39 mnemonic phrase, or null when the account was imported from a raw key. */
28
+ get mnemonic() {
29
+ return "mnemonic" in this.wallet ? (this.wallet.mnemonic?.phrase ?? null) : null;
30
+ }
31
+ /** Generate a fresh random account (returns its mnemonic — back it up). */
32
+ static generate() {
33
+ return new Account(Wallet.createRandom());
34
+ }
35
+ /** Import from a 0x-prefixed (or bare) 32-byte hex private key. */
36
+ static fromPrivateKey(privateKey) {
37
+ const trimmed = privateKey.trim();
38
+ const key = trimmed.startsWith("0x") ? trimmed : `0x${trimmed}`;
39
+ return new Account(new Wallet(key));
40
+ }
41
+ /** Import from a BIP-39 mnemonic phrase. */
42
+ static fromMnemonic(phrase) {
43
+ return new Account(Wallet.fromPhrase(phrase.trim().replace(/\s+/g, " ")));
44
+ }
45
+ /**
46
+ * Sign an arbitrary message with EIP-191 personal-message prefixing
47
+ * ("\x19Ethereum Signed Message:\n" + len + message). This is exactly what
48
+ * core's verifyMessage() expects for transaction signatures — the SDK uses
49
+ * it internally; exposed as an escape hatch for custom/governance flows.
50
+ */
51
+ signMessage(message) {
52
+ return this.wallet.signMessage(message);
53
+ }
54
+ /** Export the key material as a plain object. */
55
+ export() {
56
+ const kp = { address: this.address, privateKey: this.privateKey };
57
+ if (this.mnemonic)
58
+ kp.mnemonic = this.mnemonic;
59
+ return kp;
60
+ }
61
+ }
62
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAY9C;;;GAGG;AACH,MAAM,OAAO,OAAO;IACD,MAAM,CAAwB;IAE/C,YAAoB,MAA6B;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,kCAAkC;IAClC,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC7B,CAAC;IAED,4CAA4C;IAC5C,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;IAChC,CAAC;IAED,oFAAoF;IACpF,IAAI,QAAQ;QACV,OAAO,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnF,CAAC;IAED,2EAA2E;IAC3E,MAAM,CAAC,QAAQ;QACb,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,mEAAmE;IACnE,MAAM,CAAC,cAAc,CAAC,UAAkB;QACtC,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QAClC,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;QAChE,OAAO,IAAI,OAAO,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,4CAA4C;IAC5C,MAAM,CAAC,YAAY,CAAC,MAAc;QAChC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,OAAe;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,iDAAiD;IACjD,MAAM;QACJ,MAAM,EAAE,GAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;QAC3E,IAAI,IAAI,CAAC,QAAQ;YAAE,EAAE,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/C,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
@@ -0,0 +1,148 @@
1
+ /**
2
+ * HTTP client for the Nyontra Dev Portal Backend (gateway).
3
+ *
4
+ * All developer traffic flows through the gateway, which authenticates your
5
+ * project with an API key and applies rate limits before proxying to the
6
+ * Nyontra core network. Writes are authorized by the transaction signature
7
+ * itself; permission-checked reads use the optional X-Nyontra-Requester header.
8
+ *
9
+ * Runs anywhere fetch exists (Node ≥ 18, browsers, workers); a custom fetch
10
+ * implementation can be injected for testing or non-standard runtimes.
11
+ */
12
+ import type { Account } from "./account.js";
13
+ import type { SignedTx } from "./transaction.js";
14
+ /** Default dev-portal backend (gateway) URL. */
15
+ export declare const DEFAULT_GATEWAY_URL = "https://core.nyontra.com";
16
+ export interface NyontraClientOptions {
17
+ /** Dev Portal Backend (gateway) base URL. Defaults to https://core.nyontra.com. */
18
+ gatewayUrl?: string;
19
+ /** Developer API key obtained from the Dev Portal. When set, every request
20
+ * includes an `x-api-key` header so api can authenticate the project
21
+ * and apply rate limits. */
22
+ apiKey?: string;
23
+ /** Requester address sent as X-Nyontra-Requester on reads (self/auditor checks). */
24
+ requester?: string;
25
+ /** Custom fetch (testing / non-standard runtimes). Defaults to globalThis.fetch. */
26
+ fetch?: typeof fetch;
27
+ }
28
+ /** Replication report returned with every successful broadcast. */
29
+ export interface Replication {
30
+ /** True once primary + majority of ready followers applied the tx. */
31
+ quorum: boolean;
32
+ /** Nodes (primary + followers) that applied at response time. */
33
+ acknowledged: number;
34
+ /** Primary + ready followers expected to apply. */
35
+ expected: number;
36
+ /** Follower node ids that failed at response time. */
37
+ failed: string[];
38
+ /** Followers still catching up in the background. */
39
+ pending: number;
40
+ }
41
+ /** Success body of POST /core/v1/tx/broadcast. */
42
+ export interface BroadcastResponse {
43
+ status: "success";
44
+ /** Chain sequence id assigned by the primary (not client-supplied). */
45
+ id: number;
46
+ /** Chain hash (lowercase hex, no 0x prefix). */
47
+ hash: string;
48
+ replication: Replication;
49
+ /** Present (true) when this was an idempotent confirmation of an already-committed tx. */
50
+ idempotent?: boolean;
51
+ }
52
+ /** Account JSON from GET /core/v1/account/:address. */
53
+ export interface AccountJson {
54
+ address: string;
55
+ name: string | null;
56
+ balance: number;
57
+ /** Permission bitmask (MANAGE_ROLES=1, MINT=2, SET_PRICE=4, API=8, ESCROW_SIGN=16, VIEW_ALL_HISTORY=64, VALIDATOR=256). */
58
+ permissions: number;
59
+ /** Current account nonce — use as the `nonce` of the next transaction. */
60
+ nonce: number;
61
+ history: unknown[];
62
+ }
63
+ /** TxLog from history/explorer/tx-status endpoints. */
64
+ export interface TxLog {
65
+ hash: string;
66
+ type: string;
67
+ from: string;
68
+ to: string;
69
+ amount: number;
70
+ payload: string;
71
+ data?: unknown;
72
+ /** Unix seconds (chain event time). */
73
+ timestamp: number;
74
+ }
75
+ /** GET /core/v1/tx/status/:hash response. */
76
+ export interface TxStatusResponse {
77
+ hash: string;
78
+ status: "confirmed" | "not_found";
79
+ data?: TxLog;
80
+ }
81
+ /** GET /core/v1/block/current response. */
82
+ export interface BlockInfo {
83
+ height: number;
84
+ hash: string;
85
+ /** Unix seconds. */
86
+ time: number;
87
+ }
88
+ /** Error thrown for any non-2xx gateway response. */
89
+ export declare class NyontraApiError extends Error {
90
+ /** HTTP status code (400 structural, 403 auth/state, 409 retryable race, 501 unknown type). */
91
+ readonly status: number;
92
+ /** Parsed response body: {error: "..."} JSON or raw text. */
93
+ readonly body: unknown;
94
+ constructor(status: number, body: unknown, message?: string);
95
+ }
96
+ export declare class NyontraClient {
97
+ readonly gatewayUrl: string;
98
+ private readonly apiKey?;
99
+ private readonly requester?;
100
+ private readonly fetchFn;
101
+ constructor(options?: NyontraClientOptions | string);
102
+ /** GET /core/v1/health — plain-text liveness probe. */
103
+ getHealth(): Promise<string>;
104
+ /** GET /core/v1/block/current — latest chain tip {height, hash, time}. */
105
+ getBlockCurrent(): Promise<BlockInfo>;
106
+ /** GET /core/v1/account/:address — account state incl. nonce (public). */
107
+ getAccount(address: string): Promise<AccountJson>;
108
+ /** GET /core/v1/balance/:address — {balance} (public). */
109
+ getBalance(address: string): Promise<number>;
110
+ /**
111
+ * Current nonce for `address` — the value your next transaction must carry.
112
+ * Unknown/unfunded addresses report nonce 0.
113
+ */
114
+ getNonce(address: string): Promise<number>;
115
+ /** GET /core/v1/tx/status/:hash — confirmed tx or not_found. */
116
+ getTxStatus(hash: string): Promise<TxStatusResponse>;
117
+ /**
118
+ * GET /core/v1/history/:address — sender/recipient history.
119
+ * Requires X-Nyontra-Requester: self lookup, or an address with
120
+ * VIEW_ALL_HISTORY (64). Set `requester` on the client (or pass `as`).
121
+ */
122
+ getHistory(address: string, options?: {
123
+ limit?: number;
124
+ as?: string;
125
+ }): Promise<TxLog[]>;
126
+ /**
127
+ * POST /core/v1/tx/broadcast — submit a pre-signed transaction.
128
+ * Retrying the identical signed tx is safe: (sender, nonce) is idempotent.
129
+ */
130
+ broadcast(tx: SignedTx): Promise<BroadcastResponse>;
131
+ /**
132
+ * End-to-end transfer: fetch the current nonce (unless given), sign locally,
133
+ * and broadcast. Throws NyontraApiError on rejection — e.g. status 403 with
134
+ * "nonce mismatch" means a concurrent tx took the slot; retry the call.
135
+ */
136
+ transfer(account: Account, input: {
137
+ to: string;
138
+ amount: number | string;
139
+ data?: unknown;
140
+ /** Override the nonce (otherwise fetched via GET /core/v1/account/:address). */
141
+ nonce?: number;
142
+ }): Promise<BroadcastResponse>;
143
+ /** Fetch + throw NyontraApiError on non-2xx; returns raw text. */
144
+ private text;
145
+ /** Fetch and JSON-parse; gateway error bodies may be JSON or plain text. */
146
+ private json;
147
+ }
148
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGjD,gDAAgD;AAChD,eAAO,MAAM,mBAAmB,6BAA6B,CAAC;AAE9D,MAAM,WAAW,oBAAoB;IACnC,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;iCAE6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,mEAAmE;AACnE,MAAM,W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,CAAC,KAAK,EAAE,CAAC;IAa5F;;;OAGG;IACH,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC;IASnD;;;;OAIG;IACG,QAAQ,CACZ,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE;QACL,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;QACxB,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,gFAAgF;QAChF,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GACA,OAAO,CAAC,iBAAiB,CAAC;IAe7B,kEAAkE;YACpD,IAAI;IAkBlB,4EAA4E;YAC9D,IAAI;CAcnB"}
package/dist/client.js ADDED
@@ -0,0 +1,151 @@
1
+ /**
2
+ * HTTP client for the Nyontra Dev Portal Backend (gateway).
3
+ *
4
+ * All developer traffic flows through the gateway, which authenticates your
5
+ * project with an API key and applies rate limits before proxying to the
6
+ * Nyontra core network. Writes are authorized by the transaction signature
7
+ * itself; permission-checked reads use the optional X-Nyontra-Requester header.
8
+ *
9
+ * Runs anywhere fetch exists (Node ≥ 18, browsers, workers); a custom fetch
10
+ * implementation can be injected for testing or non-standard runtimes.
11
+ */
12
+ import { signTx } from "./transaction.js";
13
+ /** Default dev-portal backend (gateway) URL. */
14
+ export const DEFAULT_GATEWAY_URL = "https://core.nyontra.com";
15
+ /** Error thrown for any non-2xx gateway response. */
16
+ export class NyontraApiError extends Error {
17
+ /** HTTP status code (400 structural, 403 auth/state, 409 retryable race, 501 unknown type). */
18
+ status;
19
+ /** Parsed response body: {error: "..."} JSON or raw text. */
20
+ body;
21
+ constructor(status, body, message) {
22
+ const msg = message ??
23
+ (typeof body === "object" && body !== null && "error" in body
24
+ ? String(body.error)
25
+ : String(body));
26
+ super(`Nyontra gateway error ${status}: ${msg}`);
27
+ this.name = "NyontraApiError";
28
+ this.status = status;
29
+ this.body = body;
30
+ }
31
+ }
32
+ export class NyontraClient {
33
+ gatewayUrl;
34
+ apiKey;
35
+ requester;
36
+ fetchFn;
37
+ constructor(options = {}) {
38
+ const opts = typeof options === "string" ? { gatewayUrl: options } : options;
39
+ this.gatewayUrl = (opts.gatewayUrl ?? DEFAULT_GATEWAY_URL).replace(/\/+$/, "");
40
+ this.apiKey = opts.apiKey;
41
+ this.requester = opts.requester;
42
+ this.fetchFn = opts.fetch ?? globalThis.fetch?.bind(globalThis);
43
+ if (!this.fetchFn) {
44
+ throw new Error("No fetch implementation available — pass one via { fetch }");
45
+ }
46
+ }
47
+ // ---------------------------------------------------------------- reads
48
+ /** GET /core/v1/health — plain-text liveness probe. */
49
+ async getHealth() {
50
+ return this.text("/core/v1/health", "GET");
51
+ }
52
+ /** GET /core/v1/block/current — latest chain tip {height, hash, time}. */
53
+ getBlockCurrent() {
54
+ return this.json("/core/v1/block/current", "GET");
55
+ }
56
+ /** GET /core/v1/account/:address — account state incl. nonce (public). */
57
+ getAccount(address) {
58
+ return this.json(`/core/v1/account/${encodeURIComponent(address.toLowerCase())}`, "GET");
59
+ }
60
+ /** GET /core/v1/balance/:address — {balance} (public). */
61
+ async getBalance(address) {
62
+ const res = await this.json(`/core/v1/balance/${encodeURIComponent(address.toLowerCase())}`, "GET");
63
+ return res.balance;
64
+ }
65
+ /**
66
+ * Current nonce for `address` — the value your next transaction must carry.
67
+ * Unknown/unfunded addresses report nonce 0.
68
+ */
69
+ async getNonce(address) {
70
+ return (await this.getAccount(address)).nonce;
71
+ }
72
+ /** GET /core/v1/tx/status/:hash — confirmed tx or not_found. */
73
+ getTxStatus(hash) {
74
+ return this.json(`/core/v1/tx/status/${encodeURIComponent(hash)}`, "GET");
75
+ }
76
+ /**
77
+ * GET /core/v1/history/:address — sender/recipient history.
78
+ * Requires X-Nyontra-Requester: self lookup, or an address with
79
+ * VIEW_ALL_HISTORY (64). Set `requester` on the client (or pass `as`).
80
+ */
81
+ getHistory(address, options = {}) {
82
+ const params = new URLSearchParams();
83
+ if (options.limit !== undefined)
84
+ params.set("limit", String(options.limit));
85
+ const qs = params.toString();
86
+ return this.json(`/core/v1/history/${encodeURIComponent(address.toLowerCase())}${qs ? `?${qs}` : ""}`, "GET", options.as ?? this.requester);
87
+ }
88
+ // --------------------------------------------------------------- writes
89
+ /**
90
+ * POST /core/v1/tx/broadcast — submit a pre-signed transaction.
91
+ * Retrying the identical signed tx is safe: (sender, nonce) is idempotent.
92
+ */
93
+ broadcast(tx) {
94
+ return this.json("/core/v1/tx/broadcast", "POST", undefined, JSON.stringify(tx));
95
+ }
96
+ /**
97
+ * End-to-end transfer: fetch the current nonce (unless given), sign locally,
98
+ * and broadcast. Throws NyontraApiError on rejection — e.g. status 403 with
99
+ * "nonce mismatch" means a concurrent tx took the slot; retry the call.
100
+ */
101
+ async transfer(account, input) {
102
+ const nonce = input.nonce ?? (await this.getNonce(account.address));
103
+ const signed = await signTx(account, {
104
+ type: "TRANSFER",
105
+ from: account.address,
106
+ to: input.to,
107
+ amount: input.amount,
108
+ nonce,
109
+ data: input.data,
110
+ });
111
+ return this.broadcast(signed);
112
+ }
113
+ // -------------------------------------------------------------- private
114
+ /** Fetch + throw NyontraApiError on non-2xx; returns raw text. */
115
+ async text(path, method, requester, body) {
116
+ const headers = {};
117
+ if (body !== undefined)
118
+ headers["Content-Type"] = "application/json";
119
+ if (this.apiKey)
120
+ headers["x-api-key"] = this.apiKey;
121
+ const req = requester ?? this.requester;
122
+ if (req)
123
+ headers["X-Nyontra-Requester"] = req;
124
+ const res = await this.fetchFn(`${this.gatewayUrl}${path}`, { method, headers, body });
125
+ const text = await res.text();
126
+ if (!res.ok)
127
+ throw new NyontraApiError(res.status, parseBody(text));
128
+ return text;
129
+ }
130
+ /** Fetch and JSON-parse; gateway error bodies may be JSON or plain text. */
131
+ async json(path, method, requester, body) {
132
+ const text = await this.text(path, method, requester, body);
133
+ if (text === "")
134
+ return undefined;
135
+ try {
136
+ return JSON.parse(text);
137
+ }
138
+ catch {
139
+ return text;
140
+ }
141
+ }
142
+ }
143
+ function parseBody(text) {
144
+ try {
145
+ return JSON.parse(text);
146
+ }
147
+ catch {
148
+ return text;
149
+ }
150
+ }
151
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,gDAAgD;AAChD,MAAM,CAAC,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AAiF9D,qDAAqD;AACrD,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,+FAA+F;IACtF,MAAM,CAAS;IACxB,6DAA6D;IACpD,IAAI,CAAU;IAEvB,YAAY,MAAc,EAAE,IAAa,EAAE,OAAgB;QACzD,MAAM,GAAG,GACP,OAAO;YACP,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,IAAI;gBAC3D,CAAC,CAAC,MAAM,CAAE,IAA2B,CAAC,KAAK,CAAC;gBAC5C,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACpB,KAAK,CAAC,yBAAyB,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AACD,MAAM,OAAO,aAAa;IACf,UAAU,CAAS;IACX,MAAM,CAAU;IAChB,SAAS,CAAU;IACnB,OAAO,CAAe;IAEvC,YAAY,UAAyC,EAAE;QACrD,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QAC7E,IAAI,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,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,CAAC,IAAI,CAAM,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAoB,CAAC;QAC9B,CAAC;IACH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @nyontra/sdk — official Nyontra JavaScript/TypeScript SDK.
3
+ *
4
+ * Local secp256k1 key management + canonical transaction signing (byte-exact
5
+ * parity with the core chain signer) + HTTP client for the public gateway
6
+ * at https://core.nyontra.com.
7
+ */
8
+ export { Account, type Keypair } from "./account.js";
9
+ export { buildSignMessage, canonicalData, type SignableTx, } from "./signing.js";
10
+ export { buildTransferTx, signTx, MAX_DATA_CANONICAL_LENGTH, TX_TYPES, type CoreTxType, type SignedTx, type TxInput, } from "./transaction.js";
11
+ export { DEFAULT_GATEWAY_URL, NyontraApiError, NyontraClient, type AccountJson, type BlockInfo, type BroadcastResponse, type NyontraClientOptions, type Replication, type TxLog, type TxStatusResponse, } from "./client.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,KAAK,UAAU,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,MAAM,EACN,yBAAyB,EACzB,QAAQ,EACR,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,OAAO,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @nyontra/sdk — official Nyontra JavaScript/TypeScript SDK.
3
+ *
4
+ * Local secp256k1 key management + canonical transaction signing (byte-exact
5
+ * parity with the core chain signer) + HTTP client for the public gateway
6
+ * at https://core.nyontra.com.
7
+ */
8
+ export { Account } from "./account.js";
9
+ export { buildSignMessage, canonicalData, } from "./signing.js";
10
+ export { buildTransferTx, signTx, MAX_DATA_CANONICAL_LENGTH, TX_TYPES, } from "./transaction.js";
11
+ export { DEFAULT_GATEWAY_URL, NyontraApiError, NyontraClient, } from "./client.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAgB,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,gBAAgB,EAChB,aAAa,GAEd,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,MAAM,EACN,yBAAyB,EACzB,QAAQ,GAIT,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,aAAa,GAQd,MAAM,aAAa,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Canonical message builder — EXACT mirror of the core chain signer:
3
+ * core/src/lib/signature.ts (buildSignMessage)
4
+ * core/src/lib/hash.ts (canonicalData / stableStringify)
5
+ *
6
+ * The signature this SDK produces MUST byte-for-byte match the string core
7
+ * reconstructs before verifying (viem verifyMessage = EIP-191), or every tx
8
+ * is rejected with 403 "signature verification failed".
9
+ *
10
+ * Message formats (all address parts lowercased, colon-separated):
11
+ * UPDATE_NAME: "{from}:{payload}:{nonce}:{data}"
12
+ * TRANSFER / SET_PERMISSIONS: "{from}:{to}:{amount}:{nonce}:{data}"
13
+ * default (governance family): "{from}:{type}:{payload}:{nonce}:{data}"
14
+ *
15
+ * `data` is the deterministic canonical JSON of the optional memo field
16
+ * ("" when absent/null), matching the hash chain so the sender commits to it.
17
+ */
18
+ /** Minimal tx shape needed to build the canonical message. */
19
+ export interface SignableTx {
20
+ type: string;
21
+ from: string;
22
+ to?: string;
23
+ amount?: number | string;
24
+ payload?: string;
25
+ nonce: number;
26
+ /** Optional developer memo/metadata (any JSON value). */
27
+ data?: unknown;
28
+ }
29
+ /** Deterministic canonical serialization of the optional `data` field ("": absent). */
30
+ export declare function canonicalData(value: unknown): string;
31
+ /** Build the exact message core verifies for a given transaction. */
32
+ export declare function buildSignMessage(tx: SignableTx): string;
33
+ //# sourceMappingURL=signing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,8DAA8D;AAC9D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAsBD,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGpD;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,UAAU,GAAG,MAAM,CAgBvD"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Canonical message builder — EXACT mirror of the core chain signer:
3
+ * core/src/lib/signature.ts (buildSignMessage)
4
+ * core/src/lib/hash.ts (canonicalData / stableStringify)
5
+ *
6
+ * The signature this SDK produces MUST byte-for-byte match the string core
7
+ * reconstructs before verifying (viem verifyMessage = EIP-191), or every tx
8
+ * is rejected with 403 "signature verification failed".
9
+ *
10
+ * Message formats (all address parts lowercased, colon-separated):
11
+ * UPDATE_NAME: "{from}:{payload}:{nonce}:{data}"
12
+ * TRANSFER / SET_PERMISSIONS: "{from}:{to}:{amount}:{nonce}:{data}"
13
+ * default (governance family): "{from}:{type}:{payload}:{nonce}:{data}"
14
+ *
15
+ * `data` is the deterministic canonical JSON of the optional memo field
16
+ * ("" when absent/null), matching the hash chain so the sender commits to it.
17
+ */
18
+ /**
19
+ * Deterministic JSON serialization: object keys sorted recursively, arrays in
20
+ * order, strings JSON-escaped, non-finite numbers → "null".
21
+ */
22
+ function stableStringify(value) {
23
+ if (value === null)
24
+ return "null";
25
+ if (typeof value === "number") {
26
+ return Number.isFinite(value) ? JSON.stringify(value) : "null";
27
+ }
28
+ if (typeof value === "boolean")
29
+ return value ? "true" : "false";
30
+ if (typeof value === "string")
31
+ return JSON.stringify(value);
32
+ if (Array.isArray(value))
33
+ return `[${value.map(stableStringify).join(",")}]`;
34
+ if (typeof value === "object") {
35
+ const obj = value;
36
+ const keys = Object.keys(obj).sort();
37
+ return `{${keys.map((k) => `${JSON.stringify(k)}:${stableStringify(obj[k])}`).join(",")}}`;
38
+ }
39
+ return "null";
40
+ }
41
+ /** Deterministic canonical serialization of the optional `data` field ("": absent). */
42
+ export function canonicalData(value) {
43
+ if (value === undefined || value === null)
44
+ return "";
45
+ return stableStringify(value);
46
+ }
47
+ /** Build the exact message core verifies for a given transaction. */
48
+ export function buildSignMessage(tx) {
49
+ const from = String(tx.from || "").toLowerCase();
50
+ const type = String(tx.type || "").toUpperCase();
51
+ const payload = tx.payload ?? "";
52
+ const nonce = tx.nonce ?? 0;
53
+ const data = canonicalData(tx.data);
54
+ switch (type) {
55
+ case "UPDATE_NAME":
56
+ return `${from}:${payload}:${nonce}:${data}`;
57
+ case "TRANSFER":
58
+ case "SET_PERMISSIONS":
59
+ return `${from}:${String(tx.to ?? "").toLowerCase()}:${tx.amount ?? 0}:${nonce}:${data}`;
60
+ default:
61
+ return `${from}:${type}:${payload}:${nonce}:${data}`;
62
+ }
63
+ }
64
+ //# sourceMappingURL=signing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signing.js","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAcH;;;GAGG;AACH,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACjE,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAChE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC5D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC7E,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,KAAgC,CAAC;QAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACrC,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,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 @@
1
+ /**
2
+ * Transaction construction + signing.
3
+ *
4
+ * A signed tx is the flat JSON object POSTed to /core/v1/tx/broadcast:
5
+ * { type, from, to, amount, payload, data, nonce, signature, timestamp }
6
+ *
7
+ * The signature covers the canonical message (see signing.ts) — NOT the JSON
8
+ * body — so field order on the wire is irrelevant, but every value that
9
+ * participates in the message (from, to, amount, nonce, data) must be signed
10
+ * exactly as sent. `timestamp` is informational only (not signed, not
11
+ * enforced by core), matching the wallet's wire format.
12
+ */
13
+ import type { Account } from "./account.js";
14
+ /** Mirrors core/src/lib/types.ts MAX_DATA_CANONICAL_LENGTH. */
15
+ export declare const MAX_DATA_CANONICAL_LENGTH = 256;
16
+ /** Core transaction types (non-governance). Governance types use the default signer format. */
17
+ export declare const TX_TYPES: readonly ["TRANSFER", "UPDATE_NAME", "SET_PERMISSIONS"];
18
+ export type CoreTxType = (typeof TX_TYPES)[number];
19
+ /** Unsigned transaction input. */
20
+ export interface TxInput {
21
+ /** One of TX_TYPES, or a governance type (PROPOSE_MINT, VOTE_PROPOSAL, ...). */
22
+ type: string;
23
+ /** Sender address. Defaults to the signing account's address. */
24
+ from?: string;
25
+ /** Recipient (required for TRANSFER / SET_PERMISSIONS; set to sender for UPDATE_NAME). */
26
+ to?: string;
27
+ /** Non-negative integer amount (number or decimal string). Required for TRANSFER. */
28
+ amount?: number | string;
29
+ /** Free-form string payload (e.g. new display name for UPDATE_NAME, vote choice for VOTE_PROPOSAL). */
30
+ payload?: string;
31
+ /**
32
+ * Next account nonce (the account's current nonce from
33
+ * GET /core/v1/account/:address). Must be exact — see client.transfer()
34
+ * which fetches it for you.
35
+ */
36
+ nonce: number;
37
+ /** Optional developer memo/metadata — any JSON value, ≤ 256 chars canonical. Hashed into the chain. */
38
+ data?: unknown;
39
+ }
40
+ /** Signed transaction — wire format accepted by POST /core/v1/tx/broadcast. */
41
+ export interface SignedTx {
42
+ type: string;
43
+ from: string;
44
+ to: string;
45
+ amount: number | string;
46
+ payload: string;
47
+ data: unknown;
48
+ nonce: number;
49
+ signature: string;
50
+ /** Informational only — not part of the signature; core ignores it. */
51
+ timestamp: number;
52
+ }
53
+ /** Build an unsigned TRANSFER input. */
54
+ export declare function buildTransferTx(input: {
55
+ to: string;
56
+ amount: number | string;
57
+ nonce: number;
58
+ from?: string;
59
+ data?: unknown;
60
+ }): TxInput;
61
+ /**
62
+ * Sign a transaction with the given account. Validates structure client-side
63
+ * (address format, integer amount, nonce, memo size) so obvious mistakes fail
64
+ * fast with a clear message instead of a 400/403 from the gateway.
65
+ */
66
+ export declare function signTx(account: Account, tx: TxInput): Promise<SignedTx>;
67
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,+DAA+D;AAC/D,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAE7C,+FAA+F;AAC/F,eAAO,MAAM,QAAQ,yDAA0D,CAAC;AAChF,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD,kCAAkC;AAClC,MAAM,WAAW,OAAO;IACtB,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0FAA0F;IAC1F,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,uGAAuG;IACvG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,uGAAuG;IACvG,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,+EAA+E;AAC/E,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wCAAwC;AACxC,wBAAgB,eAAe,CAAC,KAAK,EAAE;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,GAAG,OAAO,CASV;AAwBD;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0D7E"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Transaction construction + signing.
3
+ *
4
+ * A signed tx is the flat JSON object POSTed to /core/v1/tx/broadcast:
5
+ * { type, from, to, amount, payload, data, nonce, signature, timestamp }
6
+ *
7
+ * The signature covers the canonical message (see signing.ts) — NOT the JSON
8
+ * body — so field order on the wire is irrelevant, but every value that
9
+ * participates in the message (from, to, amount, nonce, data) must be signed
10
+ * exactly as sent. `timestamp` is informational only (not signed, not
11
+ * enforced by core), matching the wallet's wire format.
12
+ */
13
+ import { buildSignMessage, canonicalData } from "./signing.js";
14
+ /** Mirrors core/src/lib/types.ts MAX_DATA_CANONICAL_LENGTH. */
15
+ export const MAX_DATA_CANONICAL_LENGTH = 256;
16
+ /** Core transaction types (non-governance). Governance types use the default signer format. */
17
+ export const TX_TYPES = ["TRANSFER", "UPDATE_NAME", "SET_PERMISSIONS"];
18
+ /** Build an unsigned TRANSFER input. */
19
+ export function buildTransferTx(input) {
20
+ return {
21
+ type: "TRANSFER",
22
+ from: input.from,
23
+ to: input.to,
24
+ amount: input.amount,
25
+ nonce: input.nonce,
26
+ data: input.data,
27
+ };
28
+ }
29
+ const ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
30
+ function assertAddress(value, field) {
31
+ if (!ADDRESS_RE.test(value)) {
32
+ throw new Error(`${field} must be a 0x-prefixed 20-byte hex address (got "${value}")`);
33
+ }
34
+ }
35
+ function assertAmount(amount, required) {
36
+ if (amount === undefined || amount === null) {
37
+ if (required)
38
+ throw new Error("amount is required for TRANSFER transactions");
39
+ return;
40
+ }
41
+ const ok = typeof amount === "number"
42
+ ? Number.isSafeInteger(amount) && amount >= 0
43
+ : /^\d+$/.test(amount);
44
+ if (!ok) {
45
+ throw new Error(`amount must be a non-negative integer (got ${JSON.stringify(amount)})`);
46
+ }
47
+ }
48
+ /**
49
+ * Sign a transaction with the given account. Validates structure client-side
50
+ * (address format, integer amount, nonce, memo size) so obvious mistakes fail
51
+ * fast with a clear message instead of a 400/403 from the gateway.
52
+ */
53
+ export async function signTx(account, tx) {
54
+ const type = String(tx.type || "").toUpperCase();
55
+ if (!type)
56
+ throw new Error("type is required");
57
+ const from = (tx.from ?? account.address).toLowerCase();
58
+ assertAddress(from, "from");
59
+ if (from !== account.address.toLowerCase()) {
60
+ throw new Error(`from (${from}) does not match the signing account (${account.address.toLowerCase()})`);
61
+ }
62
+ const nonce = tx.nonce;
63
+ if (!Number.isSafeInteger(nonce) || nonce < 0) {
64
+ throw new Error(`nonce must be a non-negative integer (got ${JSON.stringify(tx.nonce)})`);
65
+ }
66
+ assertAmount(tx.amount, type === "TRANSFER");
67
+ let to = (tx.to ?? "").toLowerCase();
68
+ if (type === "UPDATE_NAME") {
69
+ to = from; // wallet parity: UPDATE_NAME sets recipient to the sender
70
+ }
71
+ else if ((type === "TRANSFER" || type === "SET_PERMISSIONS") && !to) {
72
+ throw new Error(`to is required for ${type} transactions`);
73
+ }
74
+ if (to)
75
+ assertAddress(to, "to");
76
+ if (tx.data !== undefined && tx.data !== null) {
77
+ const len = canonicalData(tx.data).length;
78
+ if (len > MAX_DATA_CANONICAL_LENGTH) {
79
+ throw new Error(`data exceeds ${MAX_DATA_CANONICAL_LENGTH} characters (canonical length ${len})`);
80
+ }
81
+ }
82
+ const message = buildSignMessage({
83
+ type,
84
+ from,
85
+ to,
86
+ amount: tx.amount ?? 0,
87
+ payload: tx.payload,
88
+ nonce,
89
+ data: tx.data,
90
+ });
91
+ const signature = await account.signMessage(message);
92
+ return {
93
+ type,
94
+ from,
95
+ to,
96
+ amount: tx.amount ?? 0,
97
+ payload: tx.payload ?? "",
98
+ data: tx.data ?? null,
99
+ nonce,
100
+ signature,
101
+ timestamp: Math.floor(Date.now() / 1000),
102
+ };
103
+ }
104
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE/D,+DAA+D;AAC/D,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAE7C,+FAA+F;AAC/F,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,UAAU,EAAE,aAAa,EAAE,iBAAiB,CAAU,CAAC;AAuChF,wCAAwC;AACxC,MAAM,UAAU,eAAe,CAAC,KAM/B;IACC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAG,qBAAqB,CAAC;AAEzC,SAAS,aAAa,CAAC,KAAa,EAAE,KAAa;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EAAE,CAAC,MAAM,IAAI,CAAC;QACtB,OAAO,EAAE,EAAE,CAAC,OAAO;QACnB,KAAK;QACL,IAAI,EAAE,EAAE,CAAC,IAAI;KACd,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAErD,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,EAAE;QACF,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,CAAC;QACtB,OAAO,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE;QACzB,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI;QACrB,KAAK;QACL,SAAS;QACT,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;KACzC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
- {
2
- "name": "@nyontra/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@nyontra/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Official Nyontra JavaScript/TypeScript SDK — local secp256k1 key management, canonical transaction signing, and an HTTP client for the core.nyontra.com gateway",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "sideEffects": false,
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "typecheck": "tsc --noEmit",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest"
25
+ },
26
+ "keywords": [
27
+ "nyontra",
28
+ "ledger",
29
+ "sdk",
30
+ "signing"
31
+ ],
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/nyontra/sdk.git",
36
+ "directory": "js"
37
+ },
38
+ "homepage": "https://github.com/nyontra/sdk#readme",
39
+ "bugs": {
40
+ "url": "https://github.com/nyontra/sdk/issues"
41
+ },
42
+ "engines": {
43
+ "node": ">=18"
44
+ },
45
+ "dependencies": {
46
+ "ethers": "^6.13.4"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^24.0.0",
50
+ "typescript": "^5.9.2",
51
+ "viem": "^2.57.5",
52
+ "vitest": "^4.1.12"
53
+ }
54
+ }