# @sourceless/sdk — the SourceLess client SDK for JavaScript Key derivation, addresses, canonical encoding, record signing and the JSON-RPC transport for a SourceLess node. **Zero runtime dependencies. Runs in Node 18+ and in the browser.** **Self-custody by construction: no method here sends a private key anywhere.** > Proprietary. Copyright (c) 2026 **Alexandru Marius Stratulat and the SourceLess team**. > All rights reserved — see [`LICENSE`](LICENSE), which travels inside this package. ## Ten lines Read first. This needs no key and no account. `expectGenesisHashHex` is Asgard's whole genesis hash, the one its realm record pins (`src/core/snotra.ts`), and `network()`, `chainId()` and signing refuse a node on any other chain. A read does not check, so a program that only reads must call `network()` first, as this one does. A shortened hash matches nothing, so copy all 64 characters. ```js import { Client } from '@sourceless/sdk'; const node = new Client('https://rpc.xplstr.org', { expectGenesisHashHex: '1cf8655125cc1bbbc0ca06a491f53775499785c349b4d0f5748d5ea170e517bf', }); await node.network(); // stops here unless the node is on that chain console.log(await node.chainId()); console.log(await node.height()); console.log(await node.domainHolder('STR.sourceless')); // an address, or null ``` Then sign. `phrase` is the account's recovery words, taken from wherever your program keeps its secrets. Never write them into the source. These lines sign on this machine and post finished records. ```js import { crypto } from '@sourceless/sdk'; const keys = await crypto.accountKeypairFromMnemonic(phrase); // More accounts from the same words: accountKeypairFromMnemonic(phrase, '', n). Account 0 is the default. console.log(keys.address, await node.balances(keys.address)); await node.claimDomain(keys, 'STR.yourname'); // reserves the name; costs and locks nothing await node.proveDomain(keys, 'STR.yourname'); // locks 1,000 STR and mints the wNFT // Send once node.domainOf(keys.address) answers STR.yourname: a block has carried the proof. // send() refuses an unnamed sender holding 1,000 STR, which the chain would name. The check is // advisory (one node's read; a credit landing before the seal can still lock the 1,000 STR). await node.send(keys, { to: 'zk13str_…', amountMinor: 1_000n }); ``` `send`, `claimDomain`, `proveDomain`, `rotateKey`, `grantDelegation`, `delegatedSpend`, `authorizedCall` and `authorizedDeploy` all sign **locally** and post the finished record. There is no method that takes a key and asks the node to do the rest, because in a browser that method is not a convenience — it is a custodial product wearing a self-custody label. `expectGenesisHashHex` covers `chainBinding` and `identityChainBinding` too, and plain `http://` is refused for anything but this machine unless `allowInsecureHttp: true` is passed. A failed write whose outcome is unknown rejects with `OutcomeUnknown` carrying the signed `record`: re-post it with `submitTransactionOnce`, never by calling `send` again. See `sdk/README.md` §3.5 and §3.6. **The first spend of an unnamed account can name it.** An account with no proved STR.domain and at least 1,000 STR available may spend, and the block that carries the transfer locks 1,000 STR and gives the account a name the chain generates. An account holds one proved name, so that name stands where a chosen one would. `send` asks `domainOf` first and refuses to sign such a transfer, saying so, unless `acceptDerivedName: true` is passed; claim and prove the name you want first, and send once `domainOf` answers it. The check is advisory: it rests on one node's reads, and a credit that lands between the read and the seal can still lock 1,000 STR and name the account. Only a name proved before the spend rules that out. ## Zero dependencies, and that was not luck Everything this needs is in **WebCrypto**: Ed25519, PBKDF2-HMAC-SHA512, HKDF-SHA256 and SHA-256. The transport is `fetch`. The usual answer — a curve library — would have been a dependency in a tree whose whole point is that it has none, and it turned out not to be needed. Three consequences, all stated here rather than discovered later: - **Every derivation is asynchronous**, including `deriveAddress`. `crypto.subtle` returns promises; that is the shape of having no dependencies. - **Ed25519 in WebCrypto needs Chrome 137+, Safari 17+, Firefox 129+ or Node 18+.** Call `await crypto.assertCryptoAvailable()` at start-up and anything older refuses **by name**, up front — rather than letting a holder write down a phrase, fund it, and then discover the page cannot sign. - **Supporting Ed25519 is not the same as exporting a private key as JWK**, which is how the public key is read. Playwright Firefox 141 refuses that export (measured 2026-11-17), so `publicKeyHexFromPrivate` computes the public key from the seed when the export is refused (`ed25519PublicKeyFromSeed`, RFC 8032 §5.1.5). Either way the key must verify a signature the engine made with the private key before it is returned: one sign and one verify per keypair. ## An amount is a `bigint`, and a number is refused ```js await node.send(keys, { to, amountMinor: 1_000n }); // correct await node.send(keys, { to, amountMinor: 1000 }); // throws: amountMinor must be a bigint ``` Not pedantry. `canonicalStringify` renders a `bigint` as the decimal string `"1000"` and a `number` as `1000`, and that string is what gets signed — so accepting a number would produce a payload that differs from the chain's in the one field that carries money. Coercing silently would also let `1e21` through as a rounded amount. ## Following the chain ```js const follower = new BlockFollower(node, { fromHeight: 0 }); for await (const block of follower.blocks({ follow: true })) { console.log(block.header.height, block.transactions.length); } ``` `follower.nextHeight` is a `bigint` a caller can store and hand back: an indexer that crashes must resume from what it **committed**, not from whatever this object happened to hold. The parent hash of every block is checked, so a chain that reorganises under the cursor throws `ReorganisationDetected` instead of quietly writing a ledger from two histories. Needs `blockRange`, which is one of the four block reads added to the chain in September 2026. A node started before they landed throws `MethodNotFound` carrying the list of verbs it **does** publish, rather than reporting the chain as empty. ## In a bundler, and in a browser `"type": "module"`, `"sideEffects": false`, subpath exports for `crypto`, `records`, `client` and `follower` — so a page that only derives an address does not ship the transport. No Node built-in is imported anywhere in `src/`; `fetch`, `crypto`, `TextEncoder` and `atob` are the whole platform surface, and `Buffer` is reached for only as a named fallback where `atob` is absent. `Client` takes `{ fetch }` for two honest reasons: a test should not need a socket, and a page inside an extension may have to route through its own. ## Correctness Every derivation, encoding and payload here is checked against `spec/conformance-vectors.json`, generated from the implementation the chain itself runs — never against this library's own output, because a client tested only against itself agrees with its own bugs and both failures that causes are silent: an address derived one bit differently shows an empty wallet, and a payload canonicalised differently produces *"invalid signature"* about a transaction signed correctly. ```sh node --test "test/**/*.test.mjs" # every test, no network; the run prints the count node test/report.mjs # 98 conformance vectors, one line each node ../conformance-report.mjs # both clients, per vector AND against each other node test/live.mjs http://127.0.0.1:8083 # opt-in, needs a node ``` `test/report.mjs` walks the vector file itself rather than counting test functions, so a failure names the vector, the expectation and the value this client produced. `../conformance-report.mjs` runs the Python client over the same ids and compares the two byte for byte: agreeing with the vectors and agreeing with each other are two different questions, and the second is what catches a value no vector pins. `../README.md` states what this SDK cannot do and why — a Gemini (post-quantum) record, an AresLang compilation, fourteen record kinds that have no vector yet, and a v2 address. ## Versioning **The two SDKs carry the SAME version number on purpose.** `@sourceless/sdk` and `sourceless` implement one protocol surface — the same addresses, the same canonical encoding, the same record signatures, checked against the same `spec/conformance-vectors.json` — so a reader holding one of each has to be able to tell at a glance whether they agree. They were 0.1.0 and 0.3.0, which answers that question with a number that means nothing. The version tracks the protocol surface, not the repository: `package.json` at the root is a different artifact with a different life, and a match between them would be a coincidence rather than a promise. A client that reproduces every vector in `spec/conformance-vectors.json` is compatible. One that does not is wrong in a way its own tests cannot see, which is why the vectors are generated by the implementation the chain actually runs and not written by hand.