@sorandomains/owner 0.2.0 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.js +25 -4
  2. package/package.json +12 -4
package/dist/index.js CHANGED
@@ -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.0",
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
  }