@ledgerhq/hw-app-exchange 0.10.4 → 0.11.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.
@@ -1,8 +1,8 @@
1
1
 
2
- > @ledgerhq/hw-app-exchange@0.10.4 prebuild /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-app-exchange
2
+ > @ledgerhq/hw-app-exchange@0.11.0 prebuild /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-app-exchange
3
3
  > pnpm pbjs -t json -r ledger_swap -o src/generate-protocol.json ./protocol.proto
4
4
 
5
5
 
6
- > @ledgerhq/hw-app-exchange@0.10.4 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-app-exchange
6
+ > @ledgerhq/hw-app-exchange@0.11.0 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-app-exchange
7
7
  > tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es
8
8
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ledgerhq/hw-app-exchange
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#10857](https://github.com/LedgerHQ/ledger-live/pull/10857) [`8de2972`](https://github.com/LedgerHQ/ledger-live/commit/8de2972333b8d40aa105c6d229d3cfe10d42058e) Thanks [@lpaquet-ledger](https://github.com/lpaquet-ledger)! - fix swap custom errors and add translations to them
8
+
9
+ ## 0.11.0-next.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#10857](https://github.com/LedgerHQ/ledger-live/pull/10857) [`8de2972`](https://github.com/LedgerHQ/ledger-live/commit/8de2972333b8d40aa105c6d229d3cfe10d42058e) Thanks [@lpaquet-ledger](https://github.com/lpaquet-ledger)! - fix swap custom errors and add translations to them
14
+
3
15
  ## 0.10.4
4
16
 
5
17
  ### Patch Changes
@@ -20,5 +20,8 @@ export declare const ErrorStatus: {
20
20
  readonly INVALID_DATA_LENGTH: 28162;
21
21
  readonly SIGN_VERIFICATION_FAIL: 40218;
22
22
  };
23
- export declare function getExchangeErrorMessage(errorCode: number, step?: string): string | undefined;
23
+ export declare function getExchangeErrorMessage(errorCode: number, step?: string): {
24
+ errorName?: string;
25
+ errorMessage?: string;
26
+ };
24
27
  //# sourceMappingURL=ReturnCode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReturnCode.d.ts","sourceRoot":"","sources":["../src/ReturnCode.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAS,CAAC;AAC/B,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;CAiBd,CAAC;AAEX,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAwC5F"}
1
+ {"version":3,"file":"ReturnCode.d.ts","sourceRoot":"","sources":["../src/ReturnCode.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAS,CAAC;AAC/B,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;CAiBd,CAAC;AAEX,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,GACZ;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAsD/C"}
package/lib/ReturnCode.js CHANGED
@@ -26,43 +26,55 @@ exports.ErrorStatus = {
26
26
  function getExchangeErrorMessage(errorCode, step) {
27
27
  switch (errorCode) {
28
28
  case exports.ErrorStatus.INCORRECT_COMMAND_DATA:
29
- return "Incorrect command data";
29
+ return { errorName: "incorrectCommandData", errorMessage: "Incorrect command data" };
30
30
  case exports.ErrorStatus.DESERIALIZATION_FAILED:
31
- return "Payload deserialzation failed";
31
+ return { errorName: "deserializationFailed", errorMessage: "Payload deserialzation failed" };
32
32
  case exports.ErrorStatus.WRONG_TRANSACTION_ID:
33
- return "Wrong transaction id";
33
+ return { errorName: "wrongTransactionId", errorMessage: "Wrong transaction id" };
34
34
  case exports.ErrorStatus.INVALID_ADDRESS:
35
35
  if (step === "CHECK_PAYOUT_ADDRESS")
36
- return "This receiving account does not belong to the device you have connected. Please change and retry";
36
+ return {
37
+ errorName: "checkPayoutAddress",
38
+ errorMessage: "This receiving account does not belong to the device you have connected. Please change and retry",
39
+ };
37
40
  else if (step === "CHECK_REFUND_ADDRESS")
38
- return "This sending account does not belong to the device you have connected. Please change and retry";
39
- return "Invalid address";
41
+ return {
42
+ errorName: "checkRefundAddress",
43
+ errorMessage: "This sending account does not belong to the device you have connected. Please change and retry",
44
+ };
45
+ return { errorName: "invalidAddress", errorMessage: "Invalid address" };
40
46
  case exports.ErrorStatus.USER_REFUSED:
41
- return "User refused";
47
+ return { errorName: "userRefused", errorMessage: "User refused" };
42
48
  case exports.ErrorStatus.INTERNAL_ERROR:
43
- return "Internal error";
49
+ return { errorName: "internalError", errorMessage: "Internal error" };
44
50
  case exports.ErrorStatus.WRONG_P1:
45
- return "Wrong P1";
51
+ return { errorName: "wrongP1", errorMessage: "Wrong P1" };
46
52
  case exports.ErrorStatus.WRONG_P2:
47
- return "Wrong P2";
53
+ return { errorName: "wrongP2", errorMessage: "Wrong P2" };
48
54
  case exports.ErrorStatus.WRONG_P2_EXTENSION:
49
- return "Wrong P2 extension";
55
+ return { errorName: "wrongP2Extension", errorMessage: "Wrong P2 extension" };
50
56
  case exports.ErrorStatus.INVALID_P2_EXTENSION:
51
- return "Invalid P2 with current context";
57
+ return { errorName: "invalidP2Extension", errorMessage: "Invalid P2 with current context" };
52
58
  case exports.ErrorStatus.UNEXPECTED_INSTRUCTION:
53
- return "Unexpected instruction with current context";
59
+ return {
60
+ errorName: "unexpectedInstruction",
61
+ errorMessage: "Unexpected instruction with current context",
62
+ };
54
63
  case exports.ErrorStatus.CLASS_NOT_SUPPORTED:
55
- return "Class not supported";
64
+ return { errorName: "classNotSupported", errorMessage: "Class not supported" };
56
65
  case exports.ErrorStatus.INVALID_INSTRUCTION:
57
- return "Invalid instruction";
66
+ return { errorName: "invalidInstruction", errorMessage: "Invalid instruction" };
58
67
  case exports.ErrorStatus.MALFORMED_APDU:
59
- return "APDU header malformed";
68
+ return { errorName: "malformedApdu", errorMessage: "APDU header malformed" };
60
69
  case exports.ErrorStatus.INVALID_DATA_LENGTH:
61
- return "The length of this data is refused for this command";
70
+ return {
71
+ errorName: "invalidDataLength",
72
+ errorMessage: "The length of this data is refused for this command",
73
+ };
62
74
  case exports.ErrorStatus.SIGN_VERIFICATION_FAIL:
63
- return "Signature verification failed";
75
+ return { errorName: "signVerificationFail", errorMessage: "Signature verification failed" };
64
76
  }
65
- return undefined;
77
+ return { errorName: undefined, errorMessage: undefined };
66
78
  }
67
79
  exports.getExchangeErrorMessage = getExchangeErrorMessage;
68
80
  //# sourceMappingURL=ReturnCode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReturnCode.js","sourceRoot":"","sources":["../src/ReturnCode.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,QAAQ,GAAG,MAAM,CAAC;AAClB,QAAA,WAAW,GAAG;IACzB,sBAAsB,EAAE,MAAM;IAC9B,sBAAsB,EAAE,MAAM;IAC9B,oBAAoB,EAAE,MAAM;IAC5B,eAAe,EAAE,MAAM;IACvB,YAAY,EAAE,MAAM;IACpB,cAAc,EAAE,MAAM;IACtB,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;IAChB,kBAAkB,EAAE,MAAM;IAC1B,oBAAoB,EAAE,MAAM;IAC5B,mBAAmB,EAAE,MAAM;IAC3B,sBAAsB,EAAE,MAAM;IAC9B,mBAAmB,EAAE,MAAM;IAC3B,cAAc,EAAE,MAAM;IACtB,mBAAmB,EAAE,MAAM;IAC3B,sBAAsB,EAAE,MAAM;CACtB,CAAC;AAEX,SAAgB,uBAAuB,CAAC,SAAiB,EAAE,IAAa;IACtE,QAAQ,SAAS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J,KAAK,mBAAW,CAAC,sBAAsB;YACrC,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,YAAY,EAAE,+BAA+B,EAAE,CAAC;IAChG,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;AAC3D,CAAC;AAzDD,0DAyDC"}
@@ -6,13 +6,16 @@ describe("getExchageErrorMessage", () => {
6
6
  // When
7
7
  const result = (0, ReturnCode_1.getExchangeErrorMessage)(0x6a80);
8
8
  // Then
9
- expect(result).toBe("Incorrect command data");
9
+ expect(result).toStrictEqual({
10
+ errorMessage: "Incorrect command data",
11
+ errorName: "incorrectCommandData",
12
+ });
10
13
  });
11
14
  it("returns undefined if the value is unknown", () => {
12
15
  // When
13
16
  const result = (0, ReturnCode_1.getExchangeErrorMessage)(0x6a77);
14
17
  // Then
15
- expect(result).toBeUndefined();
18
+ expect(result).toStrictEqual({ errorMessage: undefined, errorName: undefined });
16
19
  });
17
20
  });
18
21
  //# sourceMappingURL=ReturnCode.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReturnCode.test.js","sourceRoot":"","sources":["../src/ReturnCode.test.ts"],"names":[],"mappings":";;AAAA,6CAAuD;AAEvD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,OAAO;QACP,MAAM,MAAM,GAAG,IAAA,oCAAuB,EAAC,MAAM,CAAC,CAAC;QAE/C,OAAO;QACP,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,OAAO;QACP,MAAM,MAAM,GAAG,IAAA,oCAAuB,EAAC,MAAM,CAAC,CAAC;QAE/C,OAAO;QACP,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"ReturnCode.test.js","sourceRoot":"","sources":["../src/ReturnCode.test.ts"],"names":[],"mappings":";;AAAA,6CAAuD;AAEvD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,OAAO;QACP,MAAM,MAAM,GAAG,IAAA,oCAAuB,EAAC,MAAM,CAAC,CAAC;QAE/C,OAAO;QACP,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC;YAC3B,YAAY,EAAE,wBAAwB;YACtC,SAAS,EAAE,sBAAsB;SAClC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,OAAO;QACP,MAAM,MAAM,GAAG,IAAA,oCAAuB,EAAC,MAAM,CAAC,CAAC;QAE/C,OAAO;QACP,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -20,5 +20,8 @@ export declare const ErrorStatus: {
20
20
  readonly INVALID_DATA_LENGTH: 28162;
21
21
  readonly SIGN_VERIFICATION_FAIL: 40218;
22
22
  };
23
- export declare function getExchangeErrorMessage(errorCode: number, step?: string): string | undefined;
23
+ export declare function getExchangeErrorMessage(errorCode: number, step?: string): {
24
+ errorName?: string;
25
+ errorMessage?: string;
26
+ };
24
27
  //# sourceMappingURL=ReturnCode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReturnCode.d.ts","sourceRoot":"","sources":["../src/ReturnCode.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAS,CAAC;AAC/B,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;CAiBd,CAAC;AAEX,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAwC5F"}
1
+ {"version":3,"file":"ReturnCode.d.ts","sourceRoot":"","sources":["../src/ReturnCode.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAS,CAAC;AAC/B,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;CAiBd,CAAC;AAEX,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,GACZ;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAsD/C"}
@@ -23,42 +23,54 @@ export const ErrorStatus = {
23
23
  export function getExchangeErrorMessage(errorCode, step) {
24
24
  switch (errorCode) {
25
25
  case ErrorStatus.INCORRECT_COMMAND_DATA:
26
- return "Incorrect command data";
26
+ return { errorName: "incorrectCommandData", errorMessage: "Incorrect command data" };
27
27
  case ErrorStatus.DESERIALIZATION_FAILED:
28
- return "Payload deserialzation failed";
28
+ return { errorName: "deserializationFailed", errorMessage: "Payload deserialzation failed" };
29
29
  case ErrorStatus.WRONG_TRANSACTION_ID:
30
- return "Wrong transaction id";
30
+ return { errorName: "wrongTransactionId", errorMessage: "Wrong transaction id" };
31
31
  case ErrorStatus.INVALID_ADDRESS:
32
32
  if (step === "CHECK_PAYOUT_ADDRESS")
33
- return "This receiving account does not belong to the device you have connected. Please change and retry";
33
+ return {
34
+ errorName: "checkPayoutAddress",
35
+ errorMessage: "This receiving account does not belong to the device you have connected. Please change and retry",
36
+ };
34
37
  else if (step === "CHECK_REFUND_ADDRESS")
35
- return "This sending account does not belong to the device you have connected. Please change and retry";
36
- return "Invalid address";
38
+ return {
39
+ errorName: "checkRefundAddress",
40
+ errorMessage: "This sending account does not belong to the device you have connected. Please change and retry",
41
+ };
42
+ return { errorName: "invalidAddress", errorMessage: "Invalid address" };
37
43
  case ErrorStatus.USER_REFUSED:
38
- return "User refused";
44
+ return { errorName: "userRefused", errorMessage: "User refused" };
39
45
  case ErrorStatus.INTERNAL_ERROR:
40
- return "Internal error";
46
+ return { errorName: "internalError", errorMessage: "Internal error" };
41
47
  case ErrorStatus.WRONG_P1:
42
- return "Wrong P1";
48
+ return { errorName: "wrongP1", errorMessage: "Wrong P1" };
43
49
  case ErrorStatus.WRONG_P2:
44
- return "Wrong P2";
50
+ return { errorName: "wrongP2", errorMessage: "Wrong P2" };
45
51
  case ErrorStatus.WRONG_P2_EXTENSION:
46
- return "Wrong P2 extension";
52
+ return { errorName: "wrongP2Extension", errorMessage: "Wrong P2 extension" };
47
53
  case ErrorStatus.INVALID_P2_EXTENSION:
48
- return "Invalid P2 with current context";
54
+ return { errorName: "invalidP2Extension", errorMessage: "Invalid P2 with current context" };
49
55
  case ErrorStatus.UNEXPECTED_INSTRUCTION:
50
- return "Unexpected instruction with current context";
56
+ return {
57
+ errorName: "unexpectedInstruction",
58
+ errorMessage: "Unexpected instruction with current context",
59
+ };
51
60
  case ErrorStatus.CLASS_NOT_SUPPORTED:
52
- return "Class not supported";
61
+ return { errorName: "classNotSupported", errorMessage: "Class not supported" };
53
62
  case ErrorStatus.INVALID_INSTRUCTION:
54
- return "Invalid instruction";
63
+ return { errorName: "invalidInstruction", errorMessage: "Invalid instruction" };
55
64
  case ErrorStatus.MALFORMED_APDU:
56
- return "APDU header malformed";
65
+ return { errorName: "malformedApdu", errorMessage: "APDU header malformed" };
57
66
  case ErrorStatus.INVALID_DATA_LENGTH:
58
- return "The length of this data is refused for this command";
67
+ return {
68
+ errorName: "invalidDataLength",
69
+ errorMessage: "The length of this data is refused for this command",
70
+ };
59
71
  case ErrorStatus.SIGN_VERIFICATION_FAIL:
60
- return "Signature verification failed";
72
+ return { errorName: "signVerificationFail", errorMessage: "Signature verification failed" };
61
73
  }
62
- return undefined;
74
+ return { errorName: undefined, errorMessage: undefined };
63
75
  }
64
76
  //# sourceMapp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AAoB,EAAE,CAAC;QAC/E,KAAK,WAAW,CAAC,oBAAoB;YACnC,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,YAAY,EAAE,iCAAiC,EAAE,CAAC;QAC9F,KAAK,WAAW,CAAC,sBAAsB;YACrC,OAAO;gBACL,SAAS,EAAE,uBAAuB;gBAClC,YAAY,EAAE,6CAA6C;aAC5D,CAAC;QACJ,KAAK,WAAW,CAAC,mBAAmB;YAClC,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,YAAY,EAAE,qBAAqB,EAAE,CAAC;QACjF,KAAK,WAAW,CAAC,mBAAmB;YAClC,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,YAAY,EAAE,qBAAqB,EAAE,CAAC;QAClF,KAAK,WAAW,CAAC,cAAc;YAC7B,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,uBAAuB,EAAE,CAAC;QAC/E,KAAK,WAAW,CAAC,mBAAmB;YAClC,OAAO;gBACL,SAAS,EAAE,mBAAmB;gBAC9B,YAAY,EAAE,qDAAqD;aACpE,CAAC;QACJ,KAAK,WAAW,CAAC,sBAAsB;YACrC,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,YAAY,EAAE,+BAA+B,EAAE,CAAC;IAChG,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;AAC3D,CAAC"}
@@ -4,13 +4,16 @@ describe("getExchageErrorMessage", () => {
4
4
  // When
5
5
  const result = getExchangeErrorMessage(0x6a80);
6
6
  // Then
7
- expect(result).toBe("Incorrect command data");
7
+ expect(result).toStrictEqual({
8
+ errorMessage: "Incorrect command data",
9
+ errorName: "incorrectCommandData",
10
+ });
8
11
  });
9
12
  it("returns undefined if the value is unknown", () => {
10
13
  // When
11
14
  const result = getExchangeErrorMessage(0x6a77);
12
15
  // Then
13
- expect(result).toBeUndefined();
16
+ expect(result).toStrictEqual({ errorMessage: undefined, errorName: undefined });
14
17
  });
15
18
  });
16
19
  //# sourceMappingURL=ReturnCode.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReturnCode.test.js","sourceRoot":"","sources":["../src/ReturnCode.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,OAAO;QACP,MAAM,MAAM,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAE/C,OAAO;QACP,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,OAAO;QACP,MAAM,MAAM,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAE/C,OAAO;QACP,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"ReturnCode.test.js","sourceRoot":"","sources":["../src/ReturnCode.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,OAAO;QACP,MAAM,MAAM,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAE/C,OAAO;QACP,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC;YAC3B,YAAY,EAAE,wBAAwB;YACtC,SAAS,EAAE,sBAAsB;SAClC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,OAAO;QACP,MAAM,MAAM,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAE/C,OAAO;QACP,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/hw-app-exchange",
3
- "version": "0.10.4",
3
+ "version": "0.11.0",
4
4
  "description": "Ledger Hardware Wallet Cosmos Application API",
5
5
  "keywords": [
6
6
  "Ledger",
@@ -6,13 +6,16 @@ describe("getExchageErrorMessage", () => {
6
6
  const result = getExchangeErrorMessage(0x6a80);
7
7
 
8
8
  // Then
9
- expect(result).toBe("Incorrect command data");
9
+ expect(result).toStrictEqual({
10
+ errorMessage: "Incorrect command data",
11
+ errorName: "incorrectCommandData",
12
+ });
10
13
  });
11
14
  it("returns undefined if the value is unknown", () => {
12
15
  // When
13
16
  const result = getExchangeErrorMessage(0x6a77);
14
17
 
15
18
  // Then
16
- expect(result).toBeUndefined();
19
+ expect(result).toStrictEqual({ errorMessage: undefined, errorName: undefined });
17
20
  });
18
21
  });
package/src/ReturnCode.ts CHANGED
@@ -21,44 +21,61 @@ export const ErrorStatus = {
21
21
  SIGN_VERIFICATION_FAIL: 0x9d1a,
22
22
  } as const;
23
23
 
24
- export function getExchangeErrorMessage(errorCode: number, step?: string): string | undefined {
24
+ export function getExchangeErrorMessage(
25
+ errorCode: number,
26
+ step?: string,
27
+ ): { errorName?: string; errorMessage?: string } {
25
28
  switch (errorCode) {
26
29
  case ErrorStatus.INCORRECT_COMMAND_DATA:
27
- return "Incorrect command data";
30
+ return { errorName: "incorrectCommandData", errorMessage: "Incorrect command data" };
28
31
  case ErrorStatus.DESERIALIZATION_FAILED:
29
- return "Payload deserialzation failed";
32
+ return { errorName: "deserializationFailed", errorMessage: "Payload deserialzation failed" };
30
33
  case ErrorStatus.WRONG_TRANSACTION_ID:
31
- return "Wrong transaction id";
34
+ return { errorName: "wrongTransactionId", errorMessage: "Wrong transaction id" };
32
35
  case ErrorStatus.INVALID_ADDRESS:
33
36
  if (step === "CHECK_PAYOUT_ADDRESS")
34
- return "This receiving account does not belong to the device you have connected. Please change and retry";
37
+ return {
38
+ errorName: "checkPayoutAddress",
39
+ errorMessage:
40
+ "This receiving account does not belong to the device you have connected. Please change and retry",
41
+ };
35
42
  else if (step === "CHECK_REFUND_ADDRESS")
36
- return "This sending account does not belong to the device you have connected. Please change and retry";
37
- return "Invalid address";
43
+ return {
44
+ errorName: "checkRefundAddress",
45
+ errorMessage:
46
+ "This sending account does not belong to the device you have connected. Please change and retry",
47
+ };
48
+ return { errorName: "invalidAddress", errorMessage: "Invalid address" };
38
49
  case ErrorStatus.USER_REFUSED:
39
- return "User refused";
50
+ return { errorName: "userRefused", errorMessage: "User refused" };
40
51
  case ErrorStatus.INTERNAL_ERROR:
41
- return "Internal error";
52
+ return { errorName: "internalError", errorMessage: "Internal error" };
42
53
  case ErrorStatus.WRONG_P1:
43
- return "Wrong P1";
54
+ return { errorName: "wrongP1", errorMessage: "Wrong P1" };
44
55
  case ErrorStatus.WRONG_P2:
45
- return "Wrong P2";
56
+ return { errorName: "wrongP2", errorMessage: "Wrong P2" };
46
57
  case ErrorStatus.WRONG_P2_EXTENSION:
47
- return "Wrong P2 extension";
58
+ return { errorName: "wrongP2Extension", errorMessage: "Wrong P2 extension" };
48
59
  case ErrorStatus.INVALID_P2_EXTENSION:
49
- return "Invalid P2 with current context";
60
+ return { errorName: "invalidP2Extension", errorMessage: "Invalid P2 with current context" };
50
61
  case ErrorStatus.UNEXPECTED_INSTRUCTION:
51
- return "Unexpected instruction with current context";
62
+ return {
63
+ errorName: "unexpectedInstruction",
64
+ errorMessage: "Unexpected instruction with current context",
65
+ };
52
66
  case ErrorStatus.CLASS_NOT_SUPPORTED:
53
- return "Class not supported";
67
+ return { errorName: "classNotSupported", errorMessage: "Class not supported" };
54
68
  case ErrorStatus.INVALID_INSTRUCTION:
55
- return "Invalid instruction";
69
+ return { errorName: "invalidInstruction", errorMessage: "Invalid instruction" };
56
70
  case ErrorStatus.MALFORMED_APDU:
57
- return "APDU header malformed";
71
+ return { errorName: "malformedApdu", errorMessage: "APDU header malformed" };
58
72
  case ErrorStatus.INVALID_DATA_LENGTH:
59
- return "The length of this data is refused for this command";
73
+ return {
74
+ errorName: "invalidDataLength",
75
+ errorMessage: "The length of this data is refused for this command",
76
+ };
60
77
  case ErrorStatus.SIGN_VERIFICATION_FAIL:
61
- return "Signature verification failed";
78
+ return { errorName: "signVerificationFail", errorMessage: "Signature verification failed" };
62
79
  }
63
- return undefined;
80
+ return { errorName: undefined, errorMessage: undefined };
64
81
  }