@sorandomains/owner 0.2.0 → 0.3.1

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/README.md CHANGED
@@ -34,11 +34,12 @@ for (const o of batch.outcomes) if (!o.issued) console.warn(o.label, o.reason);
34
34
  | `makePermanent` | The one-way door — irreversible, guarded by `{ confirmIrreversible: true }` |
35
35
  | `proposeNamespaceTransfer` / `acceptNamespaceTransfer` / `cancelNamespaceTransfer` | Two-step, accept-to-move namespace transfer |
36
36
  | `setResolver` | Point the namespace at a resolver (frozen once permanent) |
37
- | `policy` / `isPermanent` / `nameState` / `pendingNamespaceTransfer` / `namespaceOwner` | Reads that support the write flows |
37
+ | `policy` / `isPermanent` / `nameState` / `pendingNamespaceTransfer` / `namespaceOwner` / `registrarOf` / `assertOwner` | Reads that support the write flows |
38
38
 
39
39
  Name-**holder** powers (transferring an individual name, re-pointing it,
40
40
  electing a primary name) are deliberately absent: the contracts grant them to
41
- holders, not owners, and they will ship in a holder-side module.
41
+ holders, not owners — they live in
42
+ [`@sorandomains/holder`](https://www.npmjs.com/package/@sorandomains/holder).
42
43
 
43
44
  ## Signing
44
45
 
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@
20
20
  * `acceptNamespaceTransfer`, which the proposed NEW owner signs. Name-holder
21
21
  * powers (transferring an individual name, pointing it at a new address,
22
22
  * electing a primary name) are the holder's alone — they live in the contracts'
23
- * holder-authorized entry points and will ship in a holder-side module; this
23
+ * holder-authorized entry points and live in `@sorandomains/holder`; this
24
24
  * package deliberately cannot exercise them.
25
25
  *
26
26
  * SIGNING. Supply a `TxSigner`: `keypairSigner(secret)` for backends, or wrap a
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@
20
20
  * `acceptNamespaceTransfer`, which the proposed NEW owner signs. Name-holder
21
21
  * powers (transferring an individual name, pointing it at a new address,
22
22
  * electing a primary name) are the holder's alone — they live in the contracts'
23
- * holder-authorized entry points and will ship in a holder-side module; this
23
+ * holder-authorized entry points and live in `@sorandomains/holder`; this
24
24
  * package deliberately cannot exercise them.
25
25
  *
26
26
  * SIGNING. Supply a `TxSigner`: `keypairSigner(secret)` for backends, or wrap a
@@ -72,7 +72,9 @@ function decodeIssuedEvents(events, registrarId) {
72
72
  if (topics.length < 1 || scValToNative(topics[0]) !== "issued")
73
73
  continue;
74
74
  const data = scValToNative(body.data());
75
- out.push({ label: Buffer.from(data[0]).toString("utf8"), holder: String(data[1]) });
75
+ if (!(data?.[0] instanceof Uint8Array) || typeof data?.[1] !== "string")
76
+ continue;
77
+ out.push({ label: new TextDecoder().decode(data[0]), holder: data[1] });
76
78
  }
77
79
  catch {
78
80
  /* not an issued event — skip */
@@ -207,13 +209,32 @@ function assertLabel(label) {
207
209
  }
208
210
  }
209
211
  /** Registry namehash of a top-level namespace: sha256(ZERO32 ‖ sha256(ns)). */
212
+ // Byte helpers with zero Node built-ins of our own — browser bundlers get no
213
+ // bare `Buffer` references from this package. (`hash` accepts Uint8Array at
214
+ // runtime; its Buffer parameter type is cast around.)
215
+ const utf8 = (str) => new TextEncoder().encode(str);
216
+ function concatBytes(...parts) {
217
+ const out = new Uint8Array(parts.reduce((n, part) => n + part.length, 0));
218
+ let offset = 0;
219
+ for (const part of parts) {
220
+ out.set(part, offset);
221
+ offset += part.length;
222
+ }
223
+ return out;
224
+ }
210
225
  function namehash(namespace) {
211
- return hash(Buffer.concat([Buffer.alloc(32), hash(Buffer.from(namespace, "utf8"))]));
226
+ const labelHash = new Uint8Array(hash(utf8(namespace)));
227
+ return new Uint8Array(hash(concatBytes(new Uint8Array(32), labelHash)));
212
228
  }
213
- const labelArg = (label) => nativeToScVal(Buffer.from(label, "utf8"), { type: "bytes" });
229
+ const labelArg = (label) => nativeToScVal(utf8(label), { type: "bytes" });
214
230
  const addrArg = (address) => nativeToScVal(address, { type: "address" });
215
231
  const nodeArg = (node) => nativeToScVal(node, { type: "bytes" });
216
- const toHex = (v) => Buffer.from(v).toString("hex");
232
+ function toHex(v) {
233
+ if (!(v instanceof Uint8Array)) {
234
+ throw new OwnerError(`expected 32 bytes from the contract, got ${typeof v} — ABI drift; refusing to fabricate a node id`);
235
+ }
236
+ return Array.from(v, (b) => b.toString(16).padStart(2, "0")).join("");
237
+ }
217
238
  // Simulation-only reads need a well-formed source account that never signs.
218
239
  const SIM_SOURCE = "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF";
219
240
  /** One transaction issues at most this many names (contract MAX_BATCH). */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sorandomains/owner",
3
- "version": "0.2.0",
4
- "description": "Run your Soran namespace on Stellar — issue names, manage lifecycle, transfer, and walk the one-way permanence door.",
3
+ "version": "0.3.1",
4
+ "description": "Run your Soran namespace on Stellar \u2014 issue names, manage lifecycle, transfer, and walk the one-way permanence door.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -11,7 +11,8 @@
11
11
  "scripts": {
12
12
  "build": "tsc",
13
13
  "typecheck": "tsc --noEmit",
14
- "prepublishOnly": "tsc"
14
+ "prepublishOnly": "tsc",
15
+ "check:browser": "esbuild dist/index.js --bundle --platform=browser --external:@stellar/stellar-sdk --outfile=browser-check.js --legal-comments=none --log-level=error && node -e \"const fs=require('fs');const s=fs.readFileSync('browser-check.js','utf8');fs.unlinkSync('browser-check.js');if(/\\bBuffer\\b/.test(s)){console.error('FAIL: bare Buffer reference in browser bundle');process.exit(1)}console.log('browser bundle clean')\""
15
16
  },
16
17
  "license": "MIT",
17
18
  "repository": {
@@ -38,6 +39,13 @@
38
39
  "@stellar/stellar-sdk": "^16.2.0",
39
40
  "@types/node": "^22.20.1",
40
41
  "tsx": "^4.19.2",
41
- "typescript": "^5.7.3"
42
+ "typescript": "^5.7.3",
43
+ "esbuild": "^0.25.0"
44
+ },
45
+ "exports": {
46
+ ".": {
47
+ "types": "./dist/index.d.ts",
48
+ "default": "./dist/index.js"
49
+ }
42
50
  }
43
51
  }