@sorandomains/holder 0.1.1 → 0.2.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 +26 -18
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@
30
30
  * before signing. Operations on one instance are serialized so concurrent
31
31
  * calls cannot race the account sequence number.
32
32
  */
33
- import { Account, Address, BASE_FEE, Contract, Keypair, Networks, Operation, TransactionBuilder, hash, nativeToScVal, rpc, scValToNative, xdr, } from "@stellar/stellar-sdk";
33
+ import { Account, Address, BASE_FEE, Contract, Keypair, Networks, Operation, TransactionBuilder, hash, nativeToScVal, rpc, scValToNative, } from "@stellar/stellar-sdk";
34
34
  // ---------------------------------------------------------------------------
35
35
  // Deployments
36
36
  // ---------------------------------------------------------------------------
@@ -167,6 +167,11 @@ function concatBytes(...parts) {
167
167
  }
168
168
  return out;
169
169
  }
170
+ /** Browser-safe hex (SDK17: hash()/XDR bytes are Uint8Array, whose toString()
171
+ * ignores a radix — and this package forbids a bare `Buffer` in the bundle). */
172
+ function toHex(b) {
173
+ return Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
174
+ }
170
175
  function namehash(namespace) {
171
176
  const labelHash = new Uint8Array(hash(utf8(namespace)));
172
177
  return new Uint8Array(hash(concatBytes(new Uint8Array(32), labelHash)));
@@ -487,12 +492,12 @@ export class SoranHolder {
487
492
  assertSatisfiableAuth(prepared, pub, contractId, fn) {
488
493
  const op = prepared.operations[0];
489
494
  for (const entry of op?.auth ?? []) {
490
- const cred = entry.credentials();
491
- if (cred.switch() !== xdr.SorobanCredentialsType.sorobanCredentialsAddress())
495
+ const cred = entry.credentials;
496
+ if (cred.type !== "sorobanCredentialsAddress")
492
497
  continue;
493
498
  let required;
494
499
  try {
495
- required = Address.fromScAddress(cred.address().address()).toString();
500
+ required = Address.fromScAddress(cred.address.address).toString();
496
501
  }
497
502
  catch {
498
503
  continue;
@@ -523,21 +528,24 @@ export class SoranHolder {
523
528
  .setTimeout(this.timeoutSecs)
524
529
  .build();
525
530
  let tx = build(await this.sourceAccount(pub, fn));
526
- let sim = await this.server.simulateTransaction(tx);
531
+ // (SDK17/P28) useUpgradedAuth=false keeps legacy V1 SorobanCredentials rather
532
+ // than CAP-71 address-bound V2 — valid against P27 (pre-vote) and P28 (post),
533
+ // and keeps assertSatisfiableAuth's `sorobanCredentialsAddress` check exact.
534
+ let sim = await this.server.simulateTransaction(tx, undefined, undefined, false);
527
535
  for (let round = 0; rpc.Api.isSimulationRestore(sim); round++) {
528
536
  if (round >= 2) {
529
537
  throw new HolderError(`${fn}: entries still need restoring after ${round} restore transactions — retry later`, contractId, fn);
530
538
  }
531
539
  await this.restore(sim, pub);
532
540
  tx = build(await this.sourceAccount(pub, fn));
533
- sim = await this.server.simulateTransaction(tx);
541
+ sim = await this.server.simulateTransaction(tx, undefined, undefined, false);
534
542
  }
535
543
  if (rpc.Api.isSimulationError(sim)) {
536
544
  throw typedError(contractId, fn, sim.error, errNames);
537
545
  }
538
546
  const prepared = rpc.assembleTransaction(tx, sim).build();
539
547
  this.assertSatisfiableAuth(prepared, pub, contractId, fn);
540
- const txHash = prepared.hash().toString("hex");
548
+ const txHash = toHex(prepared.hash()); // (SDK17) hash() is Uint8Array
541
549
  const signed = await this.signEnvelope(prepared.toXDR());
542
550
  const envelope = TransactionBuilder.fromXDR(signed, this.passphrase);
543
551
  let sent;
@@ -609,18 +617,18 @@ export class SoranHolder {
609
617
  try {
610
618
  const meta = got.resultMetaXdr;
611
619
  const diags = got.diagnosticEventsXdr ??
612
- (meta && meta.switch() === 3
613
- ? (meta.v3().sorobanMeta()?.diagnosticEvents() ?? [])
614
- : meta && meta.switch() === 4
615
- ? meta.v4().diagnosticEvents()
620
+ (meta && meta.type === "v3"
621
+ ? (meta.value.sorobanMeta?.diagnosticEvents ?? [])
622
+ : meta && meta.type === "v4"
623
+ ? meta.value.diagnosticEvents
616
624
  : []);
617
625
  outer: for (const d of diags) {
618
- const body = d.event().body().v0();
619
- for (const v of [...body.topics(), body.data()]) {
620
- if (v.switch() === xdr.ScValType.scvError()) {
621
- const err = v.error();
622
- if (err.switch() === xdr.ScErrorType.sceContract()) {
623
- code = err.contractCode();
626
+ const body = d.event.body.value;
627
+ for (const v of [...body.topics, body.data]) {
628
+ if (v.type === "scvError") {
629
+ const err = v.error;
630
+ if (err.type === "sceContract") {
631
+ code = err.contractCode;
624
632
  break outer;
625
633
  }
626
634
  }
@@ -632,7 +640,7 @@ export class SoranHolder {
632
640
  }
633
641
  let resultCode = `tx status ${got.status}`;
634
642
  try {
635
- resultCode = got.resultXdr?.result().switch().name ?? resultCode;
643
+ resultCode = got.resultXdr?.result.type ?? resultCode;
636
644
  }
637
645
  catch {
638
646
  /* keep plain status */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sorandomains/holder",
3
- "version": "0.1.1",
4
- "description": "Manage your own Soran name on Stellar \u2014 records, profile, reverse, primary, and transfers, signed by your key.",
3
+ "version": "0.2.0",
4
+ "description": "Manage your own Soran name on Stellar records, profile, reverse, primary, and transfers, signed by your key.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -39,10 +39,10 @@
39
39
  "reverse-lookup"
40
40
  ],
41
41
  "peerDependencies": {
42
- "@stellar/stellar-sdk": ">=13 <17"
42
+ "@stellar/stellar-sdk": ">=17 <18"
43
43
  },
44
44
  "devDependencies": {
45
- "@stellar/stellar-sdk": "^16.2.0",
45
+ "@stellar/stellar-sdk": "^17.0.1",
46
46
  "@types/node": "^22.20.1",
47
47
  "esbuild": "^0.25.0",
48
48
  "tsx": "^4.19.2",