@parity/product-sdk-terminal 0.6.2 → 0.7.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/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  requestResourceAllocation,
3
3
  sendResourceAllocation
4
- } from "./chunk-MQGGUAWC.js";
4
+ } from "./chunk-YS3GW2XW.js";
5
5
  import {
6
6
  createNodeStorageAdapter,
7
7
  sanitizeKey
@@ -277,8 +277,27 @@ if (void 0) {
277
277
  var fakeLazyClient2;
278
278
 
279
279
  // src/signer.ts
280
+ import { NoAllowanceError } from "@novasamatech/statement-store";
280
281
  import { decAnyMetadata, unifyMetadata } from "@polkadot-api/substrate-bindings";
281
282
  import { deriveProductAccountPublicKey } from "@parity/product-sdk-keys";
283
+ import { AllowanceExpiredError } from "@parity/product-sdk-signer/errors";
284
+ function isNoAllowanceError(error) {
285
+ for (let current = error, depth = 0; current != null && depth < 8; depth++) {
286
+ if (current instanceof NoAllowanceError) return true;
287
+ if (current instanceof Error) {
288
+ if (current.constructor.name === "NoAllowanceError" || current.message.includes("no allowance set")) {
289
+ return true;
290
+ }
291
+ current = current.cause;
292
+ } else {
293
+ break;
294
+ }
295
+ }
296
+ return false;
297
+ }
298
+ function toAllowanceExpiredError(error) {
299
+ return isNoAllowanceError(error) ? new AllowanceExpiredError("statementStore", error) : null;
300
+ }
282
301
  function buildCreateTransactionRequest(productAccountId, callData, signedExtensions, txExtVersion) {
283
302
  const checkGenesis = signedExtensions.CheckGenesis;
284
303
  if (!checkGenesis) {
@@ -314,6 +333,8 @@ function txExtVersionFromMetadata(metadata) {
314
333
  async function requestSignedTransaction(session, request) {
315
334
  const result = await session.createTransaction(request);
316
335
  if (result.isErr()) {
336
+ const expired = toAllowanceExpiredError(result.error);
337
+ if (expired) throw expired;
317
338
  throw new Error(`Mobile transaction signing rejected: ${result.error.message}`);
318
339
  }
319
340
  return result.value;
@@ -336,6 +357,8 @@ function makeRawBytesSignCallback(session, productAccountId) {
336
357
  data: { tag: "Bytes", value: data }
337
358
  });
338
359
  if (result.isErr()) {
360
+ const expired = toAllowanceExpiredError(result.error);
361
+ if (expired) throw expired;
339
362
  throw new Error(`Mobile signing rejected: ${result.error.message}`);
340
363
  }
341
364
  return result.value.signature;
@@ -585,6 +608,49 @@ if (void 0) {
585
608
  "Mobile transaction signing rejected: user declined"
586
609
  );
587
610
  });
611
+ test("throws AllowanceExpiredError when the failure is a NoAllowanceError", async () => {
612
+ const underlying = new NoAllowanceError();
613
+ const session = makeSession({
614
+ createTransaction: async () => err(underlying)
615
+ });
616
+ await expect(requestSignedTransaction(session, request)).rejects.toBeInstanceOf(
617
+ AllowanceExpiredError
618
+ );
619
+ await expect(requestSignedTransaction(session, request)).rejects.toMatchObject({
620
+ name: "AllowanceExpiredError",
621
+ resource: "statementStore",
622
+ cause: underlying
623
+ });
624
+ });
625
+ test("throws AllowanceExpiredError for a wire-serialized failure (message match only)", async () => {
626
+ expect(new NoAllowanceError().message).toBe(
627
+ "Submit failed, no allowance set for account"
628
+ );
629
+ const serialized = new Error("Submit failed, no allowance set for account");
630
+ const session = makeSession({
631
+ createTransaction: async () => err(serialized)
632
+ });
633
+ await expect(requestSignedTransaction(session, request)).rejects.toBeInstanceOf(
634
+ AllowanceExpiredError
635
+ );
636
+ });
637
+ test("throws AllowanceExpiredError when the NoAllowanceError is wrapped as a cause", async () => {
638
+ const wrapped = new Error("submitRequest failed", { cause: new NoAllowanceError() });
639
+ const session = makeSession({
640
+ createTransaction: async () => err(wrapped)
641
+ });
642
+ await expect(requestSignedTransaction(session, request)).rejects.toBeInstanceOf(
643
+ AllowanceExpiredError
644
+ );
645
+ });
646
+ test("a non-allowance Error still surfaces as the generic rejection", async () => {
647
+ const session = makeSession({
648
+ createTransaction: async () => err(new Error("transport exploded"))
649
+ });
650
+ await expect(requestSignedTransaction(session, request)).rejects.toThrow(
651
+ "Mobile transaction signing rejected: transport exploded"
652
+ );
653
+ });
588
654
  });
589
655
  describe("makeRawBytesSignCallback", () => {
590
656
  test("forwards data verbatim under the Bytes tag with the right productAccountId", async () => {
@@ -612,6 +678,29 @@ if (void 0) {
612
678
  const out = await callback(new Uint8Array([0]));
613
679
  expect(out).toBe(sig);
614
680
  });
681
+ test("throws AllowanceExpiredError when the failure is a NoAllowanceError", async () => {
682
+ const underlying = new NoAllowanceError();
683
+ const session = makeSession({
684
+ signRaw: async () => err(underlying)
685
+ });
686
+ const callback = makeRawBytesSignCallback(session, ["my-app", 0]);
687
+ await expect(callback(new Uint8Array([1]))).rejects.toBeInstanceOf(
688
+ AllowanceExpiredError
689
+ );
690
+ await expect(callback(new Uint8Array([1]))).rejects.toMatchObject({
691
+ resource: "statementStore",
692
+ cause: underlying
693
+ });
694
+ });
695
+ test("a non-allowance failure still surfaces as the generic rejection", async () => {
696
+ const session = makeSession({
697
+ signRaw: async () => err(new Error("user declined"))
698
+ });
699
+ const callback = makeRawBytesSignCallback(session, ["my-app", 0]);
700
+ await expect(callback(new Uint8Array([1]))).rejects.toThrow(
701
+ "Mobile signing rejected: user declined"
702
+ );
703
+ });
615
704
  });
616
705
  describe("createSessionSignerForAccount", () => {
617
706
  test("forwards productAccountId from the explicit ref", async () => {
@@ -655,6 +744,9 @@ var makeSession2;
655
744
  var ext2;
656
745
  var fakeAdapter2;
657
746
 
747
+ // src/index.ts
748
+ import { AllowanceExpiredError as AllowanceExpiredError2, SignerError } from "@parity/product-sdk-signer/errors";
749
+
658
750
  // src/allowance.ts
659
751
  import { AllowanceError } from "@novasamatech/host-papp";
660
752
 
@@ -1047,9 +1139,11 @@ if (void 0) {
1047
1139
  }
1048
1140
  export {
1049
1141
  AllowanceError2 as AllowanceError,
1142
+ AllowanceExpiredError2 as AllowanceExpiredError,
1050
1143
  INCOMPLETE_SESSION_MESSAGE,
1051
1144
  SS_PASEO_STABLE_STAGE_ENDPOINTS,
1052
1145
  SS_STABLE_STAGE_ENDPOINTS,
1146
+ SignerError,
1053
1147
  createNodeStorageAdapter,
1054
1148
  createSessionSigner,
1055
1149
  createSessionSignerForAccount,