@ledgerhq/context-module 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/package.json +2 -1
- package/lib/cjs/src/ContextModuleBuilder.js +1 -1
- package/lib/cjs/src/ContextModuleBuilder.js.map +2 -2
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.js +1 -1
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.js.map +3 -3
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.js +1 -1
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.js.map +3 -3
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js +1 -1
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js.map +3 -3
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js +1 -1
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js.map +3 -3
- package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js +1 -1
- package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js.map +3 -3
- package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js +2 -0
- package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js.map +7 -0
- package/lib/cjs/src/modules/solana/lifi/data/HttpLifiDataSource.js +1 -1
- package/lib/cjs/src/modules/solana/lifi/data/HttpLifiDataSource.js.map +2 -2
- package/lib/cjs/src/modules/solana/lifi/data/HttpLifiDataSource.test.js +1 -1
- package/lib/cjs/src/modules/solana/lifi/data/HttpLifiDataSource.test.js.map +2 -2
- package/lib/cjs/src/shared/utils/bs58Encoder.js +2 -0
- package/lib/cjs/src/shared/utils/bs58Encoder.js.map +7 -0
- package/lib/cjs/src/shared/utils/uint8ArrayCodec.js +2 -0
- package/lib/cjs/src/shared/utils/uint8ArrayCodec.js.map +7 -0
- package/lib/cjs/src/shared/utils/uint8ArrayCodec.test.js +2 -0
- package/lib/cjs/src/shared/utils/uint8ArrayCodec.test.js.map +7 -0
- package/lib/esm/package.json +2 -1
- package/lib/esm/src/ContextModuleBuilder.js +1 -1
- package/lib/esm/src/ContextModuleBuilder.js.map +2 -2
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.js +1 -1
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.js.map +3 -3
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.js +1 -1
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.js.map +3 -3
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js +1 -1
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js.map +3 -3
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js +1 -1
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js.map +3 -3
- package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js +1 -1
- package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js.map +3 -3
- package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js +2 -0
- package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js.map +7 -0
- package/lib/esm/src/modules/solana/lifi/data/HttpLifiDataSource.js +1 -1
- package/lib/esm/src/modules/solana/lifi/data/HttpLifiDataSource.js.map +2 -2
- package/lib/esm/src/modules/solana/lifi/data/HttpLifiDataSource.test.js +1 -1
- package/lib/esm/src/modules/solana/lifi/data/HttpLifiDataSource.test.js.map +2 -2
- package/lib/esm/src/shared/utils/bs58Encoder.js +2 -0
- package/lib/esm/src/shared/utils/bs58Encoder.js.map +7 -0
- package/lib/esm/src/shared/utils/uint8ArrayCodec.js +2 -0
- package/lib/esm/src/shared/utils/uint8ArrayCodec.js.map +7 -0
- package/lib/esm/src/shared/utils/uint8ArrayCodec.test.js +2 -0
- package/lib/esm/src/shared/utils/uint8ArrayCodec.test.js.map +7 -0
- package/lib/types/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.d.ts +3 -2
- package/lib/types/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.d.ts.map +1 -1
- package/lib/types/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.d.ts +3 -2
- package/lib/types/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.d.ts.map +1 -1
- package/lib/types/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.d.ts +16 -2
- package/lib/types/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.d.ts.map +1 -1
- package/lib/types/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.d.ts +2 -0
- package/lib/types/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.d.ts.map +1 -0
- package/lib/types/src/modules/solana/lifi/data/HttpLifiDataSource.d.ts.map +1 -1
- package/lib/types/src/shared/utils/bs58Encoder.d.ts +9 -0
- package/lib/types/src/shared/utils/bs58Encoder.d.ts.map +1 -0
- package/lib/types/src/shared/utils/uint8ArrayCodec.d.ts +3 -0
- package/lib/types/src/shared/utils/uint8ArrayCodec.d.ts.map +1 -0
- package/lib/types/src/shared/utils/uint8ArrayCodec.test.d.ts +2 -0
- package/lib/types/src/shared/utils/uint8ArrayCodec.test.d.ts.map +1 -0
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -4
package/lib/cjs/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
+
"bs58": "catalog:",
|
|
3
4
|
"crypto-js": "catalog:",
|
|
4
5
|
"ethers": "catalog:",
|
|
5
6
|
"inversify": "catalog:",
|
|
@@ -57,5 +58,5 @@
|
|
|
57
58
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
58
59
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
59
60
|
},
|
|
60
|
-
"version": "2.
|
|
61
|
+
"version": "2.1.0"
|
|
61
62
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},
|
|
1
|
+
"use strict";var i=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},l=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!g.call(t,r)&&r!==o&&i(t,r,{get:()=>e[r],enumerable:!(n=u(e,r))||n.enumerable});return t};var f=t=>l(i({},"__esModule",{value:!0}),t);var y={};C(y,{ContextModuleBuilder:()=>M,DEFAULT_CONFIG:()=>d});module.exports=f(y);var a=require("@ledgerhq/device-management-kit"),s=require("./DefaultContextModule");const p="https://crypto-assets-service.api.ledger.com/v1",h="https://web3checks-backend.api.ledger.com/v3",m="https://nft.api.live.ledger.com",x="https://blind-signing.api.ledger.com/ingest/v1",d=Object.freeze({cal:Object.freeze({url:p,mode:"prod",branch:"main"}),web3checks:Object.freeze({url:h}),metadataServiceDomain:Object.freeze({url:m}),reporter:Object.freeze({url:x}),datasource:Object.freeze({proxy:"default"}),appSource:"third-party"}),L={defaultLoaders:!0,defaultFieldLoaders:!0,customLoaders:[],customFieldLoaders:[],customTypedDataLoader:void 0,customBlindSigningReporter:void 0,customTrustedNameDataSource:void 0};class M{config;constructor({originToken:e,loggerFactory:o}){this.config={...d,...L,customLoaders:[],customFieldLoaders:[],originToken:e??"",loggerFactory:o??a.noopLoggerFactory}}removeDefaultLoaders(){return this.config.defaultLoaders=!1,this}addLoader(e){return this.config.customLoaders.push(e),this}addTypedDataLoader(e){return this.config.customTypedDataLoader=e,this}setCalConfig(e){return this.config.cal=e,this}setMetadataServiceConfig(e){return this.config.metadataServiceDomain=e,this}setWeb3ChecksConfig(e){return this.config.web3checks=e,this}setDatasourceConfig(e){return this.config.datasource=e,this}setReporterConfig(e){return this.config.reporter=e,this}setAppSource(e){return this.config.appSource=e,this}setBlindSigningReporter(e){return this.config.customBlindSigningReporter=e,this}setTrustedNameDataSource(e){return this.config.customTrustedNameDataSource=e,this}setLoggerFactory(e){return this.config.loggerFactory=e,this}setChain(e){return this.config.chain=e,this}build(){if(!this.config.chain)throw new Error("[ContextModuleBuilder] setChain() must be called before build()");return new s.DefaultContextModule(this.config)}}0&&(module.exports={ContextModuleBuilder,DEFAULT_CONFIG});
|
|
2
2
|
//# sourceMappingURL=ContextModuleBuilder.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ContextModuleBuilder.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type LoggerPublisherService,\n noopLoggerFactory,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleLoaderConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleReporterConfig,\n type ContextModuleServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type TrustedNameDataSource } from \"./modules/ethereum/trusted-name/data/TrustedNameDataSource\";\nimport { type TypedDataContextLoader } from \"./modules/ethereum/typed-data/domain/TypedDataContextLoader\";\nimport { type BlindSigningReporter } from \"./modules/multichain/reporter/domain/BlindSigningReporter\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type ContextModuleChainID } from \"./shared/domain/ContextModuleChainID\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\nconst DEFAULT_METADATA_SERVICE_DOMAIN = \"https://nft.api.live.ledger.com\";\nconst DEFAULT_REPORTER_URL = \"https://
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAGO,2CAmBPC,EAAqC,kCAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAClCC,EAAuB,
|
|
4
|
+
"sourcesContent": ["import {\n type LoggerPublisherService,\n noopLoggerFactory,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleLoaderConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleReporterConfig,\n type ContextModuleServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type TrustedNameDataSource } from \"./modules/ethereum/trusted-name/data/TrustedNameDataSource\";\nimport { type TypedDataContextLoader } from \"./modules/ethereum/typed-data/domain/TypedDataContextLoader\";\nimport { type BlindSigningReporter } from \"./modules/multichain/reporter/domain/BlindSigningReporter\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type ContextModuleChainID } from \"./shared/domain/ContextModuleChainID\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\nconst DEFAULT_METADATA_SERVICE_DOMAIN = \"https://nft.api.live.ledger.com\";\nconst DEFAULT_REPORTER_URL = \"https://blind-signing.api.ledger.com/ingest/v1\";\n\n/**\n * Default configuration for the context module\n *\n * @note This configuration is frozen to prevent modifications after construction\n * and can be used by external packages to get a default configuration.\n */\nexport const DEFAULT_CONFIG: Readonly<ContextModuleConfig> = Object.freeze({\n cal: Object.freeze({\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n }),\n web3checks: Object.freeze({\n url: DEFAULT_WEB3_CHECKS_URL,\n }),\n metadataServiceDomain: Object.freeze({\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n }),\n reporter: Object.freeze({\n url: DEFAULT_REPORTER_URL,\n }),\n datasource: Object.freeze({ proxy: \"default\" }),\n appSource: \"third-party\",\n});\n\n/**\n * Default loader configuration for the context module\n *\n * @note This configuration is internal and will be the default configuration for the context module.\n */\nconst DEFAULT_LOADER_CONFIG: ContextModuleLoaderConfig = {\n defaultLoaders: true,\n defaultFieldLoaders: true,\n customLoaders: [],\n customFieldLoaders: [],\n customTypedDataLoader: undefined,\n customBlindSigningReporter: undefined,\n customTrustedNameDataSource: undefined,\n};\n\n// Internal config type: all ServiceConfig fields except chain (set later via setChain)\ntype BuilderConfig = Omit<ContextModuleServiceConfig, \"chain\"> &\n Partial<Pick<ContextModuleServiceConfig, \"chain\">> &\n ContextModuleLoaderConfig;\n\nexport class ContextModuleBuilder {\n private config: BuilderConfig;\n\n constructor({ originToken, loggerFactory }: ContextModuleConstructorArgs) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...DEFAULT_LOADER_CONFIG,\n customLoaders: [],\n customFieldLoaders: [],\n originToken: originToken ?? \"\",\n loggerFactory: loggerFactory ?? noopLoggerFactory,\n };\n }\n\n /**\n * Remove default loaders from the list of loaders\n *\n * @returns this\n */\n removeDefaultLoaders() {\n this.config.defaultLoaders = false;\n return this;\n }\n\n /**\n * Add a custom loader to the list of loaders\n *\n * @param loader loader to add to the list of loaders\n * @returns this\n */\n addLoader(loader: ContextLoader) {\n this.config.customLoaders.push(loader);\n return this;\n }\n\n /**\n * Replace the default loader for typed data clear signing contexts\n *\n * @param loader loader to use for typed data clear signing contexts\n * @returns this\n */\n addTypedDataLoader(loader: TypedDataContextLoader) {\n this.config.customTypedDataLoader = loader;\n return this;\n }\n\n /**\n * Add a custom CAL configuration\n *\n * @param calConfig\n * @returns this\n */\n setCalConfig(calConfig: ContextModuleCalConfig) {\n this.config.cal = calConfig;\n return this;\n }\n\n /**\n * Add a custom metadata service configuration\n *\n * @param metadataServiceConfig\n * @returns this\n */\n setMetadataServiceConfig(\n metadataServiceConfig: ContextModuleMetadataServiceConfig,\n ) {\n this.config.metadataServiceDomain = metadataServiceConfig;\n return this;\n }\n\n /**\n * Add a custom web3 checks configuration\n *\n * @param web3ChecksConfig\n * @returns this\n */\n setWeb3ChecksConfig(web3ChecksConfig: ContextModuleWeb3ChecksConfig) {\n this.config.web3checks = web3ChecksConfig;\n return this;\n }\n\n /**\n * Add datasource configuration\n *\n * @param datasourceConfig\n * @returns this\n */\n setDatasourceConfig(datasourceConfig: ContextModuleDatasourceConfig) {\n this.config.datasource = datasourceConfig;\n return this;\n }\n\n /**\n * Set a custom reporter configuration\n *\n * @param reporterConfig\n * @returns this\n */\n setReporterConfig(reporterConfig: ContextModuleReporterConfig) {\n this.config.reporter = reporterConfig;\n return this;\n }\n\n /**\n * Set the app source identifier included in blind signing reports\n *\n * @param appSource\n * @returns this\n */\n setAppSource(appSource: string) {\n this.config.appSource = appSource;\n return this;\n }\n\n /**\n * Set a custom blind signing reporter\n *\n * @param reporter reporter to use for blind signing events\n * @returns this\n */\n setBlindSigningReporter(reporter: BlindSigningReporter) {\n this.config.customBlindSigningReporter = reporter;\n return this;\n }\n\n /**\n * Set a custom trusted name data source\n *\n * @param dataSource data source to use for trusted name resolution\n * @returns this\n */\n setTrustedNameDataSource(dataSource: TrustedNameDataSource) {\n this.config.customTrustedNameDataSource = dataSource;\n return this;\n }\n\n /**\n * Set a custom logger factory\n *\n * @param loggerFactory\n * @returns this\n */\n setLoggerFactory(loggerFactory: (tag: string) => LoggerPublisherService) {\n this.config.loggerFactory = loggerFactory;\n return this;\n }\n\n /**\n * Set the chain for which this context module is built\n *\n * @param chain\n * @returns this\n */\n setChain(chain: ContextModuleChainID) {\n this.config.chain = chain;\n return this;\n }\n\n /**\n * Build the context module\n *\n * @returns the context module\n */\n build(): ContextModule {\n if (!this.config.chain) {\n throw new Error(\n \"[ContextModuleBuilder] setChain() must be called before build()\",\n );\n }\n return new DefaultContextModule(\n this.config as ContextModuleServiceConfig & ContextModuleLoaderConfig,\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAGO,2CAmBPC,EAAqC,kCAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAClCC,EAAuB,iDAQhBP,EAAgD,OAAO,OAAO,CACzE,IAAK,OAAO,OAAO,CACjB,IAAKI,EACL,KAAM,OACN,OAAQ,MACV,CAAC,EACD,WAAY,OAAO,OAAO,CACxB,IAAKC,CACP,CAAC,EACD,sBAAuB,OAAO,OAAO,CACnC,IAAKC,CACP,CAAC,EACD,SAAU,OAAO,OAAO,CACtB,IAAKC,CACP,CAAC,EACD,WAAY,OAAO,OAAO,CAAE,MAAO,SAAU,CAAC,EAC9C,UAAW,aACb,CAAC,EAOKC,EAA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
"names": ["ContextModuleBuilder_exports", "__export", "ContextModuleBuilder", "DEFAULT_CONFIG", "__toCommonJS", "import_device_management_kit", "import_DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "DEFAULT_REPORTER_URL", "DEFAULT_LOADER_CONFIG", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "reporterConfig", "appSource", "reporter", "dataSource", "chain"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var y=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var A=(a,e)=>{for(var t in e)y(a,t,{get:e[t],enumerable:!0})},M=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of N(e))!L.call(a,o)&&o!==t&&y(a,o,{get:()=>e[o],enumerable:!(r=S(e,o))||r.enumerable});return a};var U=a=>M(y({},"__esModule",{value:!0}),a),C=(a,e,t,r)=>{for(var o=r>1?void 0:r?S(e,t):e,s=a.length-1,n;s>=0;s--)(n=a[s])&&(o=(r?n(e,t,o):n(o))||o);return r&&o&&y(e,t,o),o},p=(a,e)=>(t,r)=>e(t,r,a);var b={};A(b,{GatedSigningContextLoader:()=>g});module.exports=U(b);var u=require("@ledgerhq/device-management-kit"),d=require("inversify"),D=require("../../../../config/di/configTypes"),G=require("../../../../modules/ethereum/gated-signing/di/gatedSigningTypes"),_=require("../../../../modules/ethereum/proxy/di/proxyTypes"),T=require("../../../../modules/multichain/pki/di/pkiTypes"),I=require("../../../../modules/multichain/pki/model/KeyId"),h=require("../../../../modules/multichain/pki/model/KeyUsage"),i=require("../../../../shared/model/ClearSignContext");const k=[i.ClearSignContextType.ETHEREUM_GATED_SIGNING];function w(a){const e=a.toLowerCase();return e.startsWith("0x")?e:`0x${e}`}let g=class{constructor(e,t,r,o){this._dataSource=e;this._certificateLoader=t;this._proxyDataSource=r;this.logger=o("GatedSigningContextLoader")}logger;canHandle(e,t){return k.every(r=>t.includes(r))&&typeof e=="object"&&e!==null&&"to"in e&&(0,u.isHexaString)(e.to)&&e.to!=="0x"&&"selector"in e&&(0,u.isHexaString)(e.selector)&&"chainId"in e&&typeof e.chainId=="number"&&"deviceModelId"in e&&e.deviceModelId!==void 0}async load({to:e,selector:t,chainId:r,deviceModelId:o}){const s=await this._dataSource.getGatedDescriptor({contractAddress:e,selector:t,chainId:r});if(s.isRight()){const{signedDescriptor:c}=s.unsafeCoerce(),H=await this._loadGatedCertificate(o);return this.logger.debug("load result",{data:{path:"direct",to:e,selector:t,chainId:r,contextTypes:[i.ClearSignContextType.ETHEREUM_GATED_SIGNING]}}),[{type:i.ClearSignContextType.ETHEREUM_GATED_SIGNING,payload:c,certificate:H}]}const n=s.extract(),E={type:i.ClearSignContextType.ERROR,error:n},m=await this._proxyDataSource.getProxyImplementationAddress({proxyAddress:e,chainId:r,challenge:"",calldata:"0x"});if(m.isLeft()){const c=m.extract();return this.logger.warn("No gated descriptor found and proxy resolution failed",{data:{to:e,selector:t,chainId:r,directError:n.message,proxyError:c.message}}),[E]}const l=m.unsafeCoerce(),x=w(l.implementationAddress),f=await this._dataSource.getGatedDescriptor({contractAddress:x,selector:t,chainId:r});if(f.isLeft()){const c=f.extract();return this.logger.warn("No gated descriptor found for proxy implementation address",{data:{to:e,implementationAddress:x,selector:t,chainId:r,directError:n.message,implError:c.message}}),[E]}const{signedDescriptor:P}=f.unsafeCoerce(),[R,v]=await Promise.all([this._certificateLoader.loadCertificate({keyId:l.keyId,keyUsage:l.keyUsage,targetDevice:o}),this._loadGatedCertificate(o)]);return this.logger.debug("load result",{data:{path:"proxy",to:e,implementationAddress:x,selector:t,chainId:r,contextTypes:[i.ClearSignContextType.ETHEREUM_PROXY_INFO,i.ClearSignContextType.ETHEREUM_GATED_SIGNING]}}),[{type:i.ClearSignContextType.ETHEREUM_PROXY_INFO,payload:l.signedDescriptor,certificate:R},{type:i.ClearSignContextType.ETHEREUM_GATED_SIGNING,payload:P,certificate:v}]}_loadGatedCertificate(e){return this._certificateLoader.loadCertificate({keyId:I.KeyId.CalGatedSigning,keyUsage:h.KeyUsage.GatedSigning,targetDevice:e})}};g=C([(0,d.injectable)(),p(0,(0,d.inject)(G.gatedSigningTypes.GatedDescriptorDataSource)),p(1,(0,d.inject)(T.pkiTypes.PkiCertificateLoader)),p(2,(0,d.inject)(_.proxyTypes.ProxyDataSource)),p(3,(0,d.inject)(D.configTypes.ContextModuleLoggerFactory))],g);0&&(module.exports={GatedSigningContextLoader});
|
|
2
2
|
//# sourceMappingURL=GatedSigningContextLoader.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n DeviceModelId,\n HexaString,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport { gatedSigningTypes } from \"@/modules/ethereum/gated-signing/di/gatedSigningTypes\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/modules/ethereum/proxy/di/proxyTypes\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nexport type GatedSigningContextInput = {\n to: HexaString;\n selector: HexaString;\n chainId: number;\n deviceModelId: DeviceModelId;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n];\n\nfunction normalizeAddress(address: string): HexaString {\n const lower = address.toLowerCase();\n return (lower.startsWith(\"0x\") ? lower : `0x${lower}`) as HexaString;\n}\n\n@injectable()\nexport class GatedSigningContextLoader\n implements ContextLoader<GatedSigningContextInput>\n{\n constructor(\n @inject(gatedSigningTypes.GatedDescriptorDataSource)\n private readonly _dataSource: GatedDescriptorDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(proxyTypes.ProxyDataSource)\n private readonly _proxyDataSource: ProxyDataSource,\n ) {}\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is GatedSigningContextInput {\n return (\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type)) &&\n typeof input === \"object\" &&\n input !== null &&\n \"to\" in input &&\n isHexaString(input.to) &&\n input.to !== \"0x\" &&\n \"selector\" in input &&\n isHexaString(input.selector) &&\n \"chainId\" in input &&\n typeof input.chainId === \"number\" &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined\n );\n }\n\n async load({\n to,\n selector,\n chainId,\n deviceModelId,\n }: GatedSigningContextInput): Promise<ClearSignContext[]> {\n const directResult = await this._dataSource.getGatedDescriptor({\n contractAddress: to,\n selector,\n chainId,\n });\n\n if (directResult.isRight()) {\n const { signedDescriptor } = directResult.unsafeCoerce();\n const certificate = await this._loadGatedCertificate(deviceModelId);\n return [\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate,\n },\n ];\n }\n\n const errorContext: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error:
|
|
5
|
-
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,
|
|
6
|
-
"names": ["GatedSigningContextLoader_exports", "__export", "GatedSigningContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_gatedSigningTypes", "import_proxyTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "SUPPORTED_TYPES", "normalizeAddress", "address", "lower", "GatedSigningContextLoader", "_dataSource", "_certificateLoader", "_proxyDataSource", "input", "expectedTypes", "type", "to", "selector", "chainId", "deviceModelId", "directResult", "signedDescriptor", "certificate", "errorContext", "proxyResult", "proxyData", "implementationAddress", "implGatedResult", "proxyCertificate", "gatedCertificate", "__decorateClass", "__decorateParam"]
|
|
4
|
+
"sourcesContent": ["import {\n DeviceModelId,\n HexaString,\n isHexaString,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport { gatedSigningTypes } from \"@/modules/ethereum/gated-signing/di/gatedSigningTypes\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/modules/ethereum/proxy/di/proxyTypes\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nexport type GatedSigningContextInput = {\n to: HexaString;\n selector: HexaString;\n chainId: number;\n deviceModelId: DeviceModelId;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n];\n\nfunction normalizeAddress(address: string): HexaString {\n const lower = address.toLowerCase();\n return (lower.startsWith(\"0x\") ? lower : `0x${lower}`) as HexaString;\n}\n\n@injectable()\nexport class GatedSigningContextLoader\n implements ContextLoader<GatedSigningContextInput>\n{\n private readonly logger: LoggerPublisherService;\n\n constructor(\n @inject(gatedSigningTypes.GatedDescriptorDataSource)\n private readonly _dataSource: GatedDescriptorDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(proxyTypes.ProxyDataSource)\n private readonly _proxyDataSource: ProxyDataSource,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"GatedSigningContextLoader\");\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is GatedSigningContextInput {\n return (\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type)) &&\n typeof input === \"object\" &&\n input !== null &&\n \"to\" in input &&\n isHexaString(input.to) &&\n input.to !== \"0x\" &&\n \"selector\" in input &&\n isHexaString(input.selector) &&\n \"chainId\" in input &&\n typeof input.chainId === \"number\" &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined\n );\n }\n\n async load({\n to,\n selector,\n chainId,\n deviceModelId,\n }: GatedSigningContextInput): Promise<ClearSignContext[]> {\n const directResult = await this._dataSource.getGatedDescriptor({\n contractAddress: to,\n selector,\n chainId,\n });\n\n if (directResult.isRight()) {\n const { signedDescriptor } = directResult.unsafeCoerce();\n const certificate = await this._loadGatedCertificate(deviceModelId);\n this.logger.debug(\"load result\", {\n data: {\n path: \"direct\",\n to,\n selector,\n chainId,\n contextTypes: [ClearSignContextType.ETHEREUM_GATED_SIGNING],\n },\n });\n return [\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate,\n },\n ];\n }\n\n const directError = directResult.extract() as Error;\n const errorContext: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: directError,\n };\n\n const proxyResult =\n await this._proxyDataSource.getProxyImplementationAddress({\n proxyAddress: to,\n chainId,\n challenge: \"\",\n calldata: \"0x\",\n });\n\n if (proxyResult.isLeft()) {\n const proxyError = proxyResult.extract() as Error;\n this.logger.warn(\n \"No gated descriptor found and proxy resolution failed\",\n {\n data: {\n to,\n selector,\n chainId,\n directError: directError.message,\n proxyError: proxyError.message,\n },\n },\n );\n return [errorContext];\n }\n\n const proxyData = proxyResult.unsafeCoerce();\n const implementationAddress = normalizeAddress(\n proxyData.implementationAddress,\n );\n\n const implGatedResult = await this._dataSource.getGatedDescriptor({\n contractAddress: implementationAddress,\n selector,\n chainId,\n });\n\n if (implGatedResult.isLeft()) {\n const implError = implGatedResult.extract() as Error;\n this.logger.warn(\n \"No gated descriptor found for proxy implementation address\",\n {\n data: {\n to,\n implementationAddress,\n selector,\n chainId,\n directError: directError.message,\n implError: implError.message,\n },\n },\n );\n return [errorContext];\n }\n\n const { signedDescriptor } = implGatedResult.unsafeCoerce();\n const [proxyCertificate, gatedCertificate] = await Promise.all([\n this._certificateLoader.loadCertificate({\n keyId: proxyData.keyId,\n keyUsage: proxyData.keyUsage,\n targetDevice: deviceModelId,\n }),\n this._loadGatedCertificate(deviceModelId),\n ]);\n\n this.logger.debug(\"load result\", {\n data: {\n path: \"proxy\",\n to,\n implementationAddress,\n selector,\n chainId,\n contextTypes: [\n ClearSignContextType.ETHEREUM_PROXY_INFO,\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ],\n },\n });\n return [\n {\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxyData.signedDescriptor,\n certificate: proxyCertificate,\n },\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: gatedCertificate,\n },\n ];\n }\n\n private _loadGatedCertificate(deviceModelId: DeviceModelId) {\n return this._certificateLoader.loadCertificate({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: deviceModelId,\n });\n }\n}\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M,CACJ,KAAM,QACN,GAAAH,EACA,sBAAAY,EACA,SAAAX,EACA,QAAAC,EACA,aAAc,CACZ,uBAAqB,oBACrB,uBAAqB,sBACvB,CACF,CACF,CAAC,EACM,CACL,CACE,KAAM,uBAAqB,oBAC3B,QAASS,EAAU,iBACnB,YAAaI,CACf,EACA,CACE,KAAM,uBAAqB,uBAC3B,QAASV,EACT,YAAaW,CACf,CACF,CACF,CAEQ,sBAAsBb,EAA8B,CAC1D,OAAO,KAAK,mBAAmB,gBAAgB,CAC7C,MAAO,QAAM,gBACb,SAAU,WAAS,aACnB,aAAcA,CAChB,CAAC,CACH,CACF,EA/KaX,EAANyB,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,oBAAkB,yBAAyB,GAElDA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,aAAW,eAAe,GAEjCA,EAAA,eAAO,cAAY,0BAA0B,IAZrC1B",
|
|
6
|
+
"names": ["GatedSigningContextLoader_exports", "__export", "GatedSigningContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_configTypes", "import_gatedSigningTypes", "import_proxyTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "SUPPORTED_TYPES", "normalizeAddress", "address", "lower", "GatedSigningContextLoader", "_dataSource", "_certificateLoader", "_proxyDataSource", "loggerFactory", "input", "expectedTypes", "type", "to", "selector", "chainId", "deviceModelId", "directResult", "signedDescriptor", "certificate", "directError", "errorContext", "proxyResult", "proxyError", "proxyData", "implementationAddress", "implGatedResult", "implError", "proxyCertificate", "gatedCertificate", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var d=require("@ledgerhq/device-management-kit"),i=require("purify-ts"),m=require("../../../../modules/ethereum/gated-signing/domain/GatedSigningContextLoader"),f=require("../../../../modules/multichain/pki/model/KeyId"),g=require("../../../../modules/multichain/pki/model/KeyUsage"),
|
|
1
|
+
"use strict";var d=require("@ledgerhq/device-management-kit"),i=require("purify-ts"),m=require("../../../../modules/ethereum/gated-signing/domain/GatedSigningContextLoader"),f=require("../../../../modules/multichain/pki/model/KeyId"),g=require("../../../../modules/multichain/pki/model/KeyUsage"),n=require("../../../../shared/model/ClearSignContext");describe("GatedSigningContextLoader",()=>{const o={getGatedDescriptor:vi.fn(),getGatedDescriptorForTypedData:vi.fn()},c={loadCertificate:vi.fn()},s={getProxyImplementationAddress:vi.fn()},h=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]}),r=new m.GatedSigningContextLoader(o,c,s,h),x={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},l=[n.ClearSignContextType.ETHEREUM_GATED_SIGNING];beforeEach(()=>{vi.resetAllMocks(),vi.spyOn(c,"loadCertificate").mockResolvedValue(x)}),describe("canHandle function",()=>{const e={to:"0x1111111254fb6c44bac0bed2854e76f90643097d",selector:"0xa1251d75",chainId:1,deviceModelId:d.DeviceModelId.STAX};it("should return true for valid input",()=>{expect(r.canHandle(e,l)).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(r.canHandle(e,[n.ClearSignContextType.ETHEREUM_TOKEN])).toBe(!1),expect(r.canHandle(e,[n.ClearSignContextType.ETHEREUM_DYNAMIC_NETWORK])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(a,t)=>{expect(r.canHandle(a,l)).toBe(!1)}),it.each([[{...e,to:void 0},"missing to"],[{...e,selector:void 0},"missing selector"],[{...e,chainId:void 0},"missing chainId"],[{...e,deviceModelId:void 0},"missing deviceModelId"]])("should return false for %s",(a,t)=>{expect(r.canHandle(a,l)).toBe(!1)}),it.each([[{...e,to:"0x"},"empty to (0x)"],[{...e,to:"not-hex"},"non-hex to"],[{...e,selector:"not-hex"},"non-hex selector"],[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"]])("should return false for %s",(a,t)=>{expect(r.canHandle(a,l)).toBe(!1)})}),describe("load function",()=>{const e={to:"0x1111111254fb6c44bac0bed2854e76f90643097d",selector:"0xa1251d75",chainId:1,deviceModelId:d.DeviceModelId.STAX},a="010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100";it("should return error context when getGatedDescriptor returns Left and proxy resolution fails",async()=>{const t=new Error("Failed to fetch gated descriptors");vi.spyOn(o,"getGatedDescriptor").mockResolvedValue((0,i.Left)(t)),vi.spyOn(s,"getProxyImplementationAddress").mockResolvedValue((0,i.Left)(new Error("Not a proxy")));const p=await r.load(e);expect(p).toEqual([{type:n.ClearSignContextType.ERROR,error:t}]),expect(o.getGatedDescriptor).toHaveBeenCalledWith({contractAddress:e.to,selector:e.selector,chainId:e.chainId}),expect(s.getProxyImplementationAddress).toHaveBeenCalledWith({proxyAddress:e.to,chainId:e.chainId,challenge:"",calldata:"0x"}),expect(c.loadCertificate).not.toHaveBeenCalled()}),it("should return gated signing context when getGatedDescriptor succeeds",async()=>{vi.spyOn(o,"getGatedDescriptor").mockResolvedValue((0,i.Right)({signedDescriptor:a}));const t=await r.load(e);expect(t).toHaveLength(1),expect(t[0]).toMatchObject({type:n.ClearSignContextType.ETHEREUM_GATED_SIGNING,payload:a,certificate:x}),expect(o.getGatedDescriptor).toHaveBeenCalledWith({contractAddress:e.to,selector:e.selector,chainId:e.chainId}),expect(c.loadCertificate).toHaveBeenCalledWith({keyId:f.KeyId.CalGatedSigning,keyUsage:g.KeyUsage.GatedSigning,targetDevice:e.deviceModelId})}),it("should pass to as contractAddress to getGatedDescriptor",async()=>{const t="0xabcdef1234567890abcdef1234567890abcdef12";vi.spyOn(o,"getGatedDescriptor").mockResolvedValue((0,i.Right)({signedDescriptor:a})),await r.load({...e,to:t}),expect(o.getGatedDescriptor).toHaveBeenCalledWith(expect.objectContaining({contractAddress:t}))}),it("should request certificate for correct device model",async()=>{vi.spyOn(o,"getGatedDescriptor").mockResolvedValue((0,i.Right)({signedDescriptor:a})),await r.load({...e,deviceModelId:d.DeviceModelId.FLEX}),expect(c.loadCertificate).toHaveBeenCalledWith({keyId:f.KeyId.CalGatedSigning,keyUsage:g.KeyUsage.GatedSigning,targetDevice:d.DeviceModelId.FLEX})}),it("should reject when certificate loading fails",async()=>{const t=new Error("Certificate loading failed");vi.spyOn(o,"getGatedDescriptor").mockResolvedValue((0,i.Right)({signedDescriptor:a})),vi.spyOn(c,"loadCertificate").mockRejectedValue(t),await expect(r.load(e)).rejects.toThrow(t)}),it("should return PROXY_INFO and GATED_SIGNING when to is proxy and gated descriptor exists for implementation",async()=>{const t="0xabcdef1234567890abcdef1234567890abcdef12",p="0xproxy-descriptor";vi.spyOn(o,"getGatedDescriptor").mockResolvedValueOnce((0,i.Left)(new Error("No gated descriptor"))).mockResolvedValueOnce((0,i.Right)({signedDescriptor:a})),vi.spyOn(s,"getProxyImplementationAddress").mockResolvedValue((0,i.Right)({implementationAddress:t,signedDescriptor:p,keyId:"domain-metadata",keyUsage:"trusted-name"}));const u=await r.load(e);expect(u).toHaveLength(2),expect(u[0]).toMatchObject({type:n.ClearSignContextType.ETHEREUM_PROXY_INFO,payload:p}),expect(u[1]).toMatchObject({type:n.ClearSignContextType.ETHEREUM_GATED_SIGNING,payload:a}),expect(o.getGatedDescriptor).toHaveBeenCalledTimes(2),expect(o.getGatedDescriptor).toHaveBeenNthCalledWith(1,{contractAddress:e.to,selector:e.selector,chainId:e.chainId}),expect(o.getGatedDescriptor).toHaveBeenNthCalledWith(2,{contractAddress:t.toLowerCase(),selector:e.selector,chainId:e.chainId})})})});
|
|
2
2
|
//# sourceMappingURL=GatedSigningContextLoader.test.js.map
|
package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport {\n type GatedSigningContextInput,\n GatedSigningContextLoader,\n} from \"@/modules/ethereum/gated-signing/domain/GatedSigningContextLoader\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"GatedSigningContextLoader\", () => {\n const mockGatedDescriptorDataSource: GatedDescriptorDataSource = {\n getGatedDescriptor: vi.fn(),\n getGatedDescriptorForTypedData: vi.fn(),\n };\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockProxyDataSource: ProxyDataSource = {\n getProxyImplementationAddress: vi.fn(),\n };\n\n const loader = new GatedSigningContextLoader(\n mockGatedDescriptorDataSource,\n mockCertificateLoader,\n mockProxyDataSource,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ];\n\n beforeEach(() => {\n vi.resetAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: GatedSigningContextInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n it(\"should return true for valid input\", () => {\n expect(loader.canHandle(validInput, SUPPORTED_TYPES)).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.ETHEREUM_TOKEN]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.ETHEREUM_DYNAMIC_NETWORK,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing deviceModelId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"0x\" }, \"empty to (0x)\"],\n [{ ...validInput, to: \"not-hex\" }, \"non-hex to\"],\n [{ ...validInput, selector: \"not-hex\" }, \"non-hex selector\"],\n [{ ...validInput, chainId: \"1\" as unknown as number }, \"string chainId\"],\n [{ ...validInput, chainId: null as unknown as number }, \"null chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n const validInput: GatedSigningContextInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n const signedDescriptor =\n \"010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100\";\n\n it(\"should return error context when getGatedDescriptor returns Left and proxy resolution fails\", async () => {\n const error = new Error(\"Failed to fetch gated descriptors\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Left(error));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(new Error(\"Not a proxy\")));\n\n const result = await loader.load(validInput);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith({\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n proxyAddress: validInput.to,\n chainId: validInput.chainId,\n challenge: \"\",\n calldata: \"0x\",\n });\n expect(mockCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should return gated signing context when getGatedDescriptor succeeds\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: mockCertificate,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith({\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: validInput.deviceModelId,\n });\n });\n\n it(\"should pass to as contractAddress to getGatedDescriptor\", async () => {\n const customTo = \"0xabcdef1234567890abcdef1234567890abcdef12\";\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n to: customTo,\n });\n\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith(\n expect.objectContaining({\n contractAddress: customTo,\n }),\n );\n });\n\n it(\"should request certificate for correct device model\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: DeviceModelId.FLEX,\n });\n });\n\n it(\"should reject when certificate loading fails\", async () => {\n const certificateError = new Error(\"Certificate loading failed\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockRejectedValue(\n certificateError,\n );\n\n await expect(loader.load(validInput)).rejects.toThrow(certificateError);\n });\n\n it(\"should return PROXY_INFO and GATED_SIGNING when to is proxy and gated descriptor exists for implementation\", async () => {\n const implementationAddress =\n \"0xabcdef1234567890abcdef1234567890abcdef12\";\n const proxySignedDescriptor = \"0xproxy-descriptor\";\n vi.spyOn(mockGatedDescriptorDataSource, \"getGatedDescriptor\")\n .mockResolvedValueOnce(Left(new Error(\"No gated descriptor\")))\n .mockResolvedValueOnce(Right({ signedDescriptor }));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(\n Right({\n implementationAddress,\n signedDescriptor: proxySignedDescriptor,\n keyId: \"domain-metadata\",\n keyUsage: \"trusted-name\",\n }),\n );\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxySignedDescriptor,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledTimes(2);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenNthCalledWith(1, {\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenNthCalledWith(2, {\n contractAddress: implementationAddress.toLowerCase(),\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAG5BC,EAGO,6EAGPC,EAAsB,gDACtBC,EAAyB,mDAEzBC,EAAqC,2CAErC,SAAS,4BAA6B,IAAM,CAC1C,MAAMC,EAA2D,CAC/D,mBAAoB,GAAG,GAAG,EAC1B,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAuC,CAC3C,8BAA+B,GAAG,GAAG,CACvC,EAEMC,EAAS,IAAI,
|
|
6
|
-
"names": ["import_device_management_kit", "import_purify_ts", "import_GatedSigningContextLoader", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "mockGatedDescriptorDataSource", "mockCertificateLoader", "mockProxyDataSource", "loader", "mockCertificate", "SUPPORTED_TYPES", "validInput", "input", "_description", "signedDescriptor", "error", "result", "customTo", "certificateError", "implementationAddress", "proxySignedDescriptor"]
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport {\n type GatedSigningContextInput,\n GatedSigningContextLoader,\n} from \"@/modules/ethereum/gated-signing/domain/GatedSigningContextLoader\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"GatedSigningContextLoader\", () => {\n const mockGatedDescriptorDataSource: GatedDescriptorDataSource = {\n getGatedDescriptor: vi.fn(),\n getGatedDescriptorForTypedData: vi.fn(),\n };\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockProxyDataSource: ProxyDataSource = {\n getProxyImplementationAddress: vi.fn(),\n };\n\n const mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n });\n\n const loader = new GatedSigningContextLoader(\n mockGatedDescriptorDataSource,\n mockCertificateLoader,\n mockProxyDataSource,\n mockLoggerFactory,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ];\n\n beforeEach(() => {\n vi.resetAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: GatedSigningContextInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n it(\"should return true for valid input\", () => {\n expect(loader.canHandle(validInput, SUPPORTED_TYPES)).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.ETHEREUM_TOKEN]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.ETHEREUM_DYNAMIC_NETWORK,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing deviceModelId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"0x\" }, \"empty to (0x)\"],\n [{ ...validInput, to: \"not-hex\" }, \"non-hex to\"],\n [{ ...validInput, selector: \"not-hex\" }, \"non-hex selector\"],\n [{ ...validInput, chainId: \"1\" as unknown as number }, \"string chainId\"],\n [{ ...validInput, chainId: null as unknown as number }, \"null chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n const validInput: GatedSigningContextInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n const signedDescriptor =\n \"010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100\";\n\n it(\"should return error context when getGatedDescriptor returns Left and proxy resolution fails\", async () => {\n const error = new Error(\"Failed to fetch gated descriptors\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Left(error));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(new Error(\"Not a proxy\")));\n\n const result = await loader.load(validInput);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith({\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n proxyAddress: validInput.to,\n chainId: validInput.chainId,\n challenge: \"\",\n calldata: \"0x\",\n });\n expect(mockCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should return gated signing context when getGatedDescriptor succeeds\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: mockCertificate,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith({\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: validInput.deviceModelId,\n });\n });\n\n it(\"should pass to as contractAddress to getGatedDescriptor\", async () => {\n const customTo = \"0xabcdef1234567890abcdef1234567890abcdef12\";\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n to: customTo,\n });\n\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith(\n expect.objectContaining({\n contractAddress: customTo,\n }),\n );\n });\n\n it(\"should request certificate for correct device model\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: DeviceModelId.FLEX,\n });\n });\n\n it(\"should reject when certificate loading fails\", async () => {\n const certificateError = new Error(\"Certificate loading failed\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockRejectedValue(\n certificateError,\n );\n\n await expect(loader.load(validInput)).rejects.toThrow(certificateError);\n });\n\n it(\"should return PROXY_INFO and GATED_SIGNING when to is proxy and gated descriptor exists for implementation\", async () => {\n const implementationAddress =\n \"0xabcdef1234567890abcdef1234567890abcdef12\";\n const proxySignedDescriptor = \"0xproxy-descriptor\";\n vi.spyOn(mockGatedDescriptorDataSource, \"getGatedDescriptor\")\n .mockResolvedValueOnce(Left(new Error(\"No gated descriptor\")))\n .mockResolvedValueOnce(Right({ signedDescriptor }));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(\n Right({\n implementationAddress,\n signedDescriptor: proxySignedDescriptor,\n keyId: \"domain-metadata\",\n keyUsage: \"trusted-name\",\n }),\n );\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxySignedDescriptor,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledTimes(2);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenNthCalledWith(1, {\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenNthCalledWith(2, {\n contractAddress: implementationAddress.toLowerCase(),\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAG5BC,EAGO,6EAGPC,EAAsB,gDACtBC,EAAyB,mDAEzBC,EAAqC,2CAErC,SAAS,4BAA6B,IAAM,CAC1C,MAAMC,EAA2D,CAC/D,mBAAoB,GAAG,GAAG,EAC1B,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAuC,CAC3C,8BAA+B,GAAG,GAAG,CACvC,EAEMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEMC,EAAS,IAAI,4BACjBJ,EACAC,EACAC,EACAC,CACF,EAEME,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEMC,EAA0C,CAC9C,uBAAqB,sBACvB,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjB,GAAG,MAAML,EAAuB,iBAAiB,EAAE,kBACjDI,CACF,CACF,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,MAAME,EAAuC,CAC3C,GAAI,6CACJ,SAAU,aACV,QAAS,EACT,cAAe,gBAAc,IAC/B,EAEA,GAAG,qCAAsC,IAAM,CAC7C,OAAOH,EAAO,UAAUG,EAAYD,CAAe,CAAC,EAAE,KAAK,EAAI,CACjE,CAAC,EAED,GAAG,gDAAiD,IAAM,CACxD,OACEF,EAAO,UAAUG,EAAY,CAAC,uBAAqB,cAAc,CAAC,CACpE,EAAE,KAAK,EAAK,EACZ,OACEH,EAAO,UAAUG,EAAY,CAC3B,uBAAqB,wBACvB,CAAC,CACH,EAAE,KAAK,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AAc,CAC9B,KAAM,uBAAqB,oBAC3B,QAASI,CACX,CAAC,EACD,OAAOJ,EAAO,CAAC,CAAC,EAAE,cAAc,CAC9B,KAAM,uBAAqB,uBAC3B,QAASF,CACX,CAAC,EACD,OACEV,EAA8B,kBAChC,EAAE,sBAAsB,CAAC,EACzB,OACEA,EAA8B,kBAChC,EAAE,wBAAwB,EAAG,CAC3B,gBAAiBO,EAAW,GAC5B,SAAUA,EAAW,SACrB,QAASA,EAAW,OACtB,CAAC,EACD,OACEP,EAA8B,kBAChC,EAAE,wBAAwB,EAAG,CAC3B,gBAAiBe,EAAsB,YAAY,EACnD,SAAUR,EAAW,SACrB,QAASA,EAAW,OACtB,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_device_management_kit", "import_purify_ts", "import_GatedSigningContextLoader", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "mockGatedDescriptorDataSource", "mockCertificateLoader", "mockProxyDataSource", "mockLoggerFactory", "loader", "mockCertificate", "SUPPORTED_TYPES", "validInput", "input", "_description", "signedDescriptor", "error", "result", "customTo", "certificateError", "implementationAddress", "proxySignedDescriptor"]
|
|
7
7
|
}
|
package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var N=(o,e)=>{for(var t in e)m(o,t,{get:e[t],enumerable:!0})},U=(o,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of L(e))!b.call(o,r)&&r!==t&&m(o,r,{get:()=>e[r],enumerable:!(a=h(e,r))||a.enumerable});return o};var M=o=>U(m({},"__esModule",{value:!0}),o),G=(o,e,t,a)=>{for(var r=a>1?void 0:a?h(e,t):e,i=o.length-1,n;i>=0;i--)(n=o[i])&&(r=(a?n(e,t,r):n(r))||r);return a&&r&&m(e,t,r),r},g=(o,e)=>(t,a)=>e(t,a,o);var Y={};N(Y,{GatedSigningTypedDataContextLoader:()=>y});module.exports=M(Y);var d=require("inversify"),R=require("../../../../config/di/configTypes"),_=require("../../../../modules/ethereum/gated-signing/di/gatedSigningTypes"),I=require("../../../../modules/ethereum/proxy/di/proxyTypes"),k=require("../../../../modules/ethereum/typed-data/utils/getSchemaHash"),v=require("../../../../modules/multichain/pki/di/pkiTypes"),C=require("../../../../modules/multichain/pki/model/KeyId"),T=require("../../../../modules/multichain/pki/model/KeyUsage"),s=require("../../../../shared/model/ClearSignContext");const O="0x0000000000000000000000000000000000000000",j=[s.ClearSignContextType.ETHEREUM_GATED_SIGNING];function F(o){if(!o||typeof o!="object")return!1;const e=o;if(!e.types||typeof e.types!="object"||Array.isArray(e.types))return!1;const t=e.types;for(const a of Object.keys(t)){if(typeof a!="string")return!1;const r=t[a];if(!Array.isArray(r))return!1;for(const i of r)if(!i||typeof i!="object"||typeof i.name!="string"||typeof i.type!="string")return!1}return!0}let y=class{constructor(e,t,a,r){this._dataSource=e;this._certificateLoader=t;this._proxyDataSource=a;this.logger=r("GatedSigningTypedDataContextLoader")}logger;canHandle(e,t){return j.every(a=>t.includes(a))&&typeof e=="object"&&e!==null&&"data"in e&&F(e.data)&&"chainId"in e&&"deviceModelId"in e&&e.deviceModelId!==void 0&&"challenge"in e&&typeof e.challenge=="string"}async load({data:e,chainId:t,deviceModelId:a,challenge:r}){const i=e.domain?.verifyingContract?.toLowerCase()??O,n=i.startsWith("0x")?i:`0x${i}`,p=(0,k.getSchemaHash)(e.types),u=await this._dataSource.getGatedDescriptorForTypedData({contractAddress:n,schemaHash:p,chainId:t});if(u.isRight()){const{signedDescriptor:c}=u.unsafeCoerce(),A=await this._certificateLoader.loadCertificate({keyId:C.KeyId.CalGatedSigning,keyUsage:T.KeyUsage.GatedSigning,targetDevice:a});return this.logger.debug("load result",{data:{path:"direct",verifyingContract:n,schemaHash:p,chainId:t,contextTypes:[s.ClearSignContextType.ETHEREUM_GATED_SIGNING]}}),[{type:s.ClearSignContextType.ETHEREUM_GATED_SIGNING,payload:c,certificate:A}]}const l=u.caseOf({Left:c=>c,Right:()=>new Error("unreachable")}),x=await this._proxyDataSource.getProxyImplementationAddress({proxyAddress:n,chainId:t,challenge:r,calldata:"0x"});if(x.isLeft()){const c=x.extract();return this.logger.warn("Direct gated descriptor lookup failed and proxy resolution failed",{data:{verifyingContract:n,schemaHash:p,chainId:t,directError:l.message,proxyError:c.message}}),[{type:s.ClearSignContextType.ERROR,error:l}]}const f=x.unsafeCoerce(),S=f.implementationAddress.toLowerCase(),D=S.startsWith("0x")?S:`0x${S}`,E=await this._dataSource.getGatedDescriptorForTypedData({contractAddress:D,schemaHash:p,chainId:t});if(E.isLeft()){const c=E.extract();return this.logger.warn("No gated descriptor found for proxy implementation address",{data:{verifyingContract:n,implementationAddress:D,schemaHash:p,chainId:t,directError:l.message,implError:c.message}}),[{type:s.ClearSignContextType.ERROR,error:l}]}const{signedDescriptor:w}=E.unsafeCoerce(),[P,H]=await Promise.all([this._certificateLoader.loadCertificate({keyId:f.keyId,keyUsage:f.keyUsage,targetDevice:a}),this._certificateLoader.loadCertificate({keyId:C.KeyId.CalGatedSigning,keyUsage:T.KeyUsage.GatedSigning,targetDevice:a})]);return this.logger.debug("load result",{data:{path:"proxy",verifyingContract:n,implementationAddress:D,schemaHash:p,chainId:t,contextTypes:[s.ClearSignContextType.ETHEREUM_PROXY_INFO,s.ClearSignContextType.ETHEREUM_GATED_SIGNING]}}),[{type:s.ClearSignContextType.ETHEREUM_PROXY_INFO,payload:f.signedDescriptor,certificate:P},{type:s.ClearSignContextType.ETHEREUM_GATED_SIGNING,payload:w,certificate:H}]}};y=G([(0,d.injectable)(),g(0,(0,d.inject)(_.gatedSigningTypes.GatedDescriptorDataSource)),g(1,(0,d.inject)(v.pkiTypes.PkiCertificateLoader)),g(2,(0,d.inject)(I.proxyTypes.ProxyDataSource)),g(3,(0,d.inject)(R.configTypes.ContextModuleLoggerFactory))],y);0&&(module.exports={GatedSigningTypedDataContextLoader});
|
|
2
2
|
//# sourceMappingURL=GatedSigningTypedDataContextLoader.js.map
|
package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n DeviceModelId,\n type HexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport { gatedSigningTypes } from \"@/modules/ethereum/gated-signing/di/gatedSigningTypes\";\nimport type { TypedDataSchema } from \"@/modules/ethereum/model/TypedDataContext\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/modules/ethereum/proxy/di/proxyTypes\";\nimport { getSchemaHash } from \"@/modules/ethereum/typed-data/utils/getSchemaHash\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nconst ZERO_ADDRESS = \"0x0000000000000000000000000000000000000000\";\n\nexport type GatedSigningTypedDataContextInput = {\n data: {\n types: TypedDataSchema;\n domain?: { verifyingContract?: string };\n };\n chainId: number;\n deviceModelId: DeviceModelId;\n challenge: string;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n];\n\nfunction hasTypedDataShape(\n data: unknown,\n): data is { types: TypedDataSchema; domain?: { verifyingContract?: string } } {\n if (!data || typeof data !== \"object\") return false;\n const obj = data as Record<string, unknown>;\n if (\n !obj[\"types\"] ||\n typeof obj[\"types\"] !== \"object\" ||\n Array.isArray(obj[\"types\"])\n ) {\n return false;\n }\n const types = obj[\"types\"] as Record<string, unknown>;\n for (const key of Object.keys(types)) {\n if (typeof key !== \"string\") return false;\n const value = types[key];\n if (!Array.isArray(value)) return false;\n for (const item of value) {\n if (\n !item ||\n typeof item !== \"object\" ||\n typeof (item as { name?: unknown }).name !== \"string\" ||\n typeof (item as { type?: unknown }).type !== \"string\"\n ) {\n return false;\n }\n }\n }\n return true;\n}\n\n@injectable()\nexport class GatedSigningTypedDataContextLoader\n implements ContextLoader<GatedSigningTypedDataContextInput>\n{\n constructor(\n @inject(gatedSigningTypes.GatedDescriptorDataSource)\n private readonly _dataSource: GatedDescriptorDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(proxyTypes.ProxyDataSource)\n private readonly _proxyDataSource: ProxyDataSource,\n ) {}\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is GatedSigningTypedDataContextInput {\n return (\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type)) &&\n typeof input === \"object\" &&\n input !== null &&\n \"data\" in input &&\n hasTypedDataShape((input as GatedSigningTypedDataContextInput).data) &&\n \"chainId\" in input &&\n \"deviceModelId\" in input &&\n (input as GatedSigningTypedDataContextInput).deviceModelId !==\n undefined &&\n \"challenge\" in input &&\n typeof (input as GatedSigningTypedDataContextInput).challenge === \"string\"\n );\n }\n\n async load({\n data,\n chainId,\n deviceModelId,\n challenge,\n }: GatedSigningTypedDataContextInput): Promise<ClearSignContext[]> {\n const raw = data.domain?.verifyingContract?.toLowerCase() ?? ZERO_ADDRESS;\n const verifyingContract: HexaString = raw.startsWith(\"0x\")\n ? (raw as HexaString)\n : (`0x${raw}` as HexaString);\n const schemaHash = getSchemaHash(data.types);\n\n const directResult = await this._dataSource.getGatedDescriptorForTypedData({\n contractAddress: verifyingContract,\n schemaHash,\n chainId,\n });\n\n if (directResult.isRight()) {\n const { signedDescriptor } = directResult.unsafeCoerce();\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: deviceModelId,\n });\n return [\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate,\n },\n ];\n }\n\n const firstError: Error = directResult.caseOf({\n Left: (error) => error,\n Right: () => new Error(\"unreachable\"),\n });\n\n const proxyResult =\n await this._proxyDataSource.getProxyImplementationAddress({\n proxyAddress: verifyingContract,\n chainId,\n challenge,\n calldata: \"0x\",\n });\n\n if (proxyResult.isLeft()) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: firstError,\n },\n ];\n }\n\n const proxyData = proxyResult.unsafeCoerce();\n const implRaw = proxyData.implementationAddress.toLowerCase();\n const implementationAddress: HexaString = implRaw.startsWith(\"0x\")\n ? (implRaw as HexaString)\n : (`0x${implRaw}` as HexaString);\n\n const implGatedResult =\n await this._dataSource.getGatedDescriptorForTypedData({\n contractAddress: implementationAddress,\n schemaHash,\n chainId,\n });\n\n if (implGatedResult.isLeft()) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: firstError,\n },\n ];\n }\n\n const { signedDescriptor } = implGatedResult.unsafeCoerce();\n const [proxyCertificate, gatedCertificate] = await Promise.all([\n this._certificateLoader.loadCertificate({\n keyId: proxyData.keyId,\n keyUsage: proxyData.keyUsage,\n targetDevice: deviceModelId,\n }),\n this._certificateLoader.loadCertificate({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: deviceModelId,\n }),\n ]);\n\n return [\n {\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxyData.signedDescriptor,\n certificate: proxyCertificate,\n },\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: gatedCertificate,\n },\n ];\n }\n}\n"],
|
|
5
|
-
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wCAAAE,IAAA,eAAAC,EAAAH,
|
|
6
|
-
"names": ["GatedSigningTypedDataContextLoader_exports", "__export", "GatedSigningTypedDataContextLoader", "__toCommonJS", "import_inversify", "import_gatedSigningTypes", "import_proxyTypes", "import_getSchemaHash", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "ZERO_ADDRESS", "SUPPORTED_TYPES", "hasTypedDataShape", "data", "obj", "types", "key", "value", "item", "GatedSigningTypedDataContextLoader", "_dataSource", "_certificateLoader", "_proxyDataSource", "input", "expectedTypes", "type", "chainId", "deviceModelId", "challenge", "raw", "verifyingContract", "schemaHash", "directResult", "signedDescriptor", "certificate", "firstError", "error", "proxyResult", "proxyData", "implRaw", "implementationAddress", "implGatedResult", "proxyCertificate", "gatedCertificate", "__decorateClass", "__decorateParam"]
|
|
4
|
+
"sourcesContent": ["import {\n DeviceModelId,\n type HexaString,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport { gatedSigningTypes } from \"@/modules/ethereum/gated-signing/di/gatedSigningTypes\";\nimport type { TypedDataSchema } from \"@/modules/ethereum/model/TypedDataContext\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/modules/ethereum/proxy/di/proxyTypes\";\nimport { getSchemaHash } from \"@/modules/ethereum/typed-data/utils/getSchemaHash\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nconst ZERO_ADDRESS = \"0x0000000000000000000000000000000000000000\";\n\nexport type GatedSigningTypedDataContextInput = {\n data: {\n types: TypedDataSchema;\n domain?: { verifyingContract?: string };\n };\n chainId: number;\n deviceModelId: DeviceModelId;\n challenge: string;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n];\n\nfunction hasTypedDataShape(\n data: unknown,\n): data is { types: TypedDataSchema; domain?: { verifyingContract?: string } } {\n if (!data || typeof data !== \"object\") return false;\n const obj = data as Record<string, unknown>;\n if (\n !obj[\"types\"] ||\n typeof obj[\"types\"] !== \"object\" ||\n Array.isArray(obj[\"types\"])\n ) {\n return false;\n }\n const types = obj[\"types\"] as Record<string, unknown>;\n for (const key of Object.keys(types)) {\n if (typeof key !== \"string\") return false;\n const value = types[key];\n if (!Array.isArray(value)) return false;\n for (const item of value) {\n if (\n !item ||\n typeof item !== \"object\" ||\n typeof (item as { name?: unknown }).name !== \"string\" ||\n typeof (item as { type?: unknown }).type !== \"string\"\n ) {\n return false;\n }\n }\n }\n return true;\n}\n\n@injectable()\nexport class GatedSigningTypedDataContextLoader\n implements ContextLoader<GatedSigningTypedDataContextInput>\n{\n private readonly logger: LoggerPublisherService;\n\n constructor(\n @inject(gatedSigningTypes.GatedDescriptorDataSource)\n private readonly _dataSource: GatedDescriptorDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(proxyTypes.ProxyDataSource)\n private readonly _proxyDataSource: ProxyDataSource,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"GatedSigningTypedDataContextLoader\");\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is GatedSigningTypedDataContextInput {\n return (\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type)) &&\n typeof input === \"object\" &&\n input !== null &&\n \"data\" in input &&\n hasTypedDataShape((input as GatedSigningTypedDataContextInput).data) &&\n \"chainId\" in input &&\n \"deviceModelId\" in input &&\n (input as GatedSigningTypedDataContextInput).deviceModelId !==\n undefined &&\n \"challenge\" in input &&\n typeof (input as GatedSigningTypedDataContextInput).challenge === \"string\"\n );\n }\n\n async load({\n data,\n chainId,\n deviceModelId,\n challenge,\n }: GatedSigningTypedDataContextInput): Promise<ClearSignContext[]> {\n const raw = data.domain?.verifyingContract?.toLowerCase() ?? ZERO_ADDRESS;\n const verifyingContract: HexaString = raw.startsWith(\"0x\")\n ? (raw as HexaString)\n : (`0x${raw}` as HexaString);\n const schemaHash = getSchemaHash(data.types);\n\n const directResult = await this._dataSource.getGatedDescriptorForTypedData({\n contractAddress: verifyingContract,\n schemaHash,\n chainId,\n });\n\n if (directResult.isRight()) {\n const { signedDescriptor } = directResult.unsafeCoerce();\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: deviceModelId,\n });\n this.logger.debug(\"load result\", {\n data: {\n path: \"direct\",\n verifyingContract,\n schemaHash,\n chainId,\n contextTypes: [ClearSignContextType.ETHEREUM_GATED_SIGNING],\n },\n });\n return [\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate,\n },\n ];\n }\n\n const firstError: Error = directResult.caseOf({\n Left: (error) => error,\n Right: () => new Error(\"unreachable\"),\n });\n\n const proxyResult =\n await this._proxyDataSource.getProxyImplementationAddress({\n proxyAddress: verifyingContract,\n chainId,\n challenge,\n calldata: \"0x\",\n });\n\n if (proxyResult.isLeft()) {\n const proxyError = proxyResult.extract() as Error;\n this.logger.warn(\n \"Direct gated descriptor lookup failed and proxy resolution failed\",\n {\n data: {\n verifyingContract,\n schemaHash,\n chainId,\n directError: firstError.message,\n proxyError: proxyError.message,\n },\n },\n );\n return [\n {\n type: ClearSignContextType.ERROR,\n error: firstError,\n },\n ];\n }\n\n const proxyData = proxyResult.unsafeCoerce();\n const implRaw = proxyData.implementationAddress.toLowerCase();\n const implementationAddress: HexaString = implRaw.startsWith(\"0x\")\n ? (implRaw as HexaString)\n : (`0x${implRaw}` as HexaString);\n\n const implGatedResult =\n await this._dataSource.getGatedDescriptorForTypedData({\n contractAddress: implementationAddress,\n schemaHash,\n chainId,\n });\n\n if (implGatedResult.isLeft()) {\n const implError = implGatedResult.extract() as Error;\n this.logger.warn(\n \"No gated descriptor found for proxy implementation address\",\n {\n data: {\n verifyingContract,\n implementationAddress,\n schemaHash,\n chainId,\n directError: firstError.message,\n implError: implError.message,\n },\n },\n );\n return [\n {\n type: ClearSignContextType.ERROR,\n error: firstError,\n },\n ];\n }\n\n const { signedDescriptor } = implGatedResult.unsafeCoerce();\n const [proxyCertificate, gatedCertificate] = await Promise.all([\n this._certificateLoader.loadCertificate({\n keyId: proxyData.keyId,\n keyUsage: proxyData.keyUsage,\n targetDevice: deviceModelId,\n }),\n this._certificateLoader.loadCertificate({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: deviceModelId,\n }),\n ]);\n\n this.logger.debug(\"load result\", {\n data: {\n path: \"proxy\",\n verifyingContract,\n implementationAddress,\n schemaHash,\n chainId,\n contextTypes: [\n ClearSignContextType.ETHEREUM_PROXY_INFO,\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ],\n },\n });\n return [\n {\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxyData.signedDescriptor,\n certificate: proxyCertificate,\n },\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,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,eAAO,aAAW,eAAe,GAEjCA,EAAA,eAAO,cAAY,0BAA0B,IAZrC7B",
|
|
6
|
+
"names": ["GatedSigningTypedDataContextLoader_exports", "__export", "GatedSigningTypedDataContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_gatedSigningTypes", "import_proxyTypes", "import_getSchemaHash", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "ZERO_ADDRESS", "SUPPORTED_TYPES", "hasTypedDataShape", "data", "obj", "types", "key", "value", "item", "GatedSigningTypedDataContextLoader", "_dataSource", "_certificateLoader", "_proxyDataSource", "loggerFactory", "input", "expectedTypes", "type", "chainId", "deviceModelId", "challenge", "raw", "verifyingContract", "schemaHash", "directResult", "signedDescriptor", "certificate", "firstError", "error", "proxyResult", "proxyError", "proxyData", "implRaw", "implementationAddress", "implGatedResult", "implError", "proxyCertificate", "gatedCertificate", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=require("@ledgerhq/device-management-kit"),n=require("purify-ts"),m=require("../../../../modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader"),g=require("../../../../modules/multichain/pki/model/KeyId"),h=require("../../../../modules/multichain/pki/model/KeyUsage"),c=require("../../../../shared/model/ClearSignContext");describe("GatedSigningTypedDataContextLoader",()=>{const a={getGatedDescriptor:vi.fn(),getGatedDescriptorForTypedData:vi.fn()},s={loadCertificate:vi.fn()},l={getProxyImplementationAddress:vi.fn()},u=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]}),t=new m.GatedSigningTypedDataContextLoader(a,s,l,u),f={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},i=[c.ClearSignContextType.ETHEREUM_GATED_SIGNING],e={data:{types:{EIP712Domain:[{name:"name",type:"string"},{name:"chainId",type:"uint256"}],Mail:[{name:"subject",type:"string"}]},domain:{verifyingContract:"0x1111111254fb6c44bac0bed2854e76f90643097d"}},chainId:1,deviceModelId:r.DeviceModelId.STAX,challenge:"test-challenge"};beforeEach(()=>{vi.resetAllMocks(),vi.spyOn(s,"loadCertificate").mockResolvedValue(f)}),describe("canHandle",()=>{it("should return true for valid typed data input",()=>{expect(t.canHandle(e,i)).toBe(!0)}),it("should return false when expected types do not include GATED_SIGNING",()=>{expect(t.canHandle(e,[c.ClearSignContextType.ETHEREUM_TOKEN])).toBe(!1),expect(t.canHandle(e,[c.ClearSignContextType.ETHEREUM_DYNAMIC_NETWORK])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"]])("should return false for %s",(d,o)=>{expect(t.canHandle(d,i)).toBe(!1)}),it("should return false for transaction-style input (selector, to)",()=>{const d={to:"0x1111111254fb6c44bac0bed2854e76f90643097d",selector:"0xa1251d75",chainId:1,deviceModelId:r.DeviceModelId.STAX};expect(t.canHandle(d,i)).toBe(!1)}),it("should return false when data is missing",()=>{expect(t.canHandle({chainId:1,deviceModelId:r.DeviceModelId.STAX},i)).toBe(!1)}),it("should return false when data.types is not a valid schema",()=>{expect(t.canHandle({data:{types:"not-an-object"},chainId:1,deviceModelId:r.DeviceModelId.STAX,challenge:e.challenge},i)).toBe(!1),expect(t.canHandle({data:{types:{}},chainId:1,deviceModelId:r.DeviceModelId.STAX,challenge:e.challenge},i)).toBe(!0)}),it("should return false when chainId or deviceModelId is missing",()=>{expect(t.canHandle({data:e.data,deviceModelId:r.DeviceModelId.STAX,challenge:e.challenge},i)).toBe(!1),expect(t.canHandle({data:e.data,chainId:1,challenge:e.challenge},i)).toBe(!1)}),it("should return false when challenge is missing",()=>{expect(t.canHandle({data:e.data,chainId:1,deviceModelId:r.DeviceModelId.STAX},i)).toBe(!1)})}),describe("load",()=>{const d="010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100";it("should return error context when getGatedDescriptorForTypedData returns Left and proxy resolution fails",async()=>{const o=new Error("No gated descriptor for schema hash");vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValue((0,n.Left)(o)),vi.spyOn(l,"getProxyImplementationAddress").mockResolvedValue((0,n.Left)(new Error("Not a proxy")));const p=await t.load(e);expect(p).toEqual([{type:c.ClearSignContextType.ERROR,error:o}]),expect(a.getGatedDescriptorForTypedData).toHaveBeenCalledWith({contractAddress:e.data.domain.verifyingContract.toLowerCase(),schemaHash:expect.any(String),chainId:e.chainId}),expect(l.getProxyImplementationAddress).toHaveBeenCalledWith({proxyAddress:e.data.domain.verifyingContract.toLowerCase(),chainId:e.chainId,challenge:e.challenge,calldata:"0x"}),expect(s.loadCertificate).not.toHaveBeenCalled()}),it("should return gated signing context when getGatedDescriptorForTypedData succeeds",async()=>{vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValue((0,n.Right)({signedDescriptor:d}));const o=await t.load(e);expect(o).toHaveLength(1),expect(o[0]).toMatchObject({type:c.ClearSignContextType.ETHEREUM_GATED_SIGNING,payload:d,certificate:f}),expect(a.getGatedDescriptorForTypedData).toHaveBeenCalledWith({contractAddress:e.data.domain.verifyingContract.toLowerCase(),schemaHash:expect.any(String),chainId:e.chainId}),expect(s.loadCertificate).toHaveBeenCalledWith({keyId:g.KeyId.CalGatedSigning,keyUsage:h.KeyUsage.GatedSigning,targetDevice:e.deviceModelId})}),it("should use zero address when domain.verifyingContract is missing",async()=>{vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValue((0,n.Right)({signedDescriptor:d})),await t.load({data:{types:e.data.types},chainId:e.chainId,deviceModelId:e.deviceModelId,challenge:e.challenge}),expect(a.getGatedDescriptorForTypedData).toHaveBeenCalledWith(expect.objectContaining({contractAddress:"0x0000000000000000000000000000000000000000"}))}),it("should request certificate for correct device model",async()=>{vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValue((0,n.Right)({signedDescriptor:d})),await t.load({...e,deviceModelId:r.DeviceModelId.FLEX}),expect(s.loadCertificate).toHaveBeenCalledWith({keyId:g.KeyId.CalGatedSigning,keyUsage:h.KeyUsage.GatedSigning,targetDevice:r.DeviceModelId.FLEX})}),it("should reject when certificate loading fails",async()=>{const o=new Error("Certificate loading failed");vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValue((0,n.Right)({signedDescriptor:d})),vi.spyOn(s,"loadCertificate").mockRejectedValue(o),await expect(t.load(e)).rejects.toThrow(o)}),it("should return PROXY_INFO and GATED_SIGNING when verifying contract is proxy and gated descriptor exists for implementation",async()=>{const o="0xabcdef1234567890abcdef1234567890abcdef12",p="0xproxy-descriptor";vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValueOnce((0,n.Left)(new Error("No gated descriptor"))).mockResolvedValueOnce((0,n.Right)({signedDescriptor:d})),vi.spyOn(l,"getProxyImplementationAddress").mockResolvedValue((0,n.Right)({implementationAddress:o,signedDescriptor:p,keyId:"domain-metadata",keyUsage:"trusted-name"}));const y=await t.load(e);expect(y).toHaveLength(2),expect(y[0]).toMatchObject({type:c.ClearSignContextType.ETHEREUM_PROXY_INFO,payload:p}),expect(y[1]).toMatchObject({type:c.ClearSignContextType.ETHEREUM_GATED_SIGNING,payload:d}),expect(a.getGatedDescriptorForTypedData).toHaveBeenCalledTimes(2),expect(a.getGatedDescriptorForTypedData).toHaveBeenNthCalledWith(1,{contractAddress:e.data.domain.verifyingContract.toLowerCase(),schemaHash:expect.any(String),chainId:e.chainId}),expect(a.getGatedDescriptorForTypedData).toHaveBeenNthCalledWith(2,{contractAddress:o.toLowerCase(),schemaHash:expect.any(String),chainId:e.chainId})})})});
|
|
2
2
|
//# sourceMappingURL=GatedSigningTypedDataContextLoader.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport {\n type GatedSigningTypedDataContextInput,\n GatedSigningTypedDataContextLoader,\n} from \"@/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"GatedSigningTypedDataContextLoader\", () => {\n const mockGatedDescriptorDataSource: GatedDescriptorDataSource = {\n getGatedDescriptor: vi.fn(),\n getGatedDescriptorForTypedData: vi.fn(),\n };\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockProxyDataSource: ProxyDataSource = {\n getProxyImplementationAddress: vi.fn(),\n };\n\n const loader = new GatedSigningTypedDataContextLoader(\n mockGatedDescriptorDataSource,\n mockCertificateLoader,\n mockProxyDataSource,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ];\n\n const validInput: GatedSigningTypedDataContextInput = {\n data: {\n types: {\n EIP712Domain: [\n { name: \"name\", type: \"string\" },\n { name: \"chainId\", type: \"uint256\" },\n ],\n Mail: [{ name: \"subject\", type: \"string\" }],\n },\n domain: {\n verifyingContract: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n },\n },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: \"test-challenge\",\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle\", () => {\n it(\"should return true for valid typed data input\", () => {\n expect(loader.canHandle(validInput, SUPPORTED_TYPES)).toBe(true);\n });\n\n it(\"should return false when expected types do not include GATED_SIGNING\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.ETHEREUM_TOKEN]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.ETHEREUM_DYNAMIC_NETWORK,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it(\"should return false for transaction-style input (selector, to)\", () => {\n const transactionInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n expect(loader.canHandle(transactionInput, SUPPORTED_TYPES)).toBe(false);\n });\n\n it(\"should return false when data is missing\", () => {\n expect(\n loader.canHandle(\n { chainId: 1, deviceModelId: DeviceModelId.STAX },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n\n it(\"should return false when data.types is not a valid schema\", () => {\n expect(\n loader.canHandle(\n {\n data: { types: \"not-an-object\" },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n {\n data: { types: {} },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(true);\n });\n\n it(\"should return false when chainId or deviceModelId is missing\", () => {\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n chainId: 1,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n\n it(\"should return false when challenge is missing\", () => {\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n });\n\n describe(\"load\", () => {\n const signedDescriptor =\n \"010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100\";\n\n it(\"should return error context when getGatedDescriptorForTypedData returns Left and proxy resolution fails\", async () => {\n const error = new Error(\"No gated descriptor for schema hash\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Left(error));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(new Error(\"Not a proxy\")));\n\n const result = await loader.load(validInput);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith({\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n proxyAddress: validInput.data.domain!.verifyingContract!.toLowerCase(),\n chainId: validInput.chainId,\n challenge: validInput.challenge,\n calldata: \"0x\",\n });\n expect(mockCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should return gated signing context when getGatedDescriptorForTypedData succeeds\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: mockCertificate,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith({\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: validInput.deviceModelId,\n });\n });\n\n it(\"should use zero address when domain.verifyingContract is missing\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n data: { types: validInput.data.types },\n chainId: validInput.chainId,\n deviceModelId: validInput.deviceModelId,\n challenge: validInput.challenge,\n });\n\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith(\n expect.objectContaining({\n contractAddress: \"0x0000000000000000000000000000000000000000\",\n }),\n );\n });\n\n it(\"should request certificate for correct device model\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: DeviceModelId.FLEX,\n });\n });\n\n it(\"should reject when certificate loading fails\", async () => {\n const certificateError = new Error(\"Certificate loading failed\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockRejectedValue(\n certificateError,\n );\n\n await expect(loader.load(validInput)).rejects.toThrow(certificateError);\n });\n\n it(\"should return PROXY_INFO and GATED_SIGNING when verifying contract is proxy and gated descriptor exists for implementation\", async () => {\n const implementationAddress =\n \"0xabcdef1234567890abcdef1234567890abcdef12\";\n const proxySignedDescriptor = \"0xproxy-descriptor\";\n vi.spyOn(mockGatedDescriptorDataSource, \"getGatedDescriptorForTypedData\")\n .mockResolvedValueOnce(Left(new Error(\"No gated descriptor\")))\n .mockResolvedValueOnce(Right({ signedDescriptor }));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(\n Right({\n implementationAddress,\n signedDescriptor: proxySignedDescriptor,\n keyId: \"domain-metadata\",\n keyUsage: \"trusted-name\",\n }),\n );\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxySignedDescriptor,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledTimes(2);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenNthCalledWith(1, {\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenNthCalledWith(2, {\n contractAddress: implementationAddress.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAG5BC,EAGO,sFAGPC,EAAsB,gDACtBC,EAAyB,mDAEzBC,EAAqC,2CAErC,SAAS,qCAAsC,IAAM,CACnD,MAAMC,EAA2D,CAC/D,mBAAoB,GAAG,GAAG,EAC1B,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAuC,CAC3C,8BAA+B,GAAG,GAAG,CACvC,EAEMC,EAAS,IAAI,
|
|
6
|
-
"names": ["import_device_management_kit", "import_purify_ts", "import_GatedSigningTypedDataContextLoader", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "mockGatedDescriptorDataSource", "mockCertificateLoader", "mockProxyDataSource", "loader", "mockCertificate", "SUPPORTED_TYPES", "validInput", "input", "_description", "transactionInput", "signedDescriptor", "error", "result", "certificateError", "implementationAddress", "proxySignedDescriptor"]
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport {\n type GatedSigningTypedDataContextInput,\n GatedSigningTypedDataContextLoader,\n} from \"@/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"GatedSigningTypedDataContextLoader\", () => {\n const mockGatedDescriptorDataSource: GatedDescriptorDataSource = {\n getGatedDescriptor: vi.fn(),\n getGatedDescriptorForTypedData: vi.fn(),\n };\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockProxyDataSource: ProxyDataSource = {\n getProxyImplementationAddress: vi.fn(),\n };\n\n const mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n });\n\n const loader = new GatedSigningTypedDataContextLoader(\n mockGatedDescriptorDataSource,\n mockCertificateLoader,\n mockProxyDataSource,\n mockLoggerFactory,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ];\n\n const validInput: GatedSigningTypedDataContextInput = {\n data: {\n types: {\n EIP712Domain: [\n { name: \"name\", type: \"string\" },\n { name: \"chainId\", type: \"uint256\" },\n ],\n Mail: [{ name: \"subject\", type: \"string\" }],\n },\n domain: {\n verifyingContract: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n },\n },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: \"test-challenge\",\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle\", () => {\n it(\"should return true for valid typed data input\", () => {\n expect(loader.canHandle(validInput, SUPPORTED_TYPES)).toBe(true);\n });\n\n it(\"should return false when expected types do not include GATED_SIGNING\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.ETHEREUM_TOKEN]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.ETHEREUM_DYNAMIC_NETWORK,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it(\"should return false for transaction-style input (selector, to)\", () => {\n const transactionInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n expect(loader.canHandle(transactionInput, SUPPORTED_TYPES)).toBe(false);\n });\n\n it(\"should return false when data is missing\", () => {\n expect(\n loader.canHandle(\n { chainId: 1, deviceModelId: DeviceModelId.STAX },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n\n it(\"should return false when data.types is not a valid schema\", () => {\n expect(\n loader.canHandle(\n {\n data: { types: \"not-an-object\" },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n {\n data: { types: {} },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(true);\n });\n\n it(\"should return false when chainId or deviceModelId is missing\", () => {\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n chainId: 1,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n\n it(\"should return false when challenge is missing\", () => {\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n });\n\n describe(\"load\", () => {\n const signedDescriptor =\n \"010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100\";\n\n it(\"should return error context when getGatedDescriptorForTypedData returns Left and proxy resolution fails\", async () => {\n const error = new Error(\"No gated descriptor for schema hash\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Left(error));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(new Error(\"Not a proxy\")));\n\n const result = await loader.load(validInput);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith({\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n proxyAddress: validInput.data.domain!.verifyingContract!.toLowerCase(),\n chainId: validInput.chainId,\n challenge: validInput.challenge,\n calldata: \"0x\",\n });\n expect(mockCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should return gated signing context when getGatedDescriptorForTypedData succeeds\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: mockCertificate,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith({\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: validInput.deviceModelId,\n });\n });\n\n it(\"should use zero address when domain.verifyingContract is missing\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n data: { types: validInput.data.types },\n chainId: validInput.chainId,\n deviceModelId: validInput.deviceModelId,\n challenge: validInput.challenge,\n });\n\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith(\n expect.objectContaining({\n contractAddress: \"0x0000000000000000000000000000000000000000\",\n }),\n );\n });\n\n it(\"should request certificate for correct device model\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: DeviceModelId.FLEX,\n });\n });\n\n it(\"should reject when certificate loading fails\", async () => {\n const certificateError = new Error(\"Certificate loading failed\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockRejectedValue(\n certificateError,\n );\n\n await expect(loader.load(validInput)).rejects.toThrow(certificateError);\n });\n\n it(\"should return PROXY_INFO and GATED_SIGNING when verifying contract is proxy and gated descriptor exists for implementation\", async () => {\n const implementationAddress =\n \"0xabcdef1234567890abcdef1234567890abcdef12\";\n const proxySignedDescriptor = \"0xproxy-descriptor\";\n vi.spyOn(mockGatedDescriptorDataSource, \"getGatedDescriptorForTypedData\")\n .mockResolvedValueOnce(Left(new Error(\"No gated descriptor\")))\n .mockResolvedValueOnce(Right({ signedDescriptor }));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(\n Right({\n implementationAddress,\n signedDescriptor: proxySignedDescriptor,\n keyId: \"domain-metadata\",\n keyUsage: \"trusted-name\",\n }),\n );\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxySignedDescriptor,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledTimes(2);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenNthCalledWith(1, {\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenNthCalledWith(2, {\n contractAddress: implementationAddress.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAG5BC,EAGO,sFAGPC,EAAsB,gDACtBC,EAAyB,mDAEzBC,EAAqC,2CAErC,SAAS,qCAAsC,IAAM,CACnD,MAAMC,EAA2D,CAC/D,mBAAoB,GAAG,GAAG,EAC1B,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAuC,CAC3C,8BAA+B,GAAG,GAAG,CACvC,EAEMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEMC,EAAS,IAAI,qCACjBJ,EACAC,EACAC,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AE,cAAc,CAC9B,KAAM,uBAAqB,uBAC3B,QAASF,CACX,CAAC,EACD,OACEX,EAA8B,8BAChC,EAAE,sBAAsB,CAAC,EACzB,OACEA,EAA8B,8BAChC,EAAE,wBAAwB,EAAG,CAC3B,gBACEO,EAAW,KAAK,OAAQ,kBAAmB,YAAY,EAEzD,WAAY,OAAO,IAAI,MAAM,EAC7B,QAASA,EAAW,OACtB,CAAC,EACD,OACEP,EAA8B,8BAChC,EAAE,wBAAwB,EAAG,CAC3B,gBAAiBe,EAAsB,YAAY,EAEnD,WAAY,OAAO,IAAI,MAAM,EAC7B,QAASR,EAAW,OACtB,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_device_management_kit", "import_purify_ts", "import_GatedSigningTypedDataContextLoader", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "mockGatedDescriptorDataSource", "mockCertificateLoader", "mockProxyDataSource", "mockLoggerFactory", "loader", "mockCertificate", "SUPPORTED_TYPES", "validInput", "input", "_description", "transactionInput", "signedDescriptor", "error", "result", "certificateError", "implementationAddress", "proxySignedDescriptor"]
|
|
7
7
|
}
|
package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var L=(i,e)=>{for(var n in e)p(i,n,{get:e[n],enumerable:!0})},_=(i,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of I(e))!O.call(i,r)&&r!==n&&p(i,r,{get:()=>e[r],enumerable:!(t=m(e,r))||t.enumerable});return i};var w=i=>_(p({},"__esModule",{value:!0}),i),f=(i,e,n,t)=>{for(var r=t>1?void 0:t?m(e,n):e,o=i.length-1,C;o>=0;o--)(C=i[o])&&(r=(t?C(e,n,r):C(r))||r);return t&&r&&p(e,n,r),r},S=(i,e)=>(n,t)=>e(n,t,i);var V={};L(V,{SolanaTransactionCheckLoader:()=>l});module.exports=w(V);var d=require("@ledgerhq/device-management-kit"),s=require("inversify"),a=require("purify-ts"),T=require("../../../../config/di/configTypes"),A=require("../../../../modules/multichain/pki/di/pkiTypes"),k=require("../../../../modules/multichain/pki/model/KeyUsage"),x=require("../../../../modules/multichain/transaction-check/di/transactionCheckTypes"),E=require("../../../../modules/multichain/transaction-check/utils/constants"),u=require("../../../../shared/model/ClearSignContext"),R=require("../../../../shared/utils/bs58Encoder"),N=require("../../../../shared/utils/uint8ArrayCodec");const b=[u.ClearSignContextType.SOLANA_TRANSACTION_CHECK],v=64,y=64,M=128,P=128,U=127,D=7,B=a.Codec.interface({deviceModelId:(0,a.oneOf)([(0,a.exactly)(d.DeviceModelId.NANO_X),(0,a.exactly)(d.DeviceModelId.NANO_SP),(0,a.exactly)(d.DeviceModelId.STAX),(0,a.exactly)(d.DeviceModelId.FLEX)]),transactionCheck:a.Codec.interface({from:a.string,transactionBytes:N.uint8ArrayCodec,chain:a.number})});let l=class{constructor(e,n,t,r=R.DefaultBs58Encoder){this.transactionCheckDataSource=e;this.certificateLoader=n;this.bs58Encoder=r;this.logger=t("SolanaTransactionCheckLoader")}logger;canHandle(e,n){return b.every(t=>n.includes(t))?B.decode(e).caseOf({Left:()=>!1,Right:({transactionCheck:{from:t,transactionBytes:r}})=>t.length>0&&r.length>0}):!1}async load(e){const{from:n,transactionBytes:t,chain:r}=e.transactionCheck;let o;try{o=this.bs58Encoder.encode(this.wrapMessageAsTransaction(t))}catch(c){const h=[{type:u.ClearSignContextType.ERROR,error:c instanceof Error?c:new Error(String(c))}];return this.logger.debug("load result",{data:{result:h}}),h}const g=[await(await this.transactionCheckDataSource.check({path:E.TransactionCheckPaths.SOLANA_TRANSACTION,body:{tx:{from:n,raw:o},chain:r}})).caseOf({Left:c=>Promise.resolve({type:u.ClearSignContextType.ERROR,error:c}),Right:async c=>{const h=await this.certificateLoader.loadCertificate({keyId:c.publicKeyId,keyUsage:k.KeyUsage.TxSimulationSigner,targetDevice:e.deviceModelId});return{type:u.ClearSignContextType.SOLANA_TRANSACTION_CHECK,payload:{descriptor:c.descriptor},certificate:h}}})];return this.logger.debug("load result",{data:{result:g}}),g}wrapMessageAsTransaction(e){const n=this.readNumRequiredSignatures(e),t=this.encodeShortVec(n),r=n*v,o=new Uint8Array(t.length+r+e.length);return o.set(t,0),o.set(e,t.length+r),o}readNumRequiredSignatures(e){const n=e[0];if(n===void 0)throw new Error("[ContextModule] SolanaTransactionCheckLoader: empty transaction bytes");const r=(n&M)!==0?1:0,o=e[r];if(o===void 0)throw new Error("[ContextModule] SolanaTransactionCheckLoader: malformed message header");if(o>y)throw new Error(`[ContextModule] SolanaTransactionCheckLoader: numRequiredSignatures (${o}) exceeds SOLANA_MAX_SIGNATURES (${y})`);return o}encodeShortVec(e){const n=[];let t=e;for(;;){const r=t&U;if(t>>>=D,t===0){n.push(r);break}n.push(r|P)}return Uint8Array.from(n)}};l=f([(0,s.injectable)(),S(0,(0,s.inject)(x.transactionCheckTypes.TransactionCheckDataSource)),S(1,(0,s.inject)(A.pkiTypes.PkiCertificateLoader)),S(2,(0,s.inject)(T.configTypes.ContextModuleLoggerFactory))],l);0&&(module.exports={SolanaTransactionCheckLoader});
|
|
2
2
|
//# sourceMappingURL=SolanaTransactionCheckLoader.js.map
|