@ledgerhq/device-contacts-kit 0.3.0 → 0.4.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 (116) hide show
  1. package/README.md +22 -13
  2. package/lib/cjs/api/index.js +1 -1
  3. package/lib/cjs/api/index.js.map +3 -3
  4. package/lib/cjs/api/model/ContactsVersionRequirements.js +1 -1
  5. package/lib/cjs/api/model/ContactsVersionRequirements.js.map +3 -3
  6. package/lib/cjs/api/model/ContactsVersionRequirements.test.js +1 -1
  7. package/lib/cjs/api/model/ContactsVersionRequirements.test.js.map +3 -3
  8. package/lib/cjs/api/model/ProvideContact.js +2 -0
  9. package/lib/cjs/api/model/ProvideContact.js.map +7 -0
  10. package/lib/cjs/internal/app-binder/command/ProvideContactCommand.js +2 -0
  11. package/lib/cjs/internal/app-binder/command/ProvideContactCommand.js.map +7 -0
  12. package/lib/cjs/internal/app-binder/command/ProvideContactCommand.test.js +2 -0
  13. package/lib/cjs/internal/app-binder/command/ProvideContactCommand.test.js.map +7 -0
  14. package/lib/cjs/internal/app-binder/contactsVersionGuards.js +2 -0
  15. package/lib/cjs/internal/app-binder/contactsVersionGuards.js.map +7 -0
  16. package/lib/cjs/internal/app-binder/contactsVersionGuards.test.js +2 -0
  17. package/lib/cjs/internal/app-binder/contactsVersionGuards.test.js.map +7 -0
  18. package/lib/cjs/internal/app-binder/device-action/EditExternalAddressIdentifier/EditExternalAddressIdentifierDeviceAction.js +1 -1
  19. package/lib/cjs/internal/app-binder/device-action/EditExternalAddressIdentifier/EditExternalAddressIdentifierDeviceAction.js.map +3 -3
  20. package/lib/cjs/internal/app-binder/device-action/EditExternalAddressScope/EditExternalAddressScopeDeviceAction.js +1 -1
  21. package/lib/cjs/internal/app-binder/device-action/EditExternalAddressScope/EditExternalAddressScopeDeviceAction.js.map +3 -3
  22. package/lib/cjs/internal/app-binder/device-action/RegisterExternalAddress/RegisterExternalAddressDeviceAction.js +1 -1
  23. package/lib/cjs/internal/app-binder/device-action/RegisterExternalAddress/RegisterExternalAddressDeviceAction.js.map +3 -3
  24. package/lib/cjs/internal/app-binder/device-action/RenameContact/RenameContactDeviceAction.js +1 -1
  25. package/lib/cjs/internal/app-binder/device-action/RenameContact/RenameContactDeviceAction.js.map +3 -3
  26. package/lib/cjs/internal/app-binder/model/contactsConstants.js +1 -1
  27. package/lib/cjs/internal/app-binder/model/contactsConstants.js.map +3 -3
  28. package/lib/cjs/internal/app-binder/services/provideContact.js +2 -0
  29. package/lib/cjs/internal/app-binder/services/provideContact.js.map +7 -0
  30. package/lib/cjs/internal/app-binder/services/provideContact.test.js +2 -0
  31. package/lib/cjs/internal/app-binder/services/provideContact.test.js.map +7 -0
  32. package/lib/cjs/internal/app-binder/task/SendRegisterIdentityTask.js.map +2 -2
  33. package/lib/cjs/internal/app-binder/task/SendRegisterIdentityTask.test.js.map +1 -1
  34. package/lib/cjs/internal/app-binder/task/SendRenameContactTask.js +1 -1
  35. package/lib/cjs/internal/app-binder/task/SendRenameContactTask.js.map +2 -2
  36. package/lib/cjs/internal/app-binder/task/SendRenameContactTask.test.js +1 -1
  37. package/lib/cjs/internal/app-binder/task/SendRenameContactTask.test.js.map +3 -3
  38. package/lib/cjs/package.json +2 -2
  39. package/lib/esm/api/index.js +1 -1
  40. package/lib/esm/api/index.js.map +3 -3
  41. package/lib/esm/api/model/ContactsVersionRequirements.js +1 -1
  42. package/lib/esm/api/model/ContactsVersionRequirements.js.map +3 -3
  43. package/lib/esm/api/model/ContactsVersionRequirements.test.js +1 -1
  44. package/lib/esm/api/model/ContactsVersionRequirements.test.js.map +3 -3
  45. package/lib/esm/api/model/ProvideContact.js +1 -0
  46. package/lib/esm/api/model/ProvideContact.js.map +7 -0
  47. package/lib/esm/internal/app-binder/command/ProvideContactCommand.js +2 -0
  48. package/lib/esm/internal/app-binder/command/ProvideContactCommand.js.map +7 -0
  49. package/lib/esm/internal/app-binder/command/ProvideContactCommand.test.js +2 -0
  50. package/lib/esm/internal/app-binder/command/ProvideContactCommand.test.js.map +7 -0
  51. package/lib/esm/internal/app-binder/contactsVersionGuards.js +2 -0
  52. package/lib/esm/internal/app-binder/contactsVersionGuards.js.map +7 -0
  53. package/lib/esm/internal/app-binder/contactsVersionGuards.test.js +2 -0
  54. package/lib/esm/internal/app-binder/contactsVersionGuards.test.js.map +7 -0
  55. package/lib/esm/internal/app-binder/device-action/EditExternalAddressIdentifier/EditExternalAddressIdentifierDeviceAction.js +1 -1
  56. package/lib/esm/internal/app-binder/device-action/EditExternalAddressIdentifier/EditExternalAddressIdentifierDeviceAction.js.map +3 -3
  57. package/lib/esm/internal/app-binder/device-action/EditExternalAddressScope/EditExternalAddressScopeDeviceAction.js +1 -1
  58. package/lib/esm/internal/app-binder/device-action/EditExternalAddressScope/EditExternalAddressScopeDeviceAction.js.map +3 -3
  59. package/lib/esm/internal/app-binder/device-action/RegisterExternalAddress/RegisterExternalAddressDeviceAction.js +1 -1
  60. package/lib/esm/internal/app-binder/device-action/RegisterExternalAddress/RegisterExternalAddressDeviceAction.js.map +3 -3
  61. package/lib/esm/internal/app-binder/device-action/RenameContact/RenameContactDeviceAction.js +1 -1
  62. package/lib/esm/internal/app-binder/device-action/RenameContact/RenameContactDeviceAction.js.map +2 -2
  63. package/lib/esm/internal/app-binder/model/contactsConstants.js +1 -1
  64. package/lib/esm/internal/app-binder/model/contactsConstants.js.map +3 -3
  65. package/lib/esm/internal/app-binder/services/provideContact.js +2 -0
  66. package/lib/esm/internal/app-binder/services/provideContact.js.map +7 -0
  67. package/lib/esm/internal/app-binder/services/provideContact.test.js +2 -0
  68. package/lib/esm/internal/app-binder/services/provideContact.test.js.map +7 -0
  69. package/lib/esm/internal/app-binder/task/SendRegisterIdentityTask.js.map +2 -2
  70. package/lib/esm/internal/app-binder/task/SendRegisterIdentityTask.test.js.map +1 -1
  71. package/lib/esm/internal/app-binder/task/SendRenameContactTask.js +1 -1
  72. package/lib/esm/internal/app-binder/task/SendRenameContactTask.js.map +3 -3
  73. package/lib/esm/internal/app-binder/task/SendRenameContactTask.test.js +1 -1
  74. package/lib/esm/internal/app-binder/task/SendRenameContactTask.test.js.map +3 -3
  75. package/lib/esm/package.json +2 -2
  76. package/lib/types/api/index.d.ts +4 -1
  77. package/lib/types/api/index.d.ts.map +1 -1
  78. package/lib/types/api/model/ContactsVersionRequirements.d.ts +7 -25
  79. package/lib/types/api/model/ContactsVersionRequirements.d.ts.map +1 -1
  80. package/lib/types/api/model/ProvideContact.d.ts +20 -0
  81. package/lib/types/api/model/ProvideContact.d.ts.map +1 -0
  82. package/lib/types/internal/app-binder/command/ProvideContactCommand.d.ts +18 -0
  83. package/lib/types/internal/app-binder/command/ProvideContactCommand.d.ts.map +1 -0
  84. package/lib/types/internal/app-binder/command/ProvideContactCommand.test.d.ts +2 -0
  85. package/lib/types/internal/app-binder/command/ProvideContactCommand.test.d.ts.map +1 -0
  86. package/lib/types/internal/app-binder/{isContactsSupportedForSession.d.ts → contactsVersionGuards.d.ts} +19 -21
  87. package/lib/types/internal/app-binder/contactsVersionGuards.d.ts.map +1 -0
  88. package/lib/types/internal/app-binder/contactsVersionGuards.test.d.ts +2 -0
  89. package/lib/types/internal/app-binder/contactsVersionGuards.test.d.ts.map +1 -0
  90. package/lib/types/internal/app-binder/device-action/EditExternalAddressIdentifier/EditExternalAddressIdentifierDeviceAction.d.ts +1 -1
  91. package/lib/types/internal/app-binder/device-action/EditExternalAddressIdentifier/EditExternalAddressIdentifierDeviceAction.d.ts.map +1 -1
  92. package/lib/types/internal/app-binder/device-action/EditExternalAddressScope/EditExternalAddressScopeDeviceAction.d.ts +1 -1
  93. package/lib/types/internal/app-binder/device-action/EditExternalAddressScope/EditExternalAddressScopeDeviceAction.d.ts.map +1 -1
  94. package/lib/types/internal/app-binder/device-action/RegisterExternalAddress/RegisterExternalAddressDeviceAction.d.ts +1 -1
  95. package/lib/types/internal/app-binder/device-action/RegisterExternalAddress/RegisterExternalAddressDeviceAction.d.ts.map +1 -1
  96. package/lib/types/internal/app-binder/model/contactsConstants.d.ts +2 -0
  97. package/lib/types/internal/app-binder/model/contactsConstants.d.ts.map +1 -1
  98. package/lib/types/internal/app-binder/services/provideContact.d.ts +15 -0
  99. package/lib/types/internal/app-binder/services/provideContact.d.ts.map +1 -0
  100. package/lib/types/internal/app-binder/services/provideContact.test.d.ts +2 -0
  101. package/lib/types/internal/app-binder/services/provideContact.test.d.ts.map +1 -0
  102. package/lib/types/internal/app-binder/task/SendRegisterIdentityTask.d.ts.map +1 -1
  103. package/lib/types/internal/app-binder/task/SendRenameContactTask.d.ts.map +1 -1
  104. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  105. package/package.json +6 -6
  106. package/lib/cjs/internal/app-binder/isContactsSupportedForSession.js +0 -2
  107. package/lib/cjs/internal/app-binder/isContactsSupportedForSession.js.map +0 -7
  108. package/lib/cjs/internal/app-binder/isContactsSupportedForSession.test.js +0 -2
  109. package/lib/cjs/internal/app-binder/isContactsSupportedForSession.test.js.map +0 -7
  110. package/lib/esm/internal/app-binder/isContactsSupportedForSession.js +0 -2
  111. package/lib/esm/internal/app-binder/isContactsSupportedForSession.js.map +0 -7
  112. package/lib/esm/internal/app-binder/isContactsSupportedForSession.test.js +0 -2
  113. package/lib/esm/internal/app-binder/isContactsSupportedForSession.test.js.map +0 -7
  114. package/lib/types/internal/app-binder/isContactsSupportedForSession.d.ts.map +0 -1
  115. package/lib/types/internal/app-binder/isContactsSupportedForSession.test.d.ts +0 -2
  116. package/lib/types/internal/app-binder/isContactsSupportedForSession.test.d.ts.map +0 -1
package/README.md CHANGED
@@ -94,7 +94,8 @@ consume them without duplicating the values:
94
94
  ```ts
95
95
  import {
96
96
  CONTACTS_VERSION_REQUIREMENTS,
97
- isContactsSupported,
97
+ ETHEREUM_APP_NAME,
98
+ isVersionAtLeast,
98
99
  resolveContactsVersionRequirements,
99
100
  } from "@ledgerhq/device-contacts-kit";
100
101
 
@@ -102,17 +103,25 @@ import {
102
103
  const requirement = resolveContactsVersionRequirements(deviceModelId);
103
104
  // { supported: true, minOsVersion, minAppVersion: { Ethereum } } | { supported: false }
104
105
 
105
- // Or evaluate support directly.
106
- const supported = isContactsSupported({
107
- deviceModelId,
108
- osVersion,
109
- appName,
110
- appVersion,
111
- });
106
+ if (requirement.supported) {
107
+ // OS-owned operations, e.g. renaming a contact from the dashboard.
108
+ const osReady = isVersionAtLeast(osVersion, requirement.minOsVersion);
109
+
110
+ // App-owned operations, e.g. registering an external address.
111
+ const minAppVersion = requirement.minAppVersion[ETHEREUM_APP_NAME];
112
+ const appReady =
113
+ minAppVersion !== undefined && isVersionAtLeast(appVersion, minAppVersion);
114
+ }
112
115
  ```
113
116
 
114
- There are two independent axes: `minOsVersion` gates OS-owned operations (served by the device OS,
115
- e.g. renaming a contact from the dashboard) and `minAppVersion` gates app-owned operations (served
116
- by the embedded app, keyed by app name — v1 ships Ethereum only). The `isContactsSupported` helper
117
- and the raw `CONTACTS_VERSION_REQUIREMENTS` table are pure and dependency-light, so a host such as
118
- Ledger Wallet can import either to compose its own app-readiness checks.
117
+ The two axes are checked independently, never as one combined verdict: `minOsVersion` gates
118
+ OS-owned operations (served by the device OS, e.g. renaming a contact from the dashboard) and
119
+ `minAppVersion` gates app-owned operations (served by the embedded app, keyed by app name — v1
120
+ ships Ethereum only). A device can satisfy one and not the other, and each Contacts operation
121
+ depends on exactly one of them, so collapsing them into a single "is Contacts supported" answer
122
+ would reject devices that can serve the operation the host actually wants.
123
+
124
+ `isVersionAtLeast` and the raw `CONTACTS_VERSION_REQUIREMENTS` table are pure and
125
+ dependency-light, so a host such as Ledger Wallet can import either to compose its own
126
+ app-readiness checks. Version comparison ignores prerelease and build tags, so a device on a
127
+ release candidate of a minimum (`1.7.0-rc2` against a `1.7.0` minimum) counts as meeting it.
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var E=(r,t)=>{for(var d in t)p(r,d,{get:t[d],enumerable:!0})},y=(r,t,d,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of i(t))!A.call(r,n)&&n!==d&&p(r,n,{get:()=>t[n],enumerable:!(s=o(t,n))||s.enumerable});return r};var u=r=>y(p({},"__esModule",{value:!0}),r);var x={};E(x,{CONTACTS_VERSION_REQUIREMENTS:()=>e.CONTACTS_VERSION_REQUIREMENTS,ContactsManagerBuilder:()=>a.ContactsManagerBuilder,ETHEREUM_APP_NAME:()=>e.ETHEREUM_APP_NAME,isContactsSupported:()=>e.isContactsSupported,isVersionAtLeast:()=>e.isVersionAtLeast,resolveContactsVersionRequirements:()=>e.resolveContactsVersionRequirements});module.exports=u(x);var a=require("./ContactsManagerBuilder"),e=require("./model/ContactsVersionRequirements");0&&(module.exports={CONTACTS_VERSION_REQUIREMENTS,ContactsManagerBuilder,ETHEREUM_APP_NAME,isContactsSupported,isVersionAtLeast,resolveContactsVersionRequirements});
1
+ "use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var y=(r,e)=>{for(var n in e)o(r,n,{get:e[n],enumerable:!0})},u=(r,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of A(e))!E.call(r,d)&&d!==n&&o(r,d,{get:()=>e[d],enumerable:!(s=i(e,d))||s.enumerable});return r};var x=r=>u(o({},"__esModule",{value:!0}),r);var l={};y(l,{CONTACTS_VERSION_REQUIREMENTS:()=>t.CONTACTS_VERSION_REQUIREMENTS,ContactsManagerBuilder:()=>a.ContactsManagerBuilder,ETHEREUM_APP_NAME:()=>t.ETHEREUM_APP_NAME,buildProvideContactPayload:()=>p.buildProvideContactPayload,isVersionAtLeast:()=>t.isVersionAtLeast,resolveContactsVersionRequirements:()=>t.resolveContactsVersionRequirements,sendProvideContactPayload:()=>p.sendProvideContactPayload});module.exports=x(l);var a=require("./ContactsManagerBuilder"),t=require("./model/ContactsVersionRequirements"),p=require("../internal/app-binder/services/provideContact");0&&(module.exports={CONTACTS_VERSION_REQUIREMENTS,ContactsManagerBuilder,ETHEREUM_APP_NAME,buildProvideContactPayload,isVersionAtLeast,resolveContactsVersionRequirements,sendProvideContactPayload});
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/api/index.ts"],
4
- "sourcesContent": ["export {\n type EditExternalAddressIdentifierDAError,\n type EditExternalAddressIdentifierDAInput,\n type EditExternalAddressIdentifierDAIntermediateValue,\n type EditExternalAddressIdentifierDAOutput,\n type EditExternalAddressIdentifierDARequiredInteraction,\n type EditExternalAddressIdentifierDAReturnType,\n type EditExternalAddressIdentifierDAState,\n} from \"@api/app-binder/EditExternalAddressIdentifierDeviceActionTypes\";\nexport {\n type EditExternalAddressScopeDAError,\n type EditExternalAddressScopeDAInput,\n type EditExternalAddressScopeDAIntermediateValue,\n type EditExternalAddressScopeDAOutput,\n type EditExternalAddressScopeDARequiredInteraction,\n type EditExternalAddressScopeDAReturnType,\n type EditExternalAddressScopeDAState,\n} from \"@api/app-binder/EditExternalAddressScopeDeviceActionTypes\";\nexport {\n type RegisterExternalAddressDAError,\n type RegisterExternalAddressDAInput,\n type RegisterExternalAddressDAIntermediateValue,\n type RegisterExternalAddressDAOutput,\n type RegisterExternalAddressDARequiredInteraction,\n type RegisterExternalAddressDAReturnType,\n type RegisterExternalAddressDAState,\n} from \"@api/app-binder/RegisterExternalAddressDeviceActionTypes\";\nexport {\n type RenameContactDAError,\n type RenameContactDAInput,\n type RenameContactDAIntermediateValue,\n type RenameContactDAOutput,\n type RenameContactDARequiredInteraction,\n type RenameContactDAReturnType,\n type RenameContactDAState,\n} from \"@api/app-binder/RenameContactDeviceActionTypes\";\nexport { type ContactsManager } from \"@api/ContactsManager\";\nexport { ContactsManagerBuilder } from \"@api/ContactsManagerBuilder\";\nexport {\n CONTACTS_VERSION_REQUIREMENTS,\n type ContactsModelRequirement,\n type ContactsModelSupport,\n type ContactsModelUnsupported,\n type ContactsSupportQuery,\n type ContactsVersionRequirements,\n ETHEREUM_APP_NAME,\n isContactsSupported,\n isVersionAtLeast,\n resolveContactsVersionRequirements,\n} from \"@api/model/ContactsVersionRequirements\";\nexport {\n type EditExternalAddressIdentifierInput,\n type EditExternalAddressIdentifierOutput,\n} from \"@api/model/EditExternalAddressIdentifier\";\nexport {\n type EditExternalAddressScopeInput,\n type EditExternalAddressScopeOutput,\n} from \"@api/model/EditExternalAddressScope\";\nexport {\n type ExistingContactGroup,\n type RegisterExternalAddressInput,\n type RegisterExternalAddressMode,\n type RegisterExternalAddressOutput,\n} from \"@api/model/RegisterExternalAddress\";\nexport {\n type RenameContactInput,\n type RenameContactOutput,\n} from \"@api/model/RenameContact\";\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oVAAAE,EAAAF,GAqCA,IAAAG,EAAuC,uCACvCC,EAWO",
6
- "names": ["api_exports", "__export", "__toCommonJS", "import_ContactsManagerBuilder", "import_ContactsVersionRequirements"]
4
+ "sourcesContent": ["export {\n type EditExternalAddressIdentifierDAError,\n type EditExternalAddressIdentifierDAInput,\n type EditExternalAddressIdentifierDAIntermediateValue,\n type EditExternalAddressIdentifierDAOutput,\n type EditExternalAddressIdentifierDARequiredInteraction,\n type EditExternalAddressIdentifierDAReturnType,\n type EditExternalAddressIdentifierDAState,\n} from \"@api/app-binder/EditExternalAddressIdentifierDeviceActionTypes\";\nexport {\n type EditExternalAddressScopeDAError,\n type EditExternalAddressScopeDAInput,\n type EditExternalAddressScopeDAIntermediateValue,\n type EditExternalAddressScopeDAOutput,\n type EditExternalAddressScopeDARequiredInteraction,\n type EditExternalAddressScopeDAReturnType,\n type EditExternalAddressScopeDAState,\n} from \"@api/app-binder/EditExternalAddressScopeDeviceActionTypes\";\nexport {\n type RegisterExternalAddressDAError,\n type RegisterExternalAddressDAInput,\n type RegisterExternalAddressDAIntermediateValue,\n type RegisterExternalAddressDAOutput,\n type RegisterExternalAddressDARequiredInteraction,\n type RegisterExternalAddressDAReturnType,\n type RegisterExternalAddressDAState,\n} from \"@api/app-binder/RegisterExternalAddressDeviceActionTypes\";\nexport {\n type RenameContactDAError,\n type RenameContactDAInput,\n type RenameContactDAIntermediateValue,\n type RenameContactDAOutput,\n type RenameContactDARequiredInteraction,\n type RenameContactDAReturnType,\n type RenameContactDAState,\n} from \"@api/app-binder/RenameContactDeviceActionTypes\";\nexport { type ContactsManager } from \"@api/ContactsManager\";\nexport { ContactsManagerBuilder } from \"@api/ContactsManagerBuilder\";\nexport {\n CONTACTS_VERSION_REQUIREMENTS,\n type ContactsModelRequirement,\n type ContactsModelSupport,\n type ContactsModelUnsupported,\n type ContactsVersionRequirements,\n ETHEREUM_APP_NAME,\n isVersionAtLeast,\n resolveContactsVersionRequirements,\n} from \"@api/model/ContactsVersionRequirements\";\nexport {\n type EditExternalAddressIdentifierInput,\n type EditExternalAddressIdentifierOutput,\n} from \"@api/model/EditExternalAddressIdentifier\";\nexport {\n type EditExternalAddressScopeInput,\n type EditExternalAddressScopeOutput,\n} from \"@api/model/EditExternalAddressScope\";\nexport { type ProvideContactInput } from \"@api/model/ProvideContact\";\nexport {\n type ExistingContactGroup,\n type RegisterExternalAddressInput,\n type RegisterExternalAddressMode,\n type RegisterExternalAddressOutput,\n} from \"@api/model/RegisterExternalAddress\";\nexport {\n type RenameContactInput,\n type RenameContactOutput,\n} from \"@api/model/RenameContact\";\nexport { type ContactsErrorCodes } from \"@internal/app-binder/model/contactsErrors\";\nexport {\n buildProvideContactPayload,\n sendProvideContactPayload,\n type SendProvideContactPayloadArgs,\n} from \"@internal/app-binder/services/provideContact\";\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4ZAAAE,EAAAF,GAqCA,IAAAG,EAAuC,uCACvCC,EASO,kDAqBPC,EAIO",
6
+ "names": ["api_exports", "__export", "__toCommonJS", "import_ContactsManagerBuilder", "import_ContactsVersionRequirements", "import_provideContact"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var R=(e,o)=>{for(var n in o)d(e,n,{get:o[n],enumerable:!0})},S=(e,o,n,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of M(o))!N.call(e,r)&&r!==n&&d(e,r,{get:()=>o[r],enumerable:!(s=E(o,r))||s.enumerable});return e};var _=e=>S(d({},"__esModule",{value:!0}),e);var C={};R(C,{CONTACTS_VERSION_REQUIREMENTS:()=>V,ETHEREUM_APP_NAME:()=>i,isContactsSupported:()=>f,isVersionAtLeast:()=>c,resolveContactsVersionRequirements:()=>m});module.exports=_(C);var p=require("@ledgerhq/device-management-kit"),t=require("semver");const i="Ethereum",u={supported:!1},A="1.5.0",O="1.2.0",y="0.9.0",a="1.15.0",V={[p.DeviceModelId.NANO_S]:u,[p.DeviceModelId.NANO_SP]:u,[p.DeviceModelId.NANO_X]:u,[p.DeviceModelId.STAX]:{supported:!0,minOsVersion:A,minAppVersion:{[i]:a}},[p.DeviceModelId.FLEX]:{supported:!0,minOsVersion:O,minAppVersion:{[i]:a}},[p.DeviceModelId.APEX]:{supported:!0,minOsVersion:y,minAppVersion:{[i]:a}}};function m(e){return V[e]}function c(e,o){const n=(0,t.valid)(e)??(0,t.valid)((0,t.coerce)(e)),s=(0,t.valid)(o)??(0,t.valid)((0,t.coerce)(o));return n===null||s===null?!1:(0,t.gte)(n,s)}function f({deviceModelId:e,osVersion:o,appName:n,appVersion:s}){const r=m(e);if(!r.supported||!c(o,r.minOsVersion))return!1;const l=r.minAppVersion[n];return l===void 0?!1:c(s,l)}0&&(module.exports={CONTACTS_VERSION_REQUIREMENTS,ETHEREUM_APP_NAME,isContactsSupported,isVersionAtLeast,resolveContactsVersionRequirements});
1
+ "use strict";var u=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var O=(e,o)=>{for(var n in o)u(e,n,{get:o[n],enumerable:!0})},a=(e,o,n,p)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of N(o))!_.call(e,i)&&i!==n&&u(e,i,{get:()=>o[i],enumerable:!(p=l(o,i))||p.enumerable});return e};var m=e=>a(u({},"__esModule",{value:!0}),e);var y={};O(y,{CONTACTS_VERSION_REQUIREMENTS:()=>c,ETHEREUM_APP_NAME:()=>s,isVersionAtLeast:()=>C,resolveContactsVersionRequirements:()=>I});module.exports=m(y);var r=require("@ledgerhq/device-management-kit"),t=require("semver");const s="Ethereum",E={supported:!1},V="1.11.0",R="1.7.0",S="1.2.0",M="2.8.0",A="1.7.0",d="1.23.0",c={[r.DeviceModelId.NANO_S]:E,[r.DeviceModelId.NANO_SP]:{supported:!0,minOsVersion:A,minAppVersion:{[s]:d}},[r.DeviceModelId.NANO_X]:{supported:!0,minOsVersion:M,minAppVersion:{[s]:d}},[r.DeviceModelId.STAX]:{supported:!0,minOsVersion:V,minAppVersion:{[s]:d}},[r.DeviceModelId.FLEX]:{supported:!0,minOsVersion:R,minAppVersion:{[s]:d}},[r.DeviceModelId.APEX]:{supported:!0,minOsVersion:S,minAppVersion:{[s]:d}}};function I(e){return c[e]}function C(e,o){const n=(0,t.valid)((0,t.coerce)(e)),p=(0,t.valid)((0,t.coerce)(o));return n===null||p===null?!1:(0,t.gte)(n,p)}0&&(module.exports={CONTACTS_VERSION_REQUIREMENTS,ETHEREUM_APP_NAME,isVersionAtLeast,resolveContactsVersionRequirements});
2
2
  //# sourceMappingURL=ContactsVersionRequirements.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/model/ContactsVersionRequirements.ts"],
4
- "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { coerce, gte, valid } from \"semver\";\n\n/**\n * Version requirements for a device model on which Contacts (Address Book)\n * operations are supported.\n *\n * Contacts has two independent version axes:\n * - `minOsVersion` gates OS-owned operations (e.g. renaming a contact from the\n * device dashboard), which are served by the device OS.\n * - `minAppVersion` gates app-owned operations (registering / editing external\n * addresses and Ledger accounts), which are served by the embedded app. It is\n * keyed by app name because the required version differs per app; v1 ships\n * Ethereum only.\n */\nexport type ContactsModelSupport = {\n readonly supported: true;\n readonly minOsVersion: string;\n readonly minAppVersion: Readonly<Record<string, string>>;\n};\n\n/** Marks a device model on which Contacts is not supported at all. */\nexport type ContactsModelUnsupported = {\n readonly supported: false;\n};\n\nexport type ContactsModelRequirement =\n | ContactsModelSupport\n | ContactsModelUnsupported;\n\n/**\n * The full, static Contacts version-requirement table, keyed by device model.\n * Serializable plain data with no runtime dependencies, so hosts (e.g. Ledger\n * Wallet) can import and consume it directly when composing their own\n * app-readiness checks, without duplicating the values.\n */\nexport type ContactsVersionRequirements = Readonly<\n Record<DeviceModelId, ContactsModelRequirement>\n>;\n\n/** The name of the Ethereum embedded app (the only app supported in v1). */\nexport const ETHEREUM_APP_NAME = \"Ethereum\";\n\nconst UNSUPPORTED: ContactsModelUnsupported = { supported: false };\n\n// TODO(DSDK-1376): replace these placeholder versions with the real minimums\n// confirmed by the firmware and Ethereum-app owners. The shape and consumers\n// are final; only the version strings below are provisional.\nconst MIN_OS_VERSION_STAX = \"1.5.0\";\nconst MIN_OS_VERSION_FLEX = \"1.2.0\";\nconst MIN_OS_VERSION_APEX = \"0.9.0\";\nconst MIN_ETHEREUM_APP_VERSION = \"1.15.0\";\n\n/**\n * Contacts APDUs are supported only on the touchscreen device models (Stax,\n * Flex, Apex). The Nano models do not support Contacts at all.\n */\nexport const CONTACTS_VERSION_REQUIREMENTS: ContactsVersionRequirements = {\n [DeviceModelId.NANO_S]: UNSUPPORTED,\n [DeviceModelId.NANO_SP]: UNSUPPORTED,\n [DeviceModelId.NANO_X]: UNSUPPORTED,\n [DeviceModelId.STAX]: {\n supported: true,\n minOsVersion: MIN_OS_VERSION_STAX,\n minAppVersion: { [ETHEREUM_APP_NAME]: MIN_ETHEREUM_APP_VERSION },\n },\n [DeviceModelId.FLEX]: {\n supported: true,\n minOsVersion: MIN_OS_VERSION_FLEX,\n minAppVersion: { [ETHEREUM_APP_NAME]: MIN_ETHEREUM_APP_VERSION },\n },\n [DeviceModelId.APEX]: {\n supported: true,\n minOsVersion: MIN_OS_VERSION_APEX,\n minAppVersion: { [ETHEREUM_APP_NAME]: MIN_ETHEREUM_APP_VERSION },\n },\n};\n\n/**\n * Resolve the Contacts version requirements for a device model \u2014 i.e. the\n * minimum supported OS and app versions, or that the model is unsupported.\n */\nexport function resolveContactsVersionRequirements(\n deviceModelId: DeviceModelId,\n): ContactsModelRequirement {\n return CONTACTS_VERSION_REQUIREMENTS[deviceModelId];\n}\n\n/**\n * Whether `actual` is greater than or equal to `minimum`, comparing as semver.\n * Tolerant of non-strict version strings (coerces where possible) and returns\n * `false` (i.e. requirement not met) when either version cannot be parsed, so\n * an unknown version never passes a check.\n */\nexport function isVersionAtLeast(actual: string, minimum: string): boolean {\n const a = valid(actual) ?? valid(coerce(actual));\n const b = valid(minimum) ?? valid(coerce(minimum));\n if (a === null || b === null) return false;\n return gte(a, b);\n}\n\n/** Inputs for {@link isContactsSupported}. */\nexport type ContactsSupportQuery = {\n readonly deviceModelId: DeviceModelId;\n /** The device OS (firmware) version. */\n readonly osVersion: string;\n /** The name of the currently running embedded app. */\n readonly appName: string;\n /** The version of the currently running embedded app. */\n readonly appVersion: string;\n};\n\n/**\n * Whether Contacts app-owned operations are supported for the given device\n * model, OS version, and running app \u2014 checking the model is supported, the OS\n * meets its minimum, the app is known to Contacts, and the app meets its\n * minimum.\n *\n * Pure and dependency-light: hosts can call this directly, or read\n * {@link CONTACTS_VERSION_REQUIREMENTS} to build their own checks.\n */\nexport function isContactsSupported({\n deviceModelId,\n osVersion,\n appName,\n appVersion,\n}: ContactsSupportQuery): boolean {\n const requirement = resolveContactsVersionRequirements(deviceModelId);\n if (!requirement.supported) return false;\n if (!isVersionAtLeast(osVersion, requirement.minOsVersion)) return false;\n\n const minAppVersion = requirement.minAppVersion[appName];\n if (minAppVersion === undefined) return false;\n return isVersionAtLeast(appVersion, minAppVersion);\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,EAAA,sBAAAC,EAAA,wBAAAC,EAAA,qBAAAC,EAAA,uCAAAC,IAAA,eAAAC,EAAAP,GAAA,IAAAQ,EAA8B,2CAC9BC,EAAmC,kBAwC5B,MAAMN,EAAoB,WAE3BO,EAAwC,CAAE,UAAW,EAAM,EAK3DC,EAAsB,QACtBC,EAAsB,QACtBC,EAAsB,QACtBC,EAA2B,SAMpBZ,EAA6D,CACxE,CAAC,gBAAc,MAAM,EAAGQ,EACxB,CAAC,gBAAc,OAAO,EAAGA,EACzB,CAAC,gBAAc,MAAM,EAAGA,EACxB,CAAC,gBAAc,IAAI,EAAG,CACpB,UAAW,GACX,aAAcC,EACd,cAAe,CAAE,CAACR,CAAiB,EAAGW,CAAyB,CACjE,EACA,CAAC,gBAAc,IAAI,EAAG,CACpB,UAAW,GACX,aAAcF,EACd,cAAe,CAAE,CAACT,CAAiB,EAAGW,CAAyB,CACjE,EACA,CAAC,gBAAc,IAAI,EAAG,CACpB,UAAW,GACX,aAAcD,EACd,cAAe,CAAE,CAACV,CAAiB,EAAGW,CAAyB,CACjE,CACF,EAMO,SAASR,EACdS,EAC0B,CAC1B,OAAOb,EAA8Ba,CAAa,CACpD,CAQO,SAASV,EAAiBW,EAAgBC,EAA0B,CACzE,MAAMC,KAAI,SAAMF,CAAM,MAAK,YAAM,UAAOA,CAAM,CAAC,EACzCG,KAAI,SAAMF,CAAO,MAAK,YAAM,UAAOA,CAAO,CAAC,EACjD,OAAIC,IAAM,MAAQC,IAAM,KAAa,MAC9B,OAAID,EAAGC,CAAC,CACjB,CAsBO,SAASf,EAAoB,CAClC,cAAAW,EACA,UAAAK,EACA,QAAAC,EACA,WAAAC,CACF,EAAkC,CAChC,MAAMC,EAAcjB,EAAmCS,CAAa,EAEpE,GADI,CAACQ,EAAY,WACb,CAAClB,EAAiBe,EAAWG,EAAY,YAAY,EAAG,MAAO,GAEnE,MAAMC,EAAgBD,EAAY,cAAcF,CAAO,EACvD,OAAIG,IAAkB,OAAkB,GACjCnB,EAAiBiB,EAAYE,CAAa,CACnD",
6
- "names": ["ContactsVersionRequirements_exports", "__export", "CONTACTS_VERSION_REQUIREMENTS", "ETHEREUM_APP_NAME", "isContactsSupported", "isVersionAtLeast", "resolveContactsVersionRequirements", "__toCommonJS", "import_device_management_kit", "import_semver", "UNSUPPORTED", "MIN_OS_VERSION_STAX", "MIN_OS_VERSION_FLEX", "MIN_OS_VERSION_APEX", "MIN_ETHEREUM_APP_VERSION", "deviceModelId", "actual", "minimum", "a", "b", "osVersion", "appName", "appVersion", "requirement", "minAppVersion"]
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { coerce, gte, valid } from \"semver\";\n\n/**\n * Version requirements for a device model on which Contacts (Address Book)\n * operations are supported.\n *\n * Contacts has two independent version axes:\n * - `minOsVersion` gates OS-owned operations (e.g. renaming a contact from the\n * device dashboard), which are served by the device OS.\n * - `minAppVersion` gates app-owned operations (registering / editing external\n * addresses and Ledger accounts), which are served by the embedded app. It is\n * keyed by app name because the required version differs per app; v1 ships\n * Ethereum only.\n */\nexport type ContactsModelSupport = {\n readonly supported: true;\n readonly minOsVersion: string;\n readonly minAppVersion: Readonly<Record<string, string>>;\n};\n\n/** Marks a device model on which Contacts is not supported at all. */\nexport type ContactsModelUnsupported = {\n readonly supported: false;\n};\n\nexport type ContactsModelRequirement =\n | ContactsModelSupport\n | ContactsModelUnsupported;\n\n/**\n * The full, static Contacts version-requirement table, keyed by device model.\n * Serializable plain data with no runtime dependencies, so hosts (e.g. Ledger\n * Wallet) can import and consume it directly when composing their own\n * app-readiness checks, without duplicating the values.\n */\nexport type ContactsVersionRequirements = Readonly<\n Record<DeviceModelId, ContactsModelRequirement>\n>;\n\n/** The name of the Ethereum embedded app (the only app supported in v1). */\nexport const ETHEREUM_APP_NAME = \"Ethereum\";\n\nconst UNSUPPORTED: ContactsModelUnsupported = { supported: false };\n\nconst MIN_OS_VERSION_STAX = \"1.11.0\";\nconst MIN_OS_VERSION_FLEX = \"1.7.0\";\nconst MIN_OS_VERSION_APEX = \"1.2.0\";\nconst MIN_OS_VERSION_NANO_X = \"2.8.0\";\nconst MIN_OS_VERSION_NANO_SP = \"1.7.0\";\n\nconst MIN_ETHEREUM_APP_VERSION = \"1.23.0\";\n\n/**\n * Contacts APDUs are supported on the touchscreen device models (Stax, Flex,\n * Apex) and on Nano X / Nano SP. Nano S does not support Contacts at all.\n */\nexport const CONTACTS_VERSION_REQUIREMENTS: ContactsVersionRequirements = {\n [DeviceModelId.NANO_S]: UNSUPPORTED,\n [DeviceModelId.NANO_SP]: {\n supported: true,\n minOsVersion: MIN_OS_VERSION_NANO_SP,\n minAppVersion: { [ETHEREUM_APP_NAME]: MIN_ETHEREUM_APP_VERSION },\n },\n [DeviceModelId.NANO_X]: {\n supported: true,\n minOsVersion: MIN_OS_VERSION_NANO_X,\n minAppVersion: { [ETHEREUM_APP_NAME]: MIN_ETHEREUM_APP_VERSION },\n },\n [DeviceModelId.STAX]: {\n supported: true,\n minOsVersion: MIN_OS_VERSION_STAX,\n minAppVersion: { [ETHEREUM_APP_NAME]: MIN_ETHEREUM_APP_VERSION },\n },\n [DeviceModelId.FLEX]: {\n supported: true,\n minOsVersion: MIN_OS_VERSION_FLEX,\n minAppVersion: { [ETHEREUM_APP_NAME]: MIN_ETHEREUM_APP_VERSION },\n },\n [DeviceModelId.APEX]: {\n supported: true,\n minOsVersion: MIN_OS_VERSION_APEX,\n minAppVersion: { [ETHEREUM_APP_NAME]: MIN_ETHEREUM_APP_VERSION },\n },\n};\n\n/**\n * Resolve the Contacts version requirements for a device model \u2014 i.e. the\n * minimum supported OS and app versions, or that the model is unsupported.\n */\nexport function resolveContactsVersionRequirements(\n deviceModelId: DeviceModelId,\n): ContactsModelRequirement {\n return CONTACTS_VERSION_REQUIREMENTS[deviceModelId];\n}\n\n/**\n * Whether `actual` is greater than or equal to `minimum`, comparing as semver.\n * Tolerant of non-strict version strings and prerelease/build tags (coerces\n * both sides, which drops them) so a release candidate such as `1.7.0-rc2`\n * counts as meeting a `1.7.0` minimum. Returns `false` (i.e. requirement not\n * met) when either version cannot be parsed, so an unknown version never\n * passes a check.\n */\nexport function isVersionAtLeast(actual: string, minimum: string): boolean {\n const a = valid(coerce(actual));\n const b = valid(coerce(minimum));\n if (a === null || b === null) return false;\n return gte(a, b);\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,EAAA,sBAAAC,EAAA,qBAAAC,EAAA,uCAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAA8B,2CAC9BC,EAAmC,kBAwC5B,MAAML,EAAoB,WAE3BM,EAAwC,CAAE,UAAW,EAAM,EAE3DC,EAAsB,SACtBC,EAAsB,QACtBC,EAAsB,QACtBC,EAAwB,QACxBC,EAAyB,QAEzBC,EAA2B,SAMpBb,EAA6D,CACxE,CAAC,gBAAc,MAAM,EAAGO,EACxB,CAAC,gBAAc,OAAO,EAAG,CACvB,UAAW,GACX,aAAcK,EACd,cAAe,CAAE,CAACX,CAAiB,EAAGY,CAAyB,CACjE,EACA,CAAC,gBAAc,MAAM,EAAG,CACtB,UAAW,GACX,aAAcF,EACd,cAAe,CAAE,CAACV,CAAiB,EAAGY,CAAyB,CACjE,EACA,CAAC,gBAAc,IAAI,EAAG,CACpB,UAAW,GACX,aAAcL,EACd,cAAe,CAAE,CAACP,CAAiB,EAAGY,CAAyB,CACjE,EACA,CAAC,gBAAc,IAAI,EAAG,CACpB,UAAW,GACX,aAAcJ,EACd,cAAe,CAAE,CAACR,CAAiB,EAAGY,CAAyB,CACjE,EACA,CAAC,gBAAc,IAAI,EAAG,CACpB,UAAW,GACX,aAAcH,EACd,cAAe,CAAE,CAACT,CAAiB,EAAGY,CAAyB,CACjE,CACF,EAMO,SAASV,EACdW,EAC0B,CAC1B,OAAOd,EAA8Bc,CAAa,CACpD,CAUO,SAASZ,EAAiBa,EAAgBC,EAA0B,CACzE,MAAMC,KAAI,YAAM,UAAOF,CAAM,CAAC,EACxBG,KAAI,YAAM,UAAOF,CAAO,CAAC,EAC/B,OAAIC,IAAM,MAAQC,IAAM,KAAa,MAC9B,OAAID,EAAGC,CAAC,CACjB",
6
+ "names": ["ContactsVersionRequirements_exports", "__export", "CONTACTS_VERSION_REQUIREMENTS", "ETHEREUM_APP_NAME", "isVersionAtLeast", "resolveContactsVersionRequirements", "__toCommonJS", "import_device_management_kit", "import_semver", "UNSUPPORTED", "MIN_OS_VERSION_STAX", "MIN_OS_VERSION_FLEX", "MIN_OS_VERSION_APEX", "MIN_OS_VERSION_NANO_X", "MIN_OS_VERSION_NANO_SP", "MIN_ETHEREUM_APP_VERSION", "deviceModelId", "actual", "minimum", "a", "b"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var o=require("@ledgerhq/device-management-kit"),e=require("./ContactsVersionRequirements");const a="0.0.1",p="999.0.0";function n(t){const s=(0,e.resolveContactsVersionRequirements)(t);if(!s.supported)throw new Error(`expected ${t} to be supported in the test fixture`);return s}function r(t){const s=t.minAppVersion[e.ETHEREUM_APP_NAME];if(s===void 0)throw new Error("expected an Ethereum minimum app version in the fixture");return s}describe("ContactsVersionRequirements",()=>{describe("resolveContactsVersionRequirements",()=>{it("marks every device model, supported or not",()=>{for(const t of Object.values(o.DeviceModelId))expect(e.CONTACTS_VERSION_REQUIREMENTS[t]).toBeDefined()}),it("reports Nano models as unsupported",()=>{expect((0,e.resolveContactsVersionRequirements)(o.DeviceModelId.NANO_S)).toEqual({supported:!1}),expect((0,e.resolveContactsVersionRequirements)(o.DeviceModelId.NANO_X)).toEqual({supported:!1})}),it("reports touchscreen models as supported with OS and app minimums",()=>{const t=n(o.DeviceModelId.FLEX);expect(t.minOsVersion).toEqual(expect.any(String)),expect(r(t)).toEqual(expect.any(String))})}),describe("isContactsSupported",()=>{it("returns false for an unsupported device model",()=>{const t=n(o.DeviceModelId.FLEX);expect((0,e.isContactsSupported)({deviceModelId:o.DeviceModelId.NANO_S,osVersion:p,appName:e.ETHEREUM_APP_NAME,appVersion:r(t)})).toBe(!1)}),it("gates on the minimum app version",()=>{const t=n(o.DeviceModelId.FLEX),s=r(t),i={deviceModelId:o.DeviceModelId.FLEX,osVersion:t.minOsVersion,appName:e.ETHEREUM_APP_NAME};expect((0,e.isContactsSupported)({...i,appVersion:a})).toBe(!1),expect((0,e.isContactsSupported)({...i,appVersion:s})).toBe(!0),expect((0,e.isContactsSupported)({...i,appVersion:p})).toBe(!0)}),it("returns false for an app that is unknown to Contacts",()=>{const t=n(o.DeviceModelId.FLEX);expect((0,e.isContactsSupported)({deviceModelId:o.DeviceModelId.FLEX,osVersion:t.minOsVersion,appName:"Bitcoin",appVersion:p})).toBe(!1)}),it("gates on the minimum OS version",()=>{const t=n(o.DeviceModelId.FLEX),s={deviceModelId:o.DeviceModelId.FLEX,appName:e.ETHEREUM_APP_NAME,appVersion:r(t)};expect((0,e.isContactsSupported)({...s,osVersion:a})).toBe(!1),expect((0,e.isContactsSupported)({...s,osVersion:t.minOsVersion})).toBe(!0)})}),describe("isVersionAtLeast",()=>{it("compares versions as semver, inclusive of equality",()=>{expect((0,e.isVersionAtLeast)("1.2.0","1.2.0")).toBe(!0),expect((0,e.isVersionAtLeast)("1.3.0","1.2.0")).toBe(!0),expect((0,e.isVersionAtLeast)("1.1.9","1.2.0")).toBe(!1)}),it("coerces non-strict version strings",()=>{expect((0,e.isVersionAtLeast)("1.2","1.2.0")).toBe(!0)}),it("returns false when a version cannot be parsed",()=>{expect((0,e.isVersionAtLeast)("not-a-version","1.2.0")).toBe(!1),expect((0,e.isVersionAtLeast)("1.2.0","not-a-version")).toBe(!1)})})});
1
+ "use strict";var t=require("@ledgerhq/device-management-kit"),e=require("./ContactsVersionRequirements");describe("ContactsVersionRequirements",()=>{describe("resolveContactsVersionRequirements",()=>{it("marks every device model, supported or not",()=>{for(const s of Object.values(t.DeviceModelId))expect(e.CONTACTS_VERSION_REQUIREMENTS[s]).toBeDefined()}),it("reports Nano S as unsupported",()=>{expect((0,e.resolveContactsVersionRequirements)(t.DeviceModelId.NANO_S)).toEqual({supported:!1})}),it("pins the minimum OS and app versions of every supported model",()=>{const s={[e.ETHEREUM_APP_NAME]:"1.23.0"};expect(e.CONTACTS_VERSION_REQUIREMENTS).toEqual({[t.DeviceModelId.NANO_S]:{supported:!1},[t.DeviceModelId.NANO_SP]:{supported:!0,minOsVersion:"1.7.0",minAppVersion:s},[t.DeviceModelId.NANO_X]:{supported:!0,minOsVersion:"2.8.0",minAppVersion:s},[t.DeviceModelId.STAX]:{supported:!0,minOsVersion:"1.11.0",minAppVersion:s},[t.DeviceModelId.FLEX]:{supported:!0,minOsVersion:"1.7.0",minAppVersion:s},[t.DeviceModelId.APEX]:{supported:!0,minOsVersion:"1.2.0",minAppVersion:s}})})}),describe("isVersionAtLeast",()=>{it("compares versions as semver, inclusive of equality",()=>{expect((0,e.isVersionAtLeast)("1.2.0","1.2.0")).toBe(!0),expect((0,e.isVersionAtLeast)("1.3.0","1.2.0")).toBe(!0),expect((0,e.isVersionAtLeast)("1.1.9","1.2.0")).toBe(!1)}),it("coerces non-strict version strings",()=>{expect((0,e.isVersionAtLeast)("1.2","1.2.0")).toBe(!0)}),it("returns false when a version cannot be parsed",()=>{expect((0,e.isVersionAtLeast)("not-a-version","1.2.0")).toBe(!1),expect((0,e.isVersionAtLeast)("1.2.0","not-a-version")).toBe(!1)}),it("ignores prerelease and build tags when comparing to the minimum",()=>{expect((0,e.isVersionAtLeast)("1.7.0-rc2","1.7.0")).toBe(!0),expect((0,e.isVersionAtLeast)("1.23.0-dev","1.23.0")).toBe(!0)}),it("still fails a minimum strictly above the tagged version's core",()=>{expect((0,e.isVersionAtLeast)("1.6.9-rc5","1.7.0")).toBe(!1)})})});
2
2
  //# sourceMappingURL=ContactsVersionRequirements.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/model/ContactsVersionRequirements.test.ts"],
4
- "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\n\nimport {\n CONTACTS_VERSION_REQUIREMENTS,\n type ContactsModelSupport,\n ETHEREUM_APP_NAME,\n isContactsSupported,\n isVersionAtLeast,\n resolveContactsVersionRequirements,\n} from \"./ContactsVersionRequirements\";\n\nconst BELOW_ANY_VERSION = \"0.0.1\";\nconst ABOVE_ANY_VERSION = \"999.0.0\";\n\nfunction supportOf(modelId: DeviceModelId): ContactsModelSupport {\n const requirement = resolveContactsVersionRequirements(modelId);\n if (!requirement.supported) {\n throw new Error(`expected ${modelId} to be supported in the test fixture`);\n }\n return requirement;\n}\n\nfunction ethAppVersionOf(support: ContactsModelSupport): string {\n const version = support.minAppVersion[ETHEREUM_APP_NAME];\n if (version === undefined) {\n throw new Error(\"expected an Ethereum minimum app version in the fixture\");\n }\n return version;\n}\n\ndescribe(\"ContactsVersionRequirements\", () => {\n describe(\"resolveContactsVersionRequirements\", () => {\n it(\"marks every device model, supported or not\", () => {\n for (const modelId of Object.values(DeviceModelId)) {\n expect(CONTACTS_VERSION_REQUIREMENTS[modelId]).toBeDefined();\n }\n });\n\n it(\"reports Nano models as unsupported\", () => {\n expect(resolveContactsVersionRequirements(DeviceModelId.NANO_S)).toEqual({\n supported: false,\n });\n expect(resolveContactsVersionRequirements(DeviceModelId.NANO_X)).toEqual({\n supported: false,\n });\n });\n\n it(\"reports touchscreen models as supported with OS and app minimums\", () => {\n const flex = supportOf(DeviceModelId.FLEX);\n expect(flex.minOsVersion).toEqual(expect.any(String));\n expect(ethAppVersionOf(flex)).toEqual(expect.any(String));\n });\n });\n\n describe(\"isContactsSupported\", () => {\n it(\"returns false for an unsupported device model\", () => {\n const flex = supportOf(DeviceModelId.FLEX);\n expect(\n isContactsSupported({\n deviceModelId: DeviceModelId.NANO_S,\n osVersion: ABOVE_ANY_VERSION,\n appName: ETHEREUM_APP_NAME,\n appVersion: ethAppVersionOf(flex),\n }),\n ).toBe(false);\n });\n\n // App-version requirement.\n it(\"gates on the minimum app version\", () => {\n const flex = supportOf(DeviceModelId.FLEX);\n const minAppVersion = ethAppVersionOf(flex);\n const base = {\n deviceModelId: DeviceModelId.FLEX,\n osVersion: flex.minOsVersion,\n appName: ETHEREUM_APP_NAME,\n };\n\n expect(\n isContactsSupported({ ...base, appVersion: BELOW_ANY_VERSION }),\n ).toBe(false);\n expect(isContactsSupported({ ...base, appVersion: minAppVersion })).toBe(\n true,\n );\n expect(\n isContactsSupported({ ...base, appVersion: ABOVE_ANY_VERSION }),\n ).toBe(true);\n });\n\n it(\"returns false for an app that is unknown to Contacts\", () => {\n const flex = supportOf(DeviceModelId.FLEX);\n expect(\n isContactsSupported({\n deviceModelId: DeviceModelId.FLEX,\n osVersion: flex.minOsVersion,\n appName: \"Bitcoin\",\n appVersion: ABOVE_ANY_VERSION,\n }),\n ).toBe(false);\n });\n\n // OS-version requirement.\n it(\"gates on the minimum OS version\", () => {\n const flex = supportOf(DeviceModelId.FLEX);\n const base = {\n deviceModelId: DeviceModelId.FLEX,\n appName: ETHEREUM_APP_NAME,\n appVersion: ethAppVersionOf(flex),\n };\n\n expect(\n isContactsSupported({ ...base, osVersion: BELOW_ANY_VERSION }),\n ).toBe(false);\n expect(\n isContactsSupported({ ...base, osVersion: flex.minOsVersion }),\n ).toBe(true);\n });\n });\n\n describe(\"isVersionAtLeast\", () => {\n it(\"compares versions as semver, inclusive of equality\", () => {\n expect(isVersionAtLeast(\"1.2.0\", \"1.2.0\")).toBe(true);\n expect(isVersionAtLeast(\"1.3.0\", \"1.2.0\")).toBe(true);\n expect(isVersionAtLeast(\"1.1.9\", \"1.2.0\")).toBe(false);\n });\n\n it(\"coerces non-strict version strings\", () => {\n expect(isVersionAtLeast(\"1.2\", \"1.2.0\")).toBe(true);\n });\n\n it(\"returns false when a version cannot be parsed\", () => {\n expect(isVersionAtLeast(\"not-a-version\", \"1.2.0\")).toBe(false);\n expect(isVersionAtLeast(\"1.2.0\", \"not-a-version\")).toBe(false);\n });\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAA8B,2CAE9BC,EAOO,yCAEP,MAAMC,EAAoB,QACpBC,EAAoB,UAE1B,SAASC,EAAUC,EAA8C,CAC/D,MAAMC,KAAc,sCAAmCD,CAAO,EAC9D,GAAI,CAACC,EAAY,UACf,MAAM,IAAI,MAAM,YAAYD,CAAO,sCAAsC,EAE3E,OAAOC,CACT,CAEA,SAASC,EAAgBC,EAAuC,CAC9D,MAAMC,EAAUD,EAAQ,cAAc,mBAAiB,EACvD,GAAIC,IAAY,OACd,MAAM,IAAI,MAAM,yDAAyD,EAE3E,OAAOA,CACT,CAEA,SAAS,8BAA+B,IAAM,CAC5C,SAAS,qCAAsC,IAAM,CACnD,GAAG,6CAA8C,IAAM,CACrD,UAAWJ,KAAW,OAAO,OAAO,eAAa,EAC/C,OAAO,gCAA8BA,CAAO,CAAC,EAAE,YAAY,CAE/D,CAAC,EAED,GAAG,qCAAsC,IAAM,CAC7C,UAAO,sCAAmC,gBAAc,MAAM,CAAC,EAAE,QAAQ,CACvE,UAAW,EACb,CAAC,EACD,UAAO,sCAAmC,gBAAc,MAAM,CAAC,EAAE,QAAQ,CACvE,UAAW,EACb,CAAC,CACH,CAAC,EAED,GAAG,mEAAoE,IAAM,CAC3E,MAAMK,EAAON,EAAU,gBAAc,IAAI,EACzC,OAAOM,EAAK,YAAY,EAAE,QAAQ,OAAO,IAAI,MAAM,CAAC,EACpD,OAAOH,EAAgBG,CAAI,CAAC,EAAE,QAAQ,OAAO,IAAI,MAAM,CAAC,CAC1D,CAAC,CACH,CAAC,EAED,SAAS,sBAAuB,IAAM,CACpC,GAAG,gDAAiD,IAAM,CACxD,MAAMA,EAAON,EAAU,gBAAc,IAAI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OAAO,CAAC,EAAE,KAAK,EAAI,EACpD,UAAO,oBAAiB,QAAS,OAAO,CAAC,EAAE,KAAK,EAAK,CACvD,CAAC,EAED,GAAG,qCAAsC,IAAM,CAC7C,UAAO,oBAAiB,MAAO,OAAO,CAAC,EAAE,KAAK,EAAI,CACpD,CAAC,EAED,GAAG,gDAAiD,IAAM,CACxD,UAAO,oBAAiB,gBAAiB,OAAO,CAAC,EAAE,KAAK,EAAK,EAC7D,UAAO,oBAAiB,QAAS,eAAe,CAAC,EAAE,KAAK,EAAK,CAC/D,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_device_management_kit", "import_ContactsVersionRequirements", "BELOW_ANY_VERSION", "ABOVE_ANY_VERSION", "supportOf", "modelId", "requirement", "ethAppVersionOf", "support", "version", "flex", "minAppVersion", "base"]
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\n\nimport {\n CONTACTS_VERSION_REQUIREMENTS,\n ETHEREUM_APP_NAME,\n isVersionAtLeast,\n resolveContactsVersionRequirements,\n} from \"./ContactsVersionRequirements\";\n\ndescribe(\"ContactsVersionRequirements\", () => {\n describe(\"resolveContactsVersionRequirements\", () => {\n it(\"marks every device model, supported or not\", () => {\n for (const modelId of Object.values(DeviceModelId)) {\n expect(CONTACTS_VERSION_REQUIREMENTS[modelId]).toBeDefined();\n }\n });\n\n it(\"reports Nano S as unsupported\", () => {\n expect(resolveContactsVersionRequirements(DeviceModelId.NANO_S)).toEqual({\n supported: false,\n });\n });\n\n // Pins the minimums themselves, not just their shape: each OS version is\n // the release whose changelog introduces the Address Book feature, so a\n // change here has to be a deliberate one, reviewed against that release.\n it(\"pins the minimum OS and app versions of every supported model\", () => {\n const ethereum = { [ETHEREUM_APP_NAME]: \"1.23.0\" };\n\n expect(CONTACTS_VERSION_REQUIREMENTS).toEqual({\n [DeviceModelId.NANO_S]: { supported: false },\n [DeviceModelId.NANO_SP]: {\n supported: true,\n minOsVersion: \"1.7.0\",\n minAppVersion: ethereum,\n },\n [DeviceModelId.NANO_X]: {\n supported: true,\n minOsVersion: \"2.8.0\",\n minAppVersion: ethereum,\n },\n [DeviceModelId.STAX]: {\n supported: true,\n minOsVersion: \"1.11.0\",\n minAppVersion: ethereum,\n },\n [DeviceModelId.FLEX]: {\n supported: true,\n minOsVersion: \"1.7.0\",\n minAppVersion: ethereum,\n },\n [DeviceModelId.APEX]: {\n supported: true,\n minOsVersion: \"1.2.0\",\n minAppVersion: ethereum,\n },\n });\n });\n });\n\n describe(\"isVersionAtLeast\", () => {\n it(\"compares versions as semver, inclusive of equality\", () => {\n expect(isVersionAtLeast(\"1.2.0\", \"1.2.0\")).toBe(true);\n expect(isVersionAtLeast(\"1.3.0\", \"1.2.0\")).toBe(true);\n expect(isVersionAtLeast(\"1.1.9\", \"1.2.0\")).toBe(false);\n });\n\n it(\"coerces non-strict version strings\", () => {\n expect(isVersionAtLeast(\"1.2\", \"1.2.0\")).toBe(true);\n });\n\n it(\"returns false when a version cannot be parsed\", () => {\n expect(isVersionAtLeast(\"not-a-version\", \"1.2.0\")).toBe(false);\n expect(isVersionAtLeast(\"1.2.0\", \"not-a-version\")).toBe(false);\n });\n\n it(\"ignores prerelease and build tags when comparing to the minimum\", () => {\n expect(isVersionAtLeast(\"1.7.0-rc2\", \"1.7.0\")).toBe(true);\n expect(isVersionAtLeast(\"1.23.0-dev\", \"1.23.0\")).toBe(true);\n });\n\n it(\"still fails a minimum strictly above the tagged version's core\", () => {\n expect(isVersionAtLeast(\"1.6.9-rc5\", \"1.7.0\")).toBe(false);\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA8B,2CAE9BC,EAKO,yCAEP,SAAS,8BAA+B,IAAM,CAC5C,SAAS,qCAAsC,IAAM,CACnD,GAAG,6CAA8C,IAAM,CACrD,UAAWC,KAAW,OAAO,OAAO,eAAa,EAC/C,OAAO,gCAA8BA,CAAO,CAAC,EAAE,YAAY,CAE/D,CAAC,EAED,GAAG,gCAAiC,IA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aAAc,QAAQ,CAAC,EAAE,KAAK,EAAI,CAC5D,CAAC,EAED,GAAG,iEAAkE,IAAM,CACzE,UAAO,oBAAiB,YAAa,OAAO,CAAC,EAAE,KAAK,EAAK,CAC3D,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_ContactsVersionRequirements", "modelId", "ethereum"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var l=(n,r,t,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of y(r))!d.call(n,a)&&a!==t&&o(n,a,{get:()=>r[a],enumerable:!(e=i(r,a))||e.enumerable});return n};var c=n=>l(o({},"__esModule",{value:!0}),n);var g={};module.exports=c(g);
2
+ //# sourceMappingURL=ProvideContact.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/api/model/ProvideContact.ts"],
4
+ "sourcesContent": ["/**\n * Everything the device needs to accept a registered external contact as a\n * decoration for an upcoming signing flow: the name-level material shared by\n * the whole contact group, plus the address-level material of the one matched\n * address.\n */\nexport type ProvideContactInput = {\n readonly contactName: string;\n readonly scope: string;\n /** Raw bytes, chain-dependent: a 20-byte address for Ethereum. */\n readonly identifier: Uint8Array;\n readonly groupHandle: Uint8Array;\n readonly hmacProof: Uint8Array;\n readonly hmacRest: Uint8Array;\n /** Lowercase family name, e.g. `\"ethereum\"`. */\n readonly blockchainFamily: string;\n /** Mandatory for Ethereum, omitted for every other family. */\n readonly chainId?: bigint;\n};\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["ProvideContact_exports", "__toCommonJS"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var m=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var u=(r,o)=>{for(var a in o)m(r,a,{get:o[a],enumerable:!0})},A=(r,o,a,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of c(o))!l.call(r,t)&&t!==a&&m(r,t,{get:()=>o[t],enumerable:!(s=i(o,t))||s.enumerable});return r};var y=r=>A(m({},"__esModule",{value:!0}),r);var R={};u(R,{ProvideContactCommand:()=>P});module.exports=y(R);var n=require("@ledgerhq/device-management-kit"),C=require("@ledgerhq/signer-utils"),p=require("purify-ts"),e=require("../../app-binder/model/contactsConstants"),d=require("../../app-binder/model/contactsErrors");class P{name="provideContact";args;errorHelper=new C.CommandErrorHelper(d.CONTACTS_APP_ERRORS,d.contactsCommandErrorFactory);constructor(o){this.args=o}getApdu(){return new n.ApduBuilder({cla:e.CONTACTS_APDU_CLA,ins:e.CONTACTS_APDU_INS,p1:e.SUB_CMD_PROVIDE_CONTACT,p2:this.args.p2}).addBufferToData(this.args.data).build()}parseResponse(o){return p.Maybe.fromNullable(this.errorHelper.getError(o)).orDefaultLazy(()=>(0,n.CommandResultFactory)({data:void 0}))}}0&&(module.exports={ProvideContactCommand});
2
+ //# sourceMappingURL=ProvideContactCommand.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/app-binder/command/ProvideContactCommand.ts"],
4
+ "sourcesContent": ["// Provide Contact \u2014 sub-command P1=0x20 of the address-book APDU (CLA 0xB0 /\n// INS 0x10). Sent before a signing APDU so the device renders a registered\n// contact name in place of the raw recipient address. Caller\n// (sendProvideContactPayload) assembles the TLV, prepends the 2-byte BE total\n// length and slices into <=255B chunks; this command frames one chunk. Every\n// chunk answers with SW=0x9000 and no data \u2014 the outcome is a device-side\n// effect, not a returned value.\n// Protocol: Address Book Final Specifications \u2014 Provide Contact.\nimport {\n type Apdu,\n ApduBuilder,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n} from \"@ledgerhq/device-management-kit\";\nimport { CommandErrorHelper } from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport {\n CONTACTS_APDU_CLA,\n CONTACTS_APDU_INS,\n SUB_CMD_PROVIDE_CONTACT,\n} from \"@internal/app-binder/model/contactsConstants\";\nimport {\n CONTACTS_APP_ERRORS,\n contactsCommandErrorFactory,\n type ContactsErrorCodes,\n} from \"@internal/app-binder/model/contactsErrors\";\n\nexport type ProvideContactCommandArgs = {\n /** One framed chunk built by sendProvideContactPayload. */\n readonly data: Uint8Array;\n /** 0x00 for the first/only chunk, 0x80 for continuation chunks. */\n readonly p2: number;\n};\n\nexport type ProvideContactCommandResponse = void;\n\nexport class ProvideContactCommand\n implements\n Command<\n ProvideContactCommandResponse,\n ProvideContactCommandArgs,\n ContactsErrorCodes\n >\n{\n readonly name = \"provideContact\";\n readonly args: ProvideContactCommandArgs;\n private readonly errorHelper = new CommandErrorHelper<\n ProvideContactCommandResponse,\n ContactsErrorCodes\n >(CONTACTS_APP_ERRORS, contactsCommandErrorFactory);\n\n constructor(args: ProvideContactCommandArgs) {\n this.args = args;\n }\n\n getApdu(): Apdu {\n return new ApduBuilder({\n cla: CONTACTS_APDU_CLA,\n ins: CONTACTS_APDU_INS,\n p1: SUB_CMD_PROVIDE_CONTACT,\n p2: this.args.p2,\n })\n .addBufferToData(this.args.data)\n .build();\n }\n\n parseResponse(\n response: ApduResponse,\n ): CommandResult<ProvideContactCommandResponse, ContactsErrorCodes> {\n return Maybe.fromNullable(\n this.errorHelper.getError(response),\n ).orDefaultLazy(() =>\n CommandResultFactory<ProvideContactCommandResponse, ContactsErrorCodes>({\n data: undefined,\n }),\n );\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAQA,IAAAI,EAOO,2CACPC,EAAmC,kCACnCC,EAAsB,qBAEtBC,EAIO,wDACPC,EAIO,qDAWA,MAAMN,CAOb,CACW,KAAO,iBACP,KACQ,YAAc,IAAI,qBAGjC,sBAAqB,6BAA2B,EAElD,YAAYO,EAAiC,CAC3C,KAAK,KAAOA,CACd,CAEA,SAAgB,CACd,OAAO,IAAI,cAAY,CACrB,IAAK,oBACL,IAAK,oBACL,GAAI,0BACJ,GAAI,KAAK,KAAK,EAChB,CAAC,EACE,gBAAgB,KAAK,KAAK,IAAI,EAC9B,MAAM,CACX,CAEA,cACEC,EACkE,CAClE,OAAO,QAAM,aACX,KAAK,YAAY,SAASA,CAAQ,CACpC,EAAE,cAAc,OACd,wBAAwE,CACtE,KAAM,MACR,CAAC,CACH,CACF,CACF",
6
+ "names": ["ProvideContactCommand_exports", "__export", "ProvideContactCommand", "__toCommonJS", "import_device_management_kit", "import_signer_utils", "import_purify_ts", "import_contactsConstants", "import_contactsErrors", "args", "response"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var r=require("@ledgerhq/device-management-kit"),a=require("../../app-binder/model/contactsErrors"),e=require("./ProvideContactCommand");describe("ProvideContactCommand",()=>{describe("getApdu",()=>{it("wraps the framed chunk under B0 10 20 with P2=0x00 for the first/only chunk",()=>{const t=Uint8Array.from([0,3,170,187,204]),o=new e.ProvideContactCommand({data:t,p2:0}).getApdu();expect(o.getRawApdu()).toStrictEqual(Uint8Array.from([176,16,32,0,5,0,3,170,187,204]))}),it("uses P2=0x80 for continuation chunks",()=>{const t=Uint8Array.from([170,187]),o=new e.ProvideContactCommand({data:t,p2:128}).getApdu();expect(o.getRawApdu()).toStrictEqual(Uint8Array.from([176,16,32,128,2,170,187]))})}),describe("parseResponse",()=>{it("succeeds with no data on SW=0x9000",()=>{const t=new e.ProvideContactCommand({data:new Uint8Array,p2:0}).parseResponse({data:Buffer.from([]),statusCode:Buffer.from([144,0])});expect(t).toStrictEqual({status:r.CommandResultStatus.Success,data:void 0})}),it("maps SW=0x6982 to a seed-mismatch ContactsCommandError",()=>{const t=new e.ProvideContactCommand({data:new Uint8Array,p2:0}).parseResponse({data:Buffer.from([]),statusCode:Buffer.from([105,130])});expect(t.status).toBe(r.CommandResultStatus.Error),t.status===r.CommandResultStatus.Error&&(expect(t.error).toBeInstanceOf(a.ContactsCommandError),expect(t.error.errorCode).toBe(a.CONTACT_SEED_MISMATCH_ERROR_CODE))}),it("maps SW=0x6a80 to a ContactsCommandError",()=>{const t=new e.ProvideContactCommand({data:new Uint8Array,p2:0}).parseResponse({data:Buffer.from([]),statusCode:Buffer.from([106,128])});expect(t.status).toBe(r.CommandResultStatus.Error),t.status===r.CommandResultStatus.Error&&expect(t.error.errorCode).toBe("6a80")})})});
2
+ //# sourceMappingURL=ProvideContactCommand.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/app-binder/command/ProvideContactCommand.test.ts"],
4
+ "sourcesContent": ["import { CommandResultStatus } from \"@ledgerhq/device-management-kit\";\n\nimport {\n CONTACT_SEED_MISMATCH_ERROR_CODE,\n ContactsCommandError,\n} from \"@internal/app-binder/model/contactsErrors\";\n\nimport { ProvideContactCommand } from \"./ProvideContactCommand\";\n\ndescribe(\"ProvideContactCommand\", () => {\n describe(\"getApdu\", () => {\n it(\"wraps the framed chunk under B0 10 20 with P2=0x00 for the first/only chunk\", () => {\n const data = Uint8Array.from([0x00, 0x03, 0xaa, 0xbb, 0xcc]);\n\n const apdu = new ProvideContactCommand({ data, p2: 0x00 }).getApdu();\n\n expect(apdu.getRawApdu()).toStrictEqual(\n Uint8Array.from([\n 0xb0, 0x10, 0x20, 0x00, 0x05, 0x00, 0x03, 0xaa, 0xbb, 0xcc,\n ]),\n );\n });\n\n it(\"uses P2=0x80 for continuation chunks\", () => {\n const data = Uint8Array.from([0xaa, 0xbb]);\n\n const apdu = new ProvideContactCommand({ data, p2: 0x80 }).getApdu();\n\n expect(apdu.getRawApdu()).toStrictEqual(\n Uint8Array.from([0xb0, 0x10, 0x20, 0x80, 0x02, 0xaa, 0xbb]),\n );\n });\n });\n\n describe(\"parseResponse\", () => {\n it(\"succeeds with no data on SW=0x9000\", () => {\n const result = new ProvideContactCommand({\n data: new Uint8Array(),\n p2: 0x00,\n }).parseResponse({\n data: Buffer.from([]),\n statusCode: Buffer.from([0x90, 0x00]),\n });\n\n expect(result).toStrictEqual({\n status: CommandResultStatus.Success,\n data: undefined,\n });\n });\n\n it(\"maps SW=0x6982 to a seed-mismatch ContactsCommandError\", () => {\n const result = new ProvideContactCommand({\n data: new Uint8Array(),\n p2: 0x00,\n }).parseResponse({\n data: Buffer.from([]),\n statusCode: Buffer.from([0x69, 0x82]),\n });\n\n expect(result.status).toBe(CommandResultStatus.Error);\n if (result.status === CommandResultStatus.Error) {\n expect(result.error).toBeInstanceOf(ContactsCommandError);\n expect((result.error as ContactsCommandError).errorCode).toBe(\n CONTACT_SEED_MISMATCH_ERROR_CODE,\n );\n }\n });\n\n it(\"maps SW=0x6a80 to a ContactsCommandError\", () => {\n const result = new ProvideContactCommand({\n data: new Uint8Array(),\n p2: 0x00,\n }).parseResponse({\n data: Buffer.from([]),\n statusCode: Buffer.from([0x6a, 0x80]),\n });\n\n expect(result.status).toBe(CommandResultStatus.Error);\n if (result.status === CommandResultStatus.Error) {\n expect((result.error as ContactsCommandError).errorCode).toBe(\"6a80\");\n }\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAAoC,2CAEpCC,EAGO,qDAEPC,EAAsC,mCAEtC,SAAS,wBAAyB,IAAM,CACtC,SAAS,UAAW,IAAM,CACxB,GAAG,8EAA+E,IAAM,CACtF,MAAMC,EAAO,WAAW,KAAK,CAAC,EAAM,EAAM,IAAM,IAAM,GAAI,CAAC,EAErDC,EAAO,IAAI,wBAAsB,CAAE,KAAAD,EAAM,GAAI,CAAK,CAAC,EAAE,QAAQ,EAEnE,OAAOC,EAAK,WAAW,CAAC,EAAE,cACxB,WAAW,KAAK,CACd,IAAM,GAAM,GAAM,EAAM,EAAM,EAAM,EAAM,IAAM,IAAM,GACxD,CAAC,CACH,CACF,CAAC,EAED,GAAG,uCAAwC,IAAM,CAC/C,MAAMD,EAAO,WAAW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AO,SAAW,sBAAoB,OACxC,OAAQA,EAAO,MAA+B,SAAS,EAAE,KAAK,MAAM,CAExE,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_contactsErrors", "import_ProvideContactCommand", "data", "apdu", "result"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var f=(n,e)=>{for(var t in e)s(n,t,{get:e[t],enumerable:!0})},m=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of d(e))!l.call(n,r)&&r!==t&&s(n,r,{get:()=>e[r],enumerable:!(o=u(e,r))||o.enumerable});return n};var S=n=>m(s({},"__esModule",{value:!0}),n);var C={};f(C,{isContactsAppVersionSupportedForSession:()=>A,isContactsOsSupportedForSession:()=>v});module.exports=S(C);var p=require("@ledgerhq/device-management-kit"),i=require("../../api/model/ContactsVersionRequirements"),c=require("./ContactsApplicationResolver");function a(n){return n.supported}function v(n){const e=n.getDeviceSessionState(),t=(0,i.resolveContactsVersionRequirements)(e.deviceModelId);if(!a(t))return!1;const o="firmwareVersion"in e?e.firmwareVersion?.os:void 0;return o===void 0?!1:(0,i.isVersionAtLeast)(o,t.minOsVersion)}function A(n,e){const t=n.getDeviceSessionState(),o=(0,i.resolveContactsVersionRequirements)(t.deviceModelId);if(!a(o))return!1;const r=o.minAppVersion[e.name];return r===void 0?!1:new p.ApplicationChecker(t,{version:e.version},new c.ContactsApplicationResolver).withMinVersionInclusiveAcceptingPrerelease(r).check()}0&&(module.exports={isContactsAppVersionSupportedForSession,isContactsOsSupportedForSession});
2
+ //# sourceMappingURL=contactsVersionGuards.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/internal/app-binder/contactsVersionGuards.ts"],
4
+ "sourcesContent": ["import {\n ApplicationChecker,\n type InternalApi,\n} from \"@ledgerhq/device-management-kit\";\n\nimport {\n type ContactsModelRequirement,\n type ContactsModelSupport,\n isVersionAtLeast,\n resolveContactsVersionRequirements,\n} from \"@api/model/ContactsVersionRequirements\";\n\nimport { ContactsApplicationResolver } from \"./ContactsApplicationResolver\";\n\n/** The running app's identity, read freshly from the device. */\nexport type RunningApp = {\n readonly name: string;\n readonly version: string;\n};\n\n/** Narrows a resolved requirement to the case where Contacts is supported at all on this device model. */\nfunction isContactsModelSupported(\n requirement: ContactsModelRequirement,\n): requirement is ContactsModelSupport {\n return requirement.supported;\n}\n\n/**\n * OS-only Contacts support check, for internal consumption by dashboard\n * `DeviceAction`s (e.g. Rename Contact, EDIT CONTACT NAME). Dashboard operations\n * are served by the device OS, not the embedded app, so only two dimensions\n * apply:\n * - the device model must be supported;\n * - the device OS must meet its minimum version.\n *\n * The running-app dimension is intentionally skipped: on the dashboard there is\n * no embedded app to gate on (the running \"app\" is BOLOS).\n *\n * @param internalApi - the DeviceAction's internal API for the current session.\n */\nexport function isContactsOsSupportedForSession(\n internalApi: InternalApi,\n): boolean {\n const deviceState = internalApi.getDeviceSessionState();\n const requirement = resolveContactsVersionRequirements(\n deviceState.deviceModelId,\n );\n if (!isContactsModelSupported(requirement)) return false;\n\n const osVersion =\n \"firmwareVersion\" in deviceState\n ? deviceState.firmwareVersion?.os\n : undefined;\n if (osVersion === undefined) return false;\n\n return isVersionAtLeast(osVersion, requirement.minOsVersion);\n}\n\n/**\n * Session-aware Contacts support check, for internal consumption by app-owned\n * Contacts `DeviceAction`s (registering / editing external addresses). These\n * operations are served by the embedded app, not the device OS, so only two\n * dimensions apply:\n * - the device model must be supported;\n * - the running app must be known to Contacts and meet its minimum version.\n *\n * The app `name` and `version` are supplied by the caller so they can come from\n * a fresh `WaitForAppAndVersion` result rather than the (potentially stale)\n * device session state; the model comes from the session state, which does\n * not change under the caller's feet the way the running app can.\n *\n * @param internalApi - the DeviceAction's internal API for the current session.\n * @param app - the running app's fresh name and version.\n */\nexport function isContactsAppVersionSupportedForSession(\n internalApi: InternalApi,\n app: RunningApp,\n): boolean {\n const deviceState = internalApi.getDeviceSessionState();\n const requirement = resolveContactsVersionRequirements(\n deviceState.deviceModelId,\n );\n if (!isContactsModelSupported(requirement)) return false;\n\n const minAppVersion = requirement.minAppVersion[app.name];\n if (minAppVersion === undefined) return false;\n\n return new ApplicationChecker(\n deviceState,\n { version: app.version },\n new ContactsApplicationResolver(),\n )\n .withMinVersionInclusiveAcceptingPrerelease(minAppVersion)\n .check();\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6CAAAE,EAAA,oCAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAGO,2CAEPC,EAKO,kDAEPC,EAA4C,yCAS5C,SAASC,EACPC,EACqC,CACrC,OAAOA,EAAY,SACrB,CAeO,SAASN,EACdO,EACS,CACT,MAAMC,EAAcD,EAAY,sBAAsB,EAChDD,KAAc,sCAClBE,EAAY,aACd,EACA,GAAI,CAACH,EAAyBC,CAAW,EAAG,MAAO,GAEnD,MAAMG,EACJ,oBAAqBD,EACjBA,EAAY,iBAAiB,GAC7B,OACN,OAAIC,IAAc,OAAkB,MAE7B,oBAAiBA,EAAWH,EAAY,YAAY,CAC7D,CAkBO,SAASP,EACdQ,EACAG,EACS,CACT,MAAMF,EAAcD,EAAY,sBAAsB,EAChDD,KAAc,sCAClBE,EAAY,aACd,EACA,GAAI,CAACH,EAAyBC,CAAW,EAAG,MAAO,GAEnD,MAAMK,EAAgBL,EAAY,cAAcI,EAAI,IAAI,EACxD,OAAIC,IAAkB,OAAkB,GAEjC,IAAI,qBACTH,EACA,CAAE,QAASE,EAAI,OAAQ,EACvB,IAAI,6BACN,EACG,2CAA2CC,CAAa,EACxD,MAAM,CACX",
6
+ "names": ["contactsVersionGuards_exports", "__export", "isContactsAppVersionSupportedForSession", "isContactsOsSupportedForSession", "__toCommonJS", "import_device_management_kit", "import_ContactsVersionRequirements", "import_ContactsApplicationResolver", "isContactsModelSupported", "requirement", "internalApi", "deviceState", "osVersion", "app", "minAppVersion"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var n=require("@ledgerhq/device-management-kit"),i=require("../../api/model/ContactsVersionRequirements"),t=require("./contactsVersionGuards");const c=(()=>{const e=(0,i.resolveContactsVersionRequirements)(n.DeviceModelId.FLEX);if(!e.supported)throw new Error("Flex must be supported");return e})(),u=c.minOsVersion,d=(()=>{const e=c.minAppVersion[i.ETHEREUM_APP_NAME];if(e===void 0)throw new Error("Ethereum min version required");return e})(),a="0.0.1";function o({osVersion:e=u,modelId:p=n.DeviceModelId.FLEX}={}){return{sessionStateType:n.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:n.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:i.ETHEREUM_APP_NAME,version:"0.0.0"},deviceModelId:p,firmwareVersion:{mcu:"1.0.0",bootloader:"1.0.0",os:e},isSecureConnectionAllowed:!1}}function s(e){return{getDeviceSessionState:()=>e}}function r(e=i.ETHEREUM_APP_NAME,p=d){return{name:e,version:p}}describe("isContactsAppVersionSupportedForSession",()=>{it("returns true when the model and app version meet the minimums",()=>{const e=s(o());expect((0,t.isContactsAppVersionSupportedForSession)(e,r())).toBe(!0)}),it("returns true regardless of OS version, since app-owned operations are not gated by it",()=>{const e=s(o({osVersion:a}));expect((0,t.isContactsAppVersionSupportedForSession)(e,r())).toBe(!0)}),it("returns false on an unsupported device model",()=>{const e=s(o({modelId:n.DeviceModelId.NANO_S}));expect((0,t.isContactsAppVersionSupportedForSession)(e,r())).toBe(!1)}),it("returns false when the app version is below the minimum",()=>{const e=s(o());expect((0,t.isContactsAppVersionSupportedForSession)(e,r(i.ETHEREUM_APP_NAME,a))).toBe(!1)}),it("returns false when the running app is unknown to Contacts",()=>{const e=s(o());expect((0,t.isContactsAppVersionSupportedForSession)(e,r("Bitcoin"))).toBe(!1)}),it("returns true for a prerelease build of the minimum app version",()=>{const e=s(o());expect((0,t.isContactsAppVersionSupportedForSession)(e,r(i.ETHEREUM_APP_NAME,`${d}-rc2`))).toBe(!0)}),it("returns false when the device session has no running app",()=>{const e=s({sessionStateType:n.DeviceSessionStateType.Connected,deviceStatus:n.DeviceStatus.CONNECTED,deviceModelId:n.DeviceModelId.FLEX});expect((0,t.isContactsAppVersionSupportedForSession)(e,r())).toBe(!1)})});describe("isContactsOsSupportedForSession",()=>{it("returns true when the model and OS version meet the minimums",()=>{const e=s(o());expect((0,t.isContactsOsSupportedForSession)(e)).toBe(!0)}),it("returns false on an unsupported device model",()=>{const e=s(o({modelId:n.DeviceModelId.NANO_S}));expect((0,t.isContactsOsSupportedForSession)(e)).toBe(!1)}),it("returns false when the OS version is below the minimum",()=>{const e=s(o({osVersion:a}));expect((0,t.isContactsOsSupportedForSession)(e)).toBe(!1)}),it("returns true for a release candidate of the minimum OS version",()=>{const e=s(o({osVersion:`${u}-rc2`}));expect((0,t.isContactsOsSupportedForSession)(e)).toBe(!0)}),it("returns false for a release candidate below the minimum OS version",()=>{const e=s(o({osVersion:`${a}-rc2`}));expect((0,t.isContactsOsSupportedForSession)(e)).toBe(!1)}),it("returns false when the device session has no firmware version",()=>{const e=s({sessionStateType:n.DeviceSessionStateType.Connected,deviceStatus:n.DeviceStatus.CONNECTED,deviceModelId:n.DeviceModelId.FLEX});expect((0,t.isContactsOsSupportedForSession)(e)).toBe(!1)})});
2
+ //# sourceMappingURL=contactsVersionGuards.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/internal/app-binder/contactsVersionGuards.test.ts"],
4
+ "sourcesContent": ["import {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n type InternalApi,\n} from \"@ledgerhq/device-management-kit\";\n\nimport {\n ETHEREUM_APP_NAME,\n resolveContactsVersionRequirements,\n} from \"@api/model/ContactsVersionRequirements\";\n\nimport {\n isContactsAppVersionSupportedForSession,\n isContactsOsSupportedForSession,\n type RunningApp,\n} from \"./contactsVersionGuards\";\n\nconst flexSupport = (() => {\n const requirement = resolveContactsVersionRequirements(DeviceModelId.FLEX);\n if (!requirement.supported) throw new Error(\"Flex must be supported\");\n return requirement;\n})();\n\nconst MIN_OS_VERSION = flexSupport.minOsVersion;\nconst MIN_APP_VERSION = (() => {\n const version = flexSupport.minAppVersion[ETHEREUM_APP_NAME];\n if (version === undefined) throw new Error(\"Ethereum min version required\");\n return version;\n})();\nconst BELOW_ANY_VERSION = \"0.0.1\";\n\ntype ReadyStateOptions = {\n osVersion?: string;\n modelId?: DeviceModelId;\n};\n\nfunction createReadyState({\n osVersion = MIN_OS_VERSION,\n modelId = DeviceModelId.FLEX,\n}: ReadyStateOptions = {}) {\n return {\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: ETHEREUM_APP_NAME, version: \"0.0.0\" },\n deviceModelId: modelId,\n firmwareVersion: { mcu: \"1.0.0\", bootloader: \"1.0.0\", os: osVersion },\n isSecureConnectionAllowed: false,\n };\n}\n\nfunction createInternalApi(deviceState: object): InternalApi {\n return {\n getDeviceSessionState: () => deviceState,\n } as unknown as InternalApi;\n}\n\n// The running app identity now comes from the caller (a fresh\n// WaitForAppAndVersion result), not the device session state.\nfunction runningApp(\n name = ETHEREUM_APP_NAME,\n version = MIN_APP_VERSION,\n): RunningApp {\n return { name, version };\n}\n\ndescribe(\"isContactsAppVersionSupportedForSession\", () => {\n it(\"returns true when the model and app version meet the minimums\", () => {\n const api = createInternalApi(createReadyState());\n expect(isContactsAppVersionSupportedForSession(api, runningApp())).toBe(\n true,\n );\n });\n\n it(\"returns true regardless of OS version, since app-owned operations are not gated by it\", () => {\n const api = createInternalApi(\n createReadyState({ osVersion: BELOW_ANY_VERSION }),\n );\n expect(isContactsAppVersionSupportedForSession(api, runningApp())).toBe(\n true,\n );\n });\n\n it(\"returns false on an unsupported device model\", () => {\n const api = createInternalApi(\n createReadyState({ modelId: DeviceModelId.NANO_S }),\n );\n expect(isContactsAppVersionSupportedForSession(api, runningApp())).toBe(\n false,\n );\n });\n\n it(\"returns false when the app version is below the minimum\", () => {\n const api = createInternalApi(createReadyState());\n expect(\n isContactsAppVersionSupportedForSession(\n api,\n runningApp(ETHEREUM_APP_NAME, BELOW_ANY_VERSION),\n ),\n ).toBe(false);\n });\n\n it(\"returns false when the running app is unknown to Contacts\", () => {\n const api = createInternalApi(createReadyState());\n expect(\n isContactsAppVersionSupportedForSession(api, runningApp(\"Bitcoin\")),\n ).toBe(false);\n });\n\n it(\"returns true for a prerelease build of the minimum app version\", () => {\n const api = createInternalApi(createReadyState());\n expect(\n isContactsAppVersionSupportedForSession(\n api,\n runningApp(ETHEREUM_APP_NAME, `${MIN_APP_VERSION}-rc2`),\n ),\n ).toBe(true);\n });\n\n it(\"returns false when the device session has no running app\", () => {\n const api = createInternalApi({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n expect(isContactsAppVersionSupportedForSession(api, runningApp())).toBe(\n false,\n );\n });\n});\n\ndescribe(\"isContactsOsSupportedForSession\", () => {\n it(\"returns true when the model and OS version meet the minimums\", () => {\n const api = createInternalApi(createReadyState());\n expect(isContactsOsSupportedForSession(api)).toBe(true);\n });\n\n it(\"returns false on an unsupported device model\", () => {\n const api = createInternalApi(\n createReadyState({ modelId: DeviceModelId.NANO_S }),\n );\n expect(isContactsOsSupportedForSession(api)).toBe(false);\n });\n\n it(\"returns false when the OS version is below the minimum\", () => {\n const api = createInternalApi(\n createReadyState({ osVersion: BELOW_ANY_VERSION }),\n );\n expect(isContactsOsSupportedForSession(api)).toBe(false);\n });\n\n it(\"returns true for a release candidate of the minimum OS version\", () => {\n const api = createInternalApi(\n createReadyState({ osVersion: `${MIN_OS_VERSION}-rc2` }),\n );\n expect(isContactsOsSupportedForSession(api)).toBe(true);\n });\n\n it(\"returns false for a release candidate below the minimum OS version\", () => {\n const api = createInternalApi(\n createReadyState({ osVersion: `${BELOW_ANY_VERSION}-rc2` }),\n );\n expect(isContactsOsSupportedForSession(api)).toBe(false);\n });\n\n it(\"returns false when the device session has no firmware version\", () => {\n const api = createInternalApi({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n expect(isContactsOsSupportedForSession(api)).toBe(false);\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAKO,2CAEPC,EAGO,kDAEPC,EAIO,mCAEP,MAAMC,GAAe,IAAM,CACzB,MAAMC,KAAc,sCAAmC,gBAAc,IAAI,EACzE,GAAI,CAACA,EAAY,UAAW,MAAM,IAAI,MAAM,wBAAwB,EACpE,OAAOA,CACT,GAAG,EAEGC,EAAiBF,EAAY,aAC7BG,GAAmB,IAAM,CAC7B,MAAMC,EAAUJ,EAAY,cAAc,mBAAiB,EAC3D,GAAII,IAAY,OAAW,MAAM,IAAI,MAAM,+BAA+B,EAC1E,OAAOA,CACT,GAAG,EACGC,EAAoB,QAO1B,SAASC,EAAiB,CACxB,UAAAC,EAAYL,EACZ,QAAAM,EAAU,gBAAc,IAC1B,EAAuB,CAAC,EAAG,CACzB,MAAO,CACL,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,oBAAmB,QAAS,OAAQ,EACxD,cAAeA,EACf,gBAAiB,CAAE,IAAK,QAAS,WAAY,QAAS,GAAID,CAAU,EACpE,0BAA2B,EAC7B,CACF,CAEA,SAASE,EAAkBC,EAAkC,CAC3D,MAAO,CACL,sBAAuB,IAAMA,CAC/B,CACF,CAIA,SAASC,EACPC,EAAO,oBACPR,EAAUD,EACE,CACZ,MAAO,CAAE,KAAAS,EAAM,QAAAR,CAAQ,CACzB,CAEA,SAAS,0CAA2C,IAAM,CACxD,GAAG,gEAAiE,IAAM,CACxE,MAAMS,EAAMJ,EAAkBH,EAAiB,CAAC,EAChD,UAAO,2C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AAC,EAED,GAAG,+CAAgD,IAAM,CACvD,MAAMA,EAAMJ,EACVH,EAAiB,CAAE,QAAS,gBAAc,MAAO,CAAC,CACpD,EACA,UAAO,mCAAgCO,CAAG,CAAC,EAAE,KAAK,EAAK,CACzD,CAAC,EAED,GAAG,yDAA0D,IAAM,CACjE,MAAMA,EAAMJ,EACVH,EAAiB,CAAE,UAAWD,CAAkB,CAAC,CACnD,EACA,UAAO,mCAAgCQ,CAAG,CAAC,EAAE,KAAK,EAAK,CACzD,CAAC,EAED,GAAG,iEAAkE,IAAM,CACzE,MAAMA,EAAMJ,EACVH,EAAiB,CAAE,UAAW,GAAGJ,CAAc,MAAO,CAAC,CACzD,EACA,UAAO,mCAAgCW,CAAG,CAAC,EAAE,KAAK,EAAI,CACxD,CAAC,EAED,GAAG,qEAAsE,IAAM,CAC7E,MAAMA,EAAMJ,EACVH,EAAiB,CAAE,UAAW,GAAGD,CAAiB,MAAO,CAAC,CAC5D,EACA,UAAO,mCAAgCQ,CAAG,CAAC,EAAE,KAAK,EAAK,CACzD,CAAC,EAED,GAAG,gEAAiE,IAAM,CACxE,MAAMA,EAAMJ,EAAkB,CAC5B,iBAAkB,yBAAuB,UACzC,aAAc,eAAa,UAC3B,cAAe,gBAAc,IAC/B,CAAC,EACD,UAAO,mCAAgCI,CAAG,CAAC,EAAE,KAAK,EAAK,CACzD,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_ContactsVersionRequirements", "import_contactsVersionGuards", "flexSupport", "requirement", "MIN_OS_VERSION", "MIN_APP_VERSION", "version", "BELOW_ANY_VERSION", "createReadyState", "osVersion", "modelId", "createInternalApi", "deviceState", "runningApp", "name", "api"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var u=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var g=(d,n)=>{for(var p in n)u(d,p,{get:n[p],enumerable:!0})},D=(d,n,p,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of S(n))!h.call(d,r)&&r!==p&&u(d,r,{get:()=>n[r],enumerable:!(l=m(n,r))||l.enumerable});return d};var x=d=>D(u({},"__esModule",{value:!0}),d);var V={};g(V,{EditExternalAddressIdentifierDeviceAction:()=>y});module.exports=x(V);var a=require("@ledgerhq/device-management-kit"),c=require("purify-ts"),i=require("xstate"),A=require("../../../app-binder/isContactsSupportedForSession"),E=require("../../../app-binder/model/contactsErrors"),I=require("../../../app-binder/task/SendEditExternalAddressIdentifierTask"),f=require("./validateEditExternalAddressIdentifierInput");class y extends a.XStateDeviceAction{makeStateMachine(n){const{isSupported:p,editIdentifier:l}=this.extractDependencies(n),r=this.input.appName;return(0,i.setup)({types:{input:{},context:{},output:{}},actors:{openAppStateMachine:new a.OpenAppDeviceAction({input:{appName:r}}).makeStateMachine(n),waitForAppAndVersionStateMachine:new a.WaitForAppAndVersionDeviceAction({input:{}}).makeStateMachine(n),editIdentifier:(0,i.fromPromise)(({input:e})=>l(e))},guards:{skipOpenApp:({context:e})=>e.input.skipOpenApp===!0,noInternalError:({context:e})=>e._internalState.error===null,contactsSupported:({context:e})=>{const{appAndVersion:t}=e._internalState;return t!==null&&p(t)}},actions:{assignValidationError:(0,i.assign)({_internalState:({context:e})=>{const t=(0,f.validateEditExternalAddressIdentifierInput)(e.input);return t?{...e._internalState,error:t}:e._internalState}}),assignVersionError:(0,i.assign)({_internalState:({context:e})=>({...e._internalState,error:new E.ContactsVersionRequirementError})}),assignErrorFromEvent:(0,i.assign)({_internalState:({context:e,event:t})=>({...e._internalState,error:new a.UnknownDAError(t.error instanceof Error?t.error.message:String(t.error))})})}}).createMachine({id:"EditExternalAddressIdentifierDeviceAction",initial:"InitialState",context:({input:e})=>({input:e,intermediateValue:{requiredUserInteraction:a.UserInteractionRequired.None},_internalState:{error:null,appAndVersion:null,hmacRest:null}}),states:{InitialState:{always:[{target:"ValidateInput",guard:"skipOpenApp"},{target:"OpenAppDeviceAction"}]},OpenAppDeviceAction:{invoke:{id:"openAppStateMachine",src:"openAppStateMachine",input:()=>({appName:r}),onSnapshot:{actions:(0,i.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckOpenAppResult",actions:(0,i.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:()=>t._internalState,Left:s=>({...t._internalState,error:s})})})}}},CheckOpenAppResult:{always:[{target:"ValidateInput",guard:"noInternalError"},{target:"Error"}]},ValidateInput:{entry:"assignValidationError",always:[{target:"WaitForAppAndVersion",guard:"noInternalError"},{target:"Error"}]},WaitForAppAndVersion:{entry:(0,i.assign)({intermediateValue:{requiredUserInteraction:a.UserInteractionRequired.None}}),invoke:{id:"waitForAppAndVersion",src:"waitForAppAndVersionStateMachine",input:()=>({}),onSnapshot:{actions:(0,i.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckAppAndVersion",actions:(0,i.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:s=>({...t._internalState,appAndVersion:{name:s.name,version:s.version}}),Left:s=>({...t._internalState,error:s})})})}}},CheckAppAndVersion:{always:[{target:"VersionGuard",guard:"noInternalError"},{target:"Error"}]},VersionGuard:{always:[{target:"EditIdentifier",guard:"contactsSupported"},{target:"Error",actions:"assignVersionError"}]},EditIdentifier:{entry:(0,i.assign)({intermediateValue:{requiredUserInteraction:a.UserInteractionRequired.RegisterWallet}}),exit:(0,i.assign)({intermediateValue:{requiredUserInteraction:a.UserInteractionRequired.None}}),invoke:{id:"editIdentifier",src:"editIdentifier",input:({context:e})=>e.input,onDone:{target:"EditIdentifierResultCheck",actions:(0,i.assign)({_internalState:({event:e,context:t})=>(0,a.isSuccessCommandResult)(e.output)?{...t._internalState,hmacRest:e.output.data.hmacRest}:{...t._internalState,error:e.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},EditIdentifierResultCheck:{always:[{target:"Success",guard:"noInternalError"},{target:"Error"}]},Success:{type:"final"},Error:{type:"final"}},output:({context:e})=>{const{hmacRest:t,error:s}=e._internalState;if(t){const{input:o}=e;return(0,c.Right)({contactName:o.contactName,scope:o.scope,previousIdentifier:o.previousIdentifier,identifier:o.newIdentifier,blockchainFamily:o.blockchainFamily,chainId:o.chainId,groupHandle:o.groupHandle,hmacProof:o.hmacProof,hmacRest:t})}return(0,c.Left)(s??new a.UnknownDAError("No error in final state"))}})}extractDependencies(n){return{isSupported:r=>(0,A.isContactsSupportedForSession)(n,r),editIdentifier:r=>new I.SendEditExternalAddressIdentifierTask(n,{contactName:r.contactName,scope:r.scope,previousIdentifier:r.previousIdentifier,newIdentifier:r.newIdentifier,blockchainFamily:r.blockchainFamily,chainId:r.chainId,groupHandle:r.groupHandle,hmacProof:r.hmacProof,hmacRest:r.hmacRest}).run()}}}0&&(module.exports={EditExternalAddressIdentifierDeviceAction});
1
+ "use strict";var u=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var g=(d,n)=>{for(var p in n)u(d,p,{get:n[p],enumerable:!0})},D=(d,n,p,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of S(n))!h.call(d,r)&&r!==p&&u(d,r,{get:()=>n[r],enumerable:!(l=m(n,r))||l.enumerable});return d};var x=d=>D(u({},"__esModule",{value:!0}),d);var V={};g(V,{EditExternalAddressIdentifierDeviceAction:()=>y});module.exports=x(V);var a=require("@ledgerhq/device-management-kit"),c=require("purify-ts"),i=require("xstate"),A=require("../../../app-binder/contactsVersionGuards"),E=require("../../../app-binder/model/contactsErrors"),I=require("../../../app-binder/task/SendEditExternalAddressIdentifierTask"),f=require("./validateEditExternalAddressIdentifierInput");class y extends a.XStateDeviceAction{makeStateMachine(n){const{isSupported:p,editIdentifier:l}=this.extractDependencies(n),r=this.input.appName;return(0,i.setup)({types:{input:{},context:{},output:{}},actors:{openAppStateMachine:new a.OpenAppDeviceAction({input:{appName:r}}).makeStateMachine(n),waitForAppAndVersionStateMachine:new a.WaitForAppAndVersionDeviceAction({input:{}}).makeStateMachine(n),editIdentifier:(0,i.fromPromise)(({input:e})=>l(e))},guards:{skipOpenApp:({context:e})=>e.input.skipOpenApp===!0,noInternalError:({context:e})=>e._internalState.error===null,contactsSupported:({context:e})=>{const{appAndVersion:t}=e._internalState;return t!==null&&p(t)}},actions:{assignValidationError:(0,i.assign)({_internalState:({context:e})=>{const t=(0,f.validateEditExternalAddressIdentifierInput)(e.input);return t?{...e._internalState,error:t}:e._internalState}}),assignVersionError:(0,i.assign)({_internalState:({context:e})=>({...e._internalState,error:new E.ContactsVersionRequirementError})}),assignErrorFromEvent:(0,i.assign)({_internalState:({context:e,event:t})=>({...e._internalState,error:new a.UnknownDAError(t.error instanceof Error?t.error.message:String(t.error))})})}}).createMachine({id:"EditExternalAddressIdentifierDeviceAction",initial:"InitialState",context:({input:e})=>({input:e,intermediateValue:{requiredUserInteraction:a.UserInteractionRequired.None},_internalState:{error:null,appAndVersion:null,hmacRest:null}}),states:{InitialState:{always:[{target:"ValidateInput",guard:"skipOpenApp"},{target:"OpenAppDeviceAction"}]},OpenAppDeviceAction:{invoke:{id:"openAppStateMachine",src:"openAppStateMachine",input:()=>({appName:r}),onSnapshot:{actions:(0,i.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckOpenAppResult",actions:(0,i.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:()=>t._internalState,Left:s=>({...t._internalState,error:s})})})}}},CheckOpenAppResult:{always:[{target:"ValidateInput",guard:"noInternalError"},{target:"Error"}]},ValidateInput:{entry:"assignValidationError",always:[{target:"WaitForAppAndVersion",guard:"noInternalError"},{target:"Error"}]},WaitForAppAndVersion:{entry:(0,i.assign)({intermediateValue:{requiredUserInteraction:a.UserInteractionRequired.None}}),invoke:{id:"waitForAppAndVersion",src:"waitForAppAndVersionStateMachine",input:()=>({}),onSnapshot:{actions:(0,i.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckAppAndVersion",actions:(0,i.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:s=>({...t._internalState,appAndVersion:{name:s.name,version:s.version}}),Left:s=>({...t._internalState,error:s})})})}}},CheckAppAndVersion:{always:[{target:"VersionGuard",guard:"noInternalError"},{target:"Error"}]},VersionGuard:{always:[{target:"EditIdentifier",guard:"contactsSupported"},{target:"Error",actions:"assignVersionError"}]},EditIdentifier:{entry:(0,i.assign)({intermediateValue:{requiredUserInteraction:a.UserInteractionRequired.RegisterWallet}}),exit:(0,i.assign)({intermediateValue:{requiredUserInteraction:a.UserInteractionRequired.None}}),invoke:{id:"editIdentifier",src:"editIdentifier",input:({context:e})=>e.input,onDone:{target:"EditIdentifierResultCheck",actions:(0,i.assign)({_internalState:({event:e,context:t})=>(0,a.isSuccessCommandResult)(e.output)?{...t._internalState,hmacRest:e.output.data.hmacRest}:{...t._internalState,error:e.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},EditIdentifierResultCheck:{always:[{target:"Success",guard:"noInternalError"},{target:"Error"}]},Success:{type:"final"},Error:{type:"final"}},output:({context:e})=>{const{hmacRest:t,error:s}=e._internalState;if(t){const{input:o}=e;return(0,c.Right)({contactName:o.contactName,scope:o.scope,previousIdentifier:o.previousIdentifier,identifier:o.newIdentifier,blockchainFamily:o.blockchainFamily,chainId:o.chainId,groupHandle:o.groupHandle,hmacProof:o.hmacProof,hmacRest:t})}return(0,c.Left)(s??new a.UnknownDAError("No error in final state"))}})}extractDependencies(n){return{isSupported:r=>(0,A.isContactsAppVersionSupportedForSession)(n,r),editIdentifier:r=>new I.SendEditExternalAddressIdentifierTask(n,{contactName:r.contactName,scope:r.scope,previousIdentifier:r.previousIdentifier,newIdentifier:r.newIdentifier,blockchainFamily:r.blockchainFamily,chainId:r.chainId,groupHandle:r.groupHandle,hmacProof:r.hmacProof,hmacRest:r.hmacRest}).run()}}}0&&(module.exports={EditExternalAddressIdentifierDeviceAction});
2
2
  //# sourceMappingURL=EditExternalAddressIdentifierDeviceAction.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/app-binder/device-action/EditExternalAddressIdentifier/EditExternalAddressIdentifierDeviceAction.ts"],
4
- "sourcesContent": ["import {\n type DeviceActionStateMachine,\n type InternalApi,\n isSuccessCommandResult,\n OpenAppDeviceAction,\n type StateMachineTypes,\n UnknownDAError,\n UserInteractionRequired,\n WaitForAppAndVersionDeviceAction,\n XStateDeviceAction,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport {\n type EditExternalAddressIdentifierDAError,\n type EditExternalAddressIdentifierDAInput,\n type EditExternalAddressIdentifierDAIntermediateValue,\n type EditExternalAddressIdentifierDAInternalState,\n type EditExternalAddressIdentifierDAOutput,\n} from \"@api/app-binder/EditExternalAddressIdentifierDeviceActionTypes\";\nimport {\n isContactsSupportedForSession,\n type RunningApp,\n} from \"@internal/app-binder/isContactsSupportedForSession\";\nimport { ContactsVersionRequirementError } from \"@internal/app-binder/model/contactsErrors\";\nimport {\n type EditIdentifierProof,\n SendEditExternalAddressIdentifierTask,\n} from \"@internal/app-binder/task/SendEditExternalAddressIdentifierTask\";\n\nimport { validateEditExternalAddressIdentifierInput } from \"./validateEditExternalAddressIdentifierInput\";\n\nexport type EditExternalAddressIdentifierMachineDependencies = {\n readonly isSupported: (app: RunningApp) => boolean;\n readonly editIdentifier: (\n input: EditExternalAddressIdentifierDAInput,\n ) => Promise<\n Awaited<ReturnType<SendEditExternalAddressIdentifierTask[\"run\"]>>\n >;\n};\n\nexport class EditExternalAddressIdentifierDeviceAction extends XStateDeviceAction<\n EditExternalAddressIdentifierDAOutput,\n EditExternalAddressIdentifierDAInput,\n EditExternalAddressIdentifierDAError,\n EditExternalAddressIdentifierDAIntermediateValue,\n EditExternalAddressIdentifierDAInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n EditExternalAddressIdentifierDAOutput,\n EditExternalAddressIdentifierDAInput,\n EditExternalAddressIdentifierDAError,\n EditExternalAddressIdentifierDAIntermediateValue,\n EditExternalAddressIdentifierDAInternalState\n > {\n type types = StateMachineTypes<\n EditExternalAddressIdentifierDAOutput,\n EditExternalAddressIdentifierDAInput,\n EditExternalAddressIdentifierDAError,\n EditExternalAddressIdentifierDAIntermediateValue,\n EditExternalAddressIdentifierDAInternalState\n >;\n\n const { isSupported, editIdentifier } =\n this.extractDependencies(internalApi);\n const appName = this.input.appName;\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n openAppStateMachine: new OpenAppDeviceAction({\n input: { appName },\n }).makeStateMachine(internalApi),\n waitForAppAndVersionStateMachine: new WaitForAppAndVersionDeviceAction({\n input: {},\n }).makeStateMachine(internalApi),\n editIdentifier: fromPromise(\n ({ input }: { input: EditExternalAddressIdentifierDAInput }) =>\n editIdentifier(input),\n ),\n },\n guards: {\n skipOpenApp: ({ context }) => context.input.skipOpenApp === true,\n noInternalError: ({ context }) => context._internalState.error === null,\n contactsSupported: ({ context }) => {\n const { appAndVersion } = context._internalState;\n return appAndVersion !== null && isSupported(appAndVersion);\n },\n },\n actions: {\n assignValidationError: assign({\n _internalState: ({ context }) => {\n const error = validateEditExternalAddressIdentifierInput(\n context.input,\n );\n return error\n ? { ...context._internalState, error }\n : context._internalState;\n },\n }),\n assignVersionError: assign({\n _internalState: ({ context }) => ({\n ...context._internalState,\n error: new ContactsVersionRequirementError(),\n }),\n }),\n assignErrorFromEvent: assign({\n _internalState: ({ context, event }) => ({\n ...context._internalState,\n error: new UnknownDAError(\n event[\"error\"] instanceof Error\n ? event[\"error\"].message\n : String(event[\"error\"]),\n ),\n }),\n }),\n },\n }).createMachine({\n id: \"EditExternalAddressIdentifierDeviceAction\",\n initial: \"InitialState\",\n context: ({ input }) => ({\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n error: null,\n appAndVersion: null,\n hmacRest: null,\n },\n }),\n states: {\n InitialState: {\n always: [\n { target: \"ValidateInput\", guard: \"skipOpenApp\" },\n { target: \"OpenAppDeviceAction\" },\n ],\n },\n OpenAppDeviceAction: {\n invoke: {\n id: \"openAppStateMachine\",\n src: \"openAppStateMachine\",\n input: () => ({ appName }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckOpenAppResult\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<EditExternalAddressIdentifierDAInternalState>(\n {\n Right: () => context._internalState,\n Left: (error) => ({ ...context._internalState, error }),\n },\n ),\n }),\n },\n },\n },\n CheckOpenAppResult: {\n always: [\n { target: \"ValidateInput\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n // Input validation runs inside the device action (after the app is\n // opened) so invalid caller input surfaces as a typed terminal error\n // state on the observable instead of a synchronous throw. Runs on both\n // the open-app and skip-open-app paths.\n ValidateInput: {\n entry: \"assignValidationError\",\n always: [\n { target: \"WaitForAppAndVersion\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n // Read the running app + version freshly from the device (rather than\n // the possibly-stale session state) so the version guard evaluates the\n // app that is actually running \u2014 e.g. when open-app is skipped and the\n // app was changed outside DMK. Runs on both paths.\n WaitForAppAndVersion: {\n // Start the phase from a clean value, clearing any interaction left\n // over from the OpenApp phase (e.g. ConfirmOpenApp).\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"waitForAppAndVersion\",\n src: \"waitForAppAndVersionStateMachine\",\n input: () => ({}),\n // Propagate the child DA's intermediate value so a consuming client\n // can render, e.g., a \"please unlock your device\" prompt when the\n // device is locked. Mirrors the OpenAppDeviceAction invoke above.\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckAppAndVersion\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<EditExternalAddressIdentifierDAInternalState>(\n {\n Right: (appAndVersion) => ({\n ...context._internalState,\n appAndVersion: {\n name: appAndVersion.name,\n version: appAndVersion.version,\n },\n }),\n Left: (error) => ({ ...context._internalState, error }),\n },\n ),\n }),\n },\n },\n },\n CheckAppAndVersion: {\n always: [\n { target: \"VersionGuard\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n // Version guard evaluates support from the fresh WaitForAppAndVersion\n // result. Runs on both the open-app and skip-open-app paths.\n VersionGuard: {\n always: [\n { target: \"EditIdentifier\", guard: \"contactsSupported\" },\n { target: \"Error\", actions: \"assignVersionError\" },\n ],\n },\n EditIdentifier: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.RegisterWallet,\n },\n }),\n exit: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"editIdentifier\",\n src: \"editIdentifier\",\n input: ({ context }) => context.input,\n onDone: {\n target: \"EditIdentifierResultCheck\",\n actions: assign({\n _internalState: ({ event, context }) =>\n isSuccessCommandResult(event.output)\n ? {\n ...context._internalState,\n hmacRest: event.output.data.hmacRest,\n }\n : {\n ...context._internalState,\n error: event.output.error,\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n EditIdentifierResultCheck: {\n always: [\n { target: \"Success\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n Success: { type: \"final\" },\n Error: { type: \"final\" },\n },\n output: ({ context }) => {\n const { hmacRest, error } = context._internalState;\n if (hmacRest) {\n const { input } = context;\n return Right({\n contactName: input.contactName,\n scope: input.scope,\n previousIdentifier: input.previousIdentifier,\n identifier: input.newIdentifier,\n blockchainFamily: input.blockchainFamily,\n chainId: input.chainId,\n groupHandle: input.groupHandle,\n // Preserved: the group-level name proof is untouched by an identifier\n // edit \u2014 only `hmacRest` (the address-level proof) rotates.\n hmacProof: input.hmacProof,\n hmacRest,\n });\n }\n return Left(error ?? new UnknownDAError(\"No error in final state\"));\n },\n });\n }\n\n extractDependencies(\n internalApi: InternalApi,\n ): EditExternalAddressIdentifierMachineDependencies {\n const isSupported = (app: RunningApp) =>\n isContactsSupportedForSession(internalApi, app);\n\n const editIdentifier = (\n input: EditExternalAddressIdentifierDAInput,\n ): Promise<\n Awaited<ReturnType<SendEditExternalAddressIdentifierTask[\"run\"]>>\n > =>\n new SendEditExternalAddressIdentifierTask(internalApi, {\n contactName: input.contactName,\n scope: input.scope,\n previousIdentifier: input.previousIdentifier,\n newIdentifier: input.newIdentifier,\n blockchainFamily: input.blockchainFamily,\n chainId: input.chainId,\n groupHandle: input.groupHandle,\n hmacProof: input.hmacProof,\n hmacRest: input.hmacRest,\n }).run();\n\n return { isSupported, editIdentifier };\n }\n}\n\nexport type { EditIdentifierProof };\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+CAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAUO,2CACPC,EAA4B,qBAC5BC,EAA2C,kBAS3CC,EAGO,8DACPC,EAAgD,qDAChDC,EAGO,2EAEPC,EAA2D,wDAWpD,MAAMR,UAAkD,oBAM7D,CACA,iBACES,EAOA,CASA,KAAM,CAAE,YAAAC,EAAa,eAAAC,CAAe,EAClC,KAAK,oBAAoBF,CAAW,EAChCG,EAAU,KAAK,MAAM,QAE3B,SAAO,SAAM,CACX,MAAO,CACL,MAAO,CAAC,EACR,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,oBAAqB,IAAI,sBAAoB,CAC3C,MAAO,CAAE,QAAAA,CAAQ,CACnB,CAAC,EAAE,iBAAiBH,CAAW,EAC/B,iCAAkC,IAAI,mCAAiC,CACrE,MAAO,CAAC,CACV,CAAC,EAAE,iBAAiBA,CAAW,EAC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EAAM,YAGnB,UAAWA,EAAM,UACjB,SAAAK,CACF,CAAC,CACH,CACA,SAAO,QAAKF,GAAS,IAAI,iBAAe,yBAAyB,CAAC,CACpE,CACF,CAAC,CACH,CAEA,oBACEP,EACkD,CAqBlD,MAAO,CAAE,YApBYU,MACnB,iCAA8BV,EAAaU,CAAG,EAmB1B,eAhBpBN,GAIA,IAAI,wCAAsCJ,EAAa,CACrD,YAAaI,EAAM,YACnB,MAAOA,EAAM,MACb,mBAAoBA,EAAM,mBAC1B,cAAeA,EAAM,cACrB,iBAAkBA,EAAM,iBACxB,QAASA,EAAM,QACf,YAAaA,EAAM,YACnB,UAAWA,EAAM,UACjB,SAAUA,EAAM,QAClB,CAAC,EAAE,IAAI,CAE4B,CACvC,CACF",
6
- "names": ["EditExternalAddressIdentifierDeviceAction_exports", "__export", "EditExternalAddressIdentifierDeviceAction", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_xstate", "import_isContactsSupportedForSession", "import_contactsErrors", "import_SendEditExternalAddressIdentifierTask", "import_validateEditExternalAddressIdentifierInput", "internalApi", "isSupported", "editIdentifier", "appName", "input", "context", "appAndVersion", "error", "event", "hmacRest", "app"]
4
+ "sourcesContent": ["import {\n type DeviceActionStateMachine,\n type InternalApi,\n isSuccessCommandResult,\n OpenAppDeviceAction,\n type StateMachineTypes,\n UnknownDAError,\n UserInteractionRequired,\n WaitForAppAndVersionDeviceAction,\n XStateDeviceAction,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport {\n type EditExternalAddressIdentifierDAError,\n type EditExternalAddressIdentifierDAInput,\n type EditExternalAddressIdentifierDAIntermediateValue,\n type EditExternalAddressIdentifierDAInternalState,\n type EditExternalAddressIdentifierDAOutput,\n} from \"@api/app-binder/EditExternalAddressIdentifierDeviceActionTypes\";\nimport {\n isContactsAppVersionSupportedForSession,\n type RunningApp,\n} from \"@internal/app-binder/contactsVersionGuards\";\nimport { ContactsVersionRequirementError } from \"@internal/app-binder/model/contactsErrors\";\nimport {\n type EditIdentifierProof,\n SendEditExternalAddressIdentifierTask,\n} from \"@internal/app-binder/task/SendEditExternalAddressIdentifierTask\";\n\nimport { validateEditExternalAddressIdentifierInput } from \"./validateEditExternalAddressIdentifierInput\";\n\nexport type EditExternalAddressIdentifierMachineDependencies = {\n readonly isSupported: (app: RunningApp) => boolean;\n readonly editIdentifier: (\n input: EditExternalAddressIdentifierDAInput,\n ) => Promise<\n Awaited<ReturnType<SendEditExternalAddressIdentifierTask[\"run\"]>>\n >;\n};\n\nexport class EditExternalAddressIdentifierDeviceAction extends XStateDeviceAction<\n EditExternalAddressIdentifierDAOutput,\n EditExternalAddressIdentifierDAInput,\n EditExternalAddressIdentifierDAError,\n EditExternalAddressIdentifierDAIntermediateValue,\n EditExternalAddressIdentifierDAInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n EditExternalAddressIdentifierDAOutput,\n EditExternalAddressIdentifierDAInput,\n EditExternalAddressIdentifierDAError,\n EditExternalAddressIdentifierDAIntermediateValue,\n EditExternalAddressIdentifierDAInternalState\n > {\n type types = StateMachineTypes<\n EditExternalAddressIdentifierDAOutput,\n EditExternalAddressIdentifierDAInput,\n EditExternalAddressIdentifierDAError,\n EditExternalAddressIdentifierDAIntermediateValue,\n EditExternalAddressIdentifierDAInternalState\n >;\n\n const { isSupported, editIdentifier } =\n this.extractDependencies(internalApi);\n const appName = this.input.appName;\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n openAppStateMachine: new OpenAppDeviceAction({\n input: { appName },\n }).makeStateMachine(internalApi),\n waitForAppAndVersionStateMachine: new WaitForAppAndVersionDeviceAction({\n input: {},\n }).makeStateMachine(internalApi),\n editIdentifier: fromPromise(\n ({ input }: { input: EditExternalAddressIdentifierDAInput }) =>\n editIdentifier(input),\n ),\n },\n guards: {\n skipOpenApp: ({ context }) => context.input.skipOpenApp === true,\n noInternalError: ({ context }) => context._internalState.error === null,\n contactsSupported: ({ context }) => {\n const { appAndVersion } = context._internalState;\n return appAndVersion !== null && isSupported(appAndVersion);\n },\n },\n actions: {\n assignValidationError: assign({\n _internalState: ({ context }) => {\n const error = validateEditExternalAddressIdentifierInput(\n context.input,\n );\n return error\n ? { ...context._internalState, error }\n : context._internalState;\n },\n }),\n assignVersionError: assign({\n _internalState: ({ context }) => ({\n ...context._internalState,\n error: new ContactsVersionRequirementError(),\n }),\n }),\n assignErrorFromEvent: assign({\n _internalState: ({ context, event }) => ({\n ...context._internalState,\n error: new UnknownDAError(\n event[\"error\"] instanceof Error\n ? event[\"error\"].message\n : String(event[\"error\"]),\n ),\n }),\n }),\n },\n }).createMachine({\n id: \"EditExternalAddressIdentifierDeviceAction\",\n initial: \"InitialState\",\n context: ({ input }) => ({\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n error: null,\n appAndVersion: null,\n hmacRest: null,\n },\n }),\n states: {\n InitialState: {\n always: [\n { target: \"ValidateInput\", guard: \"skipOpenApp\" },\n { target: \"OpenAppDeviceAction\" },\n ],\n },\n OpenAppDeviceAction: {\n invoke: {\n id: \"openAppStateMachine\",\n src: \"openAppStateMachine\",\n input: () => ({ appName }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckOpenAppResult\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<EditExternalAddressIdentifierDAInternalState>(\n {\n Right: () => context._internalState,\n Left: (error) => ({ ...context._internalState, error }),\n },\n ),\n }),\n },\n },\n },\n CheckOpenAppResult: {\n always: [\n { target: \"ValidateInput\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n // Input validation runs inside the device action (after the app is\n // opened) so invalid caller input surfaces as a typed terminal error\n // state on the observable instead of a synchronous throw. Runs on both\n // the open-app and skip-open-app paths.\n ValidateInput: {\n entry: \"assignValidationError\",\n always: [\n { target: \"WaitForAppAndVersion\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n // Read the running app + version freshly from the device (rather than\n // the possibly-stale session state) so the version guard evaluates the\n // app that is actually running \u2014 e.g. when open-app is skipped and the\n // app was changed outside DMK. Runs on both paths.\n WaitForAppAndVersion: {\n // Start the phase from a clean value, clearing any interaction left\n // over from the OpenApp phase (e.g. ConfirmOpenApp).\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"waitForAppAndVersion\",\n src: \"waitForAppAndVersionStateMachine\",\n input: () => ({}),\n // Propagate the child DA's intermediate value so a consuming client\n // can render, e.g., a \"please unlock your device\" prompt when the\n // device is locked. Mirrors the OpenAppDeviceAction invoke above.\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckAppAndVersion\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<EditExternalAddressIdentifierDAInternalState>(\n {\n Right: (appAndVersion) => ({\n ...context._internalState,\n appAndVersion: {\n name: appAndVersion.name,\n version: appAndVersion.version,\n },\n }),\n Left: (error) => ({ ...context._internalState, error }),\n },\n ),\n }),\n },\n },\n },\n CheckAppAndVersion: {\n always: [\n { target: \"VersionGuard\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n // Version guard evaluates support from the fresh WaitForAppAndVersion\n // result. Runs on both the open-app and skip-open-app paths.\n VersionGuard: {\n always: [\n { target: \"EditIdentifier\", guard: \"contactsSupported\" },\n { target: \"Error\", actions: \"assignVersionError\" },\n ],\n },\n EditIdentifier: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.RegisterWallet,\n },\n }),\n exit: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"editIdentifier\",\n src: \"editIdentifier\",\n input: ({ context }) => context.input,\n onDone: {\n target: \"EditIdentifierResultCheck\",\n actions: assign({\n _internalState: ({ event, context }) =>\n isSuccessCommandResult(event.output)\n ? {\n ...context._internalState,\n hmacRest: event.output.data.hmacRest,\n }\n : {\n ...context._internalState,\n error: event.output.error,\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n EditIdentifierResultCheck: {\n always: [\n { target: \"Success\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n Success: { type: \"final\" },\n Error: { type: \"final\" },\n },\n output: ({ context }) => {\n const { hmacRest, error } = context._internalState;\n if (hmacRest) {\n const { input } = context;\n return Right({\n contactName: input.contactName,\n scope: input.scope,\n previousIdentifier: input.previousIdentifier,\n identifier: input.newIdentifier,\n blockchainFamily: input.blockchainFamily,\n chainId: input.chainId,\n groupHandle: input.groupHandle,\n // Preserved: the group-level name proof is untouched by an identifier\n // edit \u2014 only `hmacRest` (the address-level proof) rotates.\n hmacProof: input.hmacProof,\n hmacRest,\n });\n }\n return Left(error ?? new UnknownDAError(\"No error in final state\"));\n },\n });\n }\n\n extractDependencies(\n internalApi: InternalApi,\n ): EditExternalAddressIdentifierMachineDependencies {\n const isSupported = (app: RunningApp) =>\n isContactsAppVersionSupportedForSession(internalApi, app);\n\n const editIdentifier = (\n input: EditExternalAddressIdentifierDAInput,\n ): Promise<\n Awaited<ReturnType<SendEditExternalAddressIdentifierTask[\"run\"]>>\n > =>\n new SendEditExternalAddressIdentifierTask(internalApi, {\n contactName: input.contactName,\n scope: input.scope,\n previousIdentifier: input.previousIdentifier,\n newIdentifier: input.newIdentifier,\n blockchainFamily: input.blockchainFamily,\n chainId: input.chainId,\n groupHandle: input.groupHandle,\n hmacProof: input.hmacProof,\n hmacRest: input.hmacRest,\n }).run();\n\n return { isSupported, editIdentifier };\n }\n}\n\nexport type { EditIdentifierProof };\n"],
5
+ "mappings": "yaAAA,IAAAA,EAA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,EAAQ,eACX,MAAOG,EAAM,OAAO,KACtB,CACR,CAAC,CACH,EACA,QAAS,CACP,OAAQ,QACR,QAAS,sBACX,CACF,CACF,EACA,0BAA2B,CACzB,OAAQ,CACN,CAAE,OAAQ,UAAW,MAAO,iBAAkB,EAC9C,CAAE,OAAQ,OAAQ,CACpB,CACF,EACA,QAAS,CAAE,KAAM,OAAQ,EACzB,MAAO,CAAE,KAAM,OAAQ,CACzB,EACA,OAAQ,CAAC,CAAE,QAAAH,CAAQ,IAAM,CACvB,KAAM,CAAE,SAAAI,EAAU,MAAAF,CAAM,EAAIF,EAAQ,eACpC,GAAII,EAAU,CACZ,KAAM,CAAE,MAAAL,CAAM,EAAIC,EAClB,SAAO,SAAM,CACX,YAAaD,EAAM,YACnB,MAAOA,EAAM,MACb,mBAAoBA,EAAM,mBAC1B,WAAYA,EAAM,cAClB,iBAAkBA,EAAM,iBACxB,QAASA,EAAM,QACf,YAAaA,EAAM,YAGnB,UAAWA,EAAM,UACjB,SAAAK,CACF,CAAC,CACH,CACA,SAAO,QAAKF,GAAS,IAAI,iBAAe,yBAAyB,CAAC,CACpE,CACF,CAAC,CACH,CAEA,oBACEP,EACkD,CAqBlD,MAAO,CAAE,YApBYU,MACnB,2CAAwCV,EAAaU,CAAG,EAmBpC,eAhBpBN,GAIA,IAAI,wCAAsCJ,EAAa,CACrD,YAAaI,EAAM,YACnB,MAAOA,EAAM,MACb,mBAAoBA,EAAM,mBAC1B,cAAeA,EAAM,cACrB,iBAAkBA,EAAM,iBACxB,QAASA,EAAM,QACf,YAAaA,EAAM,YACnB,UAAWA,EAAM,UACjB,SAAUA,EAAM,QAClB,CAAC,EAAE,IAAI,CAE4B,CACvC,CACF",
6
+ "names": ["EditExternalAddressIdentifierDeviceAction_exports", "__export", "EditExternalAddressIdentifierDeviceAction", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_xstate", "import_contactsVersionGuards", "import_contactsErrors", "import_SendEditExternalAddressIdentifierTask", "import_validateEditExternalAddressIdentifierInput", "internalApi", "isSupported", "editIdentifier", "appName", "input", "context", "appAndVersion", "error", "event", "hmacRest", "app"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var u=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var I=(o,n)=>{for(var d in n)u(o,d,{get:n[d],enumerable:!0})},x=(o,n,d,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of g(n))!D.call(o,r)&&r!==d&&u(o,r,{get:()=>n[r],enumerable:!(c=h(n,r))||c.enumerable});return o};var y=o=>x(u({},"__esModule",{value:!0}),o);var f={};I(f,{EditExternalAddressScopeDeviceAction:()=>V});module.exports=y(f);var i=require("@ledgerhq/device-management-kit"),l=require("purify-ts"),a=require("xstate"),S=require("../../../app-binder/isContactsSupportedForSession"),A=require("../../../app-binder/model/contactsErrors"),E=require("../../../app-binder/task/SendEditExternalAddressScopeTask"),m=require("./validateEditExternalAddressScopeInput");class V extends i.XStateDeviceAction{makeStateMachine(n){const{isSupported:d,editScope:c}=this.extractDependencies(n),r=this.input.appName;return(0,a.setup)({types:{input:{},context:{},output:{}},actors:{openAppStateMachine:new i.OpenAppDeviceAction({input:{appName:r}}).makeStateMachine(n),waitForAppAndVersionStateMachine:new i.WaitForAppAndVersionDeviceAction({input:{}}).makeStateMachine(n),editScope:(0,a.fromPromise)(({input:e})=>c(e))},guards:{skipOpenApp:({context:e})=>e.input.skipOpenApp===!0,noInternalError:({context:e})=>e._internalState.error===null,contactsSupported:({context:e})=>{const{appAndVersion:t}=e._internalState;return t!==null&&d(t)}},actions:{assignValidationError:(0,a.assign)({_internalState:({context:e})=>{const t=(0,m.validateEditExternalAddressScopeInput)(e.input);return t?{...e._internalState,error:t}:e._internalState}}),assignVersionError:(0,a.assign)({_internalState:({context:e})=>({...e._internalState,error:new A.ContactsVersionRequirementError})}),assignErrorFromEvent:(0,a.assign)({_internalState:({context:e,event:t})=>({...e._internalState,error:new i.UnknownDAError(t.error instanceof Error?t.error.message:String(t.error))})})}}).createMachine({id:"EditExternalAddressScopeDeviceAction",initial:"InitialState",context:({input:e})=>({input:e,intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.None},_internalState:{error:null,appAndVersion:null,hmacRest:null}}),states:{InitialState:{always:[{target:"ValidateInput",guard:"skipOpenApp"},{target:"OpenAppDeviceAction"}]},OpenAppDeviceAction:{invoke:{id:"openAppStateMachine",src:"openAppStateMachine",input:()=>({appName:r}),onSnapshot:{actions:(0,a.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckOpenAppResult",actions:(0,a.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:()=>t._internalState,Left:p=>({...t._internalState,error:p})})})}}},CheckOpenAppResult:{always:[{target:"ValidateInput",guard:"noInternalError"},{target:"Error"}]},ValidateInput:{entry:"assignValidationError",always:[{target:"WaitForAppAndVersion",guard:"noInternalError"},{target:"Error"}]},WaitForAppAndVersion:{entry:(0,a.assign)({intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.None}}),invoke:{id:"waitForAppAndVersion",src:"waitForAppAndVersionStateMachine",input:()=>({}),onSnapshot:{actions:(0,a.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckAppAndVersion",actions:(0,a.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:p=>({...t._internalState,appAndVersion:{name:p.name,version:p.version}}),Left:p=>({...t._internalState,error:p})})})}}},CheckAppAndVersion:{always:[{target:"VersionGuard",guard:"noInternalError"},{target:"Error"}]},VersionGuard:{always:[{target:"EditScope",guard:"contactsSupported"},{target:"Error",actions:"assignVersionError"}]},EditScope:{entry:(0,a.assign)({intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.RegisterWallet}}),exit:(0,a.assign)({intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.None}}),invoke:{id:"editScope",src:"editScope",input:({context:e})=>e.input,onDone:{target:"EditScopeResultCheck",actions:(0,a.assign)({_internalState:({event:e,context:t})=>(0,i.isSuccessCommandResult)(e.output)?{...t._internalState,hmacRest:e.output.data.hmacRest}:{...t._internalState,error:e.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},EditScopeResultCheck:{always:[{target:"Success",guard:"noInternalError"},{target:"Error"}]},Success:{type:"final"},Error:{type:"final"}},output:({context:e})=>{const{hmacRest:t,error:p}=e._internalState;if(t){const{input:s}=e;return(0,l.Right)({contactName:s.contactName,previousScope:s.previousScope,scope:s.newScope,identifier:s.identifier,blockchainFamily:s.blockchainFamily,chainId:s.chainId,groupHandle:s.groupHandle,hmacProof:s.hmacProof,hmacRest:t})}return(0,l.Left)(p??new i.UnknownDAError("No error in final state"))}})}extractDependencies(n){return{isSupported:r=>(0,S.isContactsSupportedForSession)(n,r),editScope:r=>new E.SendEditExternalAddressScopeTask(n,{contactName:r.contactName,previousScope:r.previousScope,newScope:r.newScope,identifier:r.identifier,blockchainFamily:r.blockchainFamily,chainId:r.chainId,groupHandle:r.groupHandle,hmacProof:r.hmacProof,hmacRest:r.hmacRest}).run()}}}0&&(module.exports={EditExternalAddressScopeDeviceAction});
1
+ "use strict";var u=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var I=(o,n)=>{for(var d in n)u(o,d,{get:n[d],enumerable:!0})},x=(o,n,d,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of g(n))!D.call(o,r)&&r!==d&&u(o,r,{get:()=>n[r],enumerable:!(c=h(n,r))||c.enumerable});return o};var y=o=>x(u({},"__esModule",{value:!0}),o);var f={};I(f,{EditExternalAddressScopeDeviceAction:()=>V});module.exports=y(f);var i=require("@ledgerhq/device-management-kit"),l=require("purify-ts"),a=require("xstate"),S=require("../../../app-binder/contactsVersionGuards"),A=require("../../../app-binder/model/contactsErrors"),E=require("../../../app-binder/task/SendEditExternalAddressScopeTask"),m=require("./validateEditExternalAddressScopeInput");class V extends i.XStateDeviceAction{makeStateMachine(n){const{isSupported:d,editScope:c}=this.extractDependencies(n),r=this.input.appName;return(0,a.setup)({types:{input:{},context:{},output:{}},actors:{openAppStateMachine:new i.OpenAppDeviceAction({input:{appName:r}}).makeStateMachine(n),waitForAppAndVersionStateMachine:new i.WaitForAppAndVersionDeviceAction({input:{}}).makeStateMachine(n),editScope:(0,a.fromPromise)(({input:e})=>c(e))},guards:{skipOpenApp:({context:e})=>e.input.skipOpenApp===!0,noInternalError:({context:e})=>e._internalState.error===null,contactsSupported:({context:e})=>{const{appAndVersion:t}=e._internalState;return t!==null&&d(t)}},actions:{assignValidationError:(0,a.assign)({_internalState:({context:e})=>{const t=(0,m.validateEditExternalAddressScopeInput)(e.input);return t?{...e._internalState,error:t}:e._internalState}}),assignVersionError:(0,a.assign)({_internalState:({context:e})=>({...e._internalState,error:new A.ContactsVersionRequirementError})}),assignErrorFromEvent:(0,a.assign)({_internalState:({context:e,event:t})=>({...e._internalState,error:new i.UnknownDAError(t.error instanceof Error?t.error.message:String(t.error))})})}}).createMachine({id:"EditExternalAddressScopeDeviceAction",initial:"InitialState",context:({input:e})=>({input:e,intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.None},_internalState:{error:null,appAndVersion:null,hmacRest:null}}),states:{InitialState:{always:[{target:"ValidateInput",guard:"skipOpenApp"},{target:"OpenAppDeviceAction"}]},OpenAppDeviceAction:{invoke:{id:"openAppStateMachine",src:"openAppStateMachine",input:()=>({appName:r}),onSnapshot:{actions:(0,a.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckOpenAppResult",actions:(0,a.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:()=>t._internalState,Left:p=>({...t._internalState,error:p})})})}}},CheckOpenAppResult:{always:[{target:"ValidateInput",guard:"noInternalError"},{target:"Error"}]},ValidateInput:{entry:"assignValidationError",always:[{target:"WaitForAppAndVersion",guard:"noInternalError"},{target:"Error"}]},WaitForAppAndVersion:{entry:(0,a.assign)({intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.None}}),invoke:{id:"waitForAppAndVersion",src:"waitForAppAndVersionStateMachine",input:()=>({}),onSnapshot:{actions:(0,a.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckAppAndVersion",actions:(0,a.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:p=>({...t._internalState,appAndVersion:{name:p.name,version:p.version}}),Left:p=>({...t._internalState,error:p})})})}}},CheckAppAndVersion:{always:[{target:"VersionGuard",guard:"noInternalError"},{target:"Error"}]},VersionGuard:{always:[{target:"EditScope",guard:"contactsSupported"},{target:"Error",actions:"assignVersionError"}]},EditScope:{entry:(0,a.assign)({intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.RegisterWallet}}),exit:(0,a.assign)({intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.None}}),invoke:{id:"editScope",src:"editScope",input:({context:e})=>e.input,onDone:{target:"EditScopeResultCheck",actions:(0,a.assign)({_internalState:({event:e,context:t})=>(0,i.isSuccessCommandResult)(e.output)?{...t._internalState,hmacRest:e.output.data.hmacRest}:{...t._internalState,error:e.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},EditScopeResultCheck:{always:[{target:"Success",guard:"noInternalError"},{target:"Error"}]},Success:{type:"final"},Error:{type:"final"}},output:({context:e})=>{const{hmacRest:t,error:p}=e._internalState;if(t){const{input:s}=e;return(0,l.Right)({contactName:s.contactName,previousScope:s.previousScope,scope:s.newScope,identifier:s.identifier,blockchainFamily:s.blockchainFamily,chainId:s.chainId,groupHandle:s.groupHandle,hmacProof:s.hmacProof,hmacRest:t})}return(0,l.Left)(p??new i.UnknownDAError("No error in final state"))}})}extractDependencies(n){return{isSupported:r=>(0,S.isContactsAppVersionSupportedForSession)(n,r),editScope:r=>new E.SendEditExternalAddressScopeTask(n,{contactName:r.contactName,previousScope:r.previousScope,newScope:r.newScope,identifier:r.identifier,blockchainFamily:r.blockchainFamily,chainId:r.chainId,groupHandle:r.groupHandle,hmacProof:r.hmacProof,hmacRest:r.hmacRest}).run()}}}0&&(module.exports={EditExternalAddressScopeDeviceAction});
2
2
  //# sourceMappingURL=EditExternalAddressScopeDeviceAction.js.map