@ledgerhq/device-signer-kit-solana 1.13.3 → 1.13.4
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/api/app-binder/ProvisionTransactionCheckDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/ProvisionTransactionCheckDeviceActionTypes.js.map +1 -1
- package/lib/cjs/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.js.map +2 -2
- package/lib/cjs/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.test.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/device-action/SignTransactionDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTransactionDeviceAction.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/SignTransactionDeviceAction.test.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTransactionDeviceAction.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/services/TransactionInputNormaliser.js +1 -1
- package/lib/cjs/internal/app-binder/services/TransactionInputNormaliser.js.map +3 -3
- package/lib/cjs/internal/app-binder/services/TransactionInputNormaliser.test.js +1 -1
- package/lib/cjs/internal/app-binder/services/TransactionInputNormaliser.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/services/__test-utils__/ambiguousMessages.js +2 -0
- package/lib/cjs/internal/app-binder/services/__test-utils__/ambiguousMessages.js.map +7 -0
- package/lib/cjs/internal/app-binder/services/utils/TransactionParser.js +1 -1
- package/lib/cjs/internal/app-binder/services/utils/TransactionParser.js.map +3 -3
- package/lib/cjs/internal/app-binder/services/utils/TransactionParser.test.js +1 -1
- package/lib/cjs/internal/app-binder/services/utils/TransactionParser.test.js.map +3 -3
- package/lib/cjs/package.json +3 -3
- package/lib/esm/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.js.map +2 -2
- package/lib/esm/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.test.js +1 -1
- package/lib/esm/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.test.js.map +2 -2
- package/lib/esm/internal/app-binder/device-action/SignTransactionDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTransactionDeviceAction.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/SignTransactionDeviceAction.test.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTransactionDeviceAction.test.js.map +3 -3
- package/lib/esm/internal/app-binder/services/TransactionInputNormaliser.js +1 -1
- package/lib/esm/internal/app-binder/services/TransactionInputNormaliser.js.map +3 -3
- package/lib/esm/internal/app-binder/services/TransactionInputNormaliser.test.js +1 -1
- package/lib/esm/internal/app-binder/services/TransactionInputNormaliser.test.js.map +3 -3
- package/lib/esm/internal/app-binder/services/__test-utils__/ambiguousMessages.js +2 -0
- package/lib/esm/internal/app-binder/services/__test-utils__/ambiguousMessages.js.map +7 -0
- package/lib/esm/internal/app-binder/services/utils/TransactionParser.js +1 -1
- package/lib/esm/internal/app-binder/services/utils/TransactionParser.js.map +3 -3
- package/lib/esm/internal/app-binder/services/utils/TransactionParser.test.js +1 -1
- package/lib/esm/internal/app-binder/services/utils/TransactionParser.test.js.map +3 -3
- package/lib/esm/package.json +3 -3
- package/lib/types/api/app-binder/ProvisionTransactionCheckDeviceActionTypes.d.ts +5 -1
- package/lib/types/api/app-binder/ProvisionTransactionCheckDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/SignTransactionDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/services/TransactionInputNormaliser.d.ts +23 -8
- package/lib/types/internal/app-binder/services/TransactionInputNormaliser.d.ts.map +1 -1
- package/lib/types/internal/app-binder/services/__test-utils__/ambiguousMessages.d.ts +7 -0
- package/lib/types/internal/app-binder/services/__test-utils__/ambiguousMessages.d.ts.map +1 -0
- package/lib/types/internal/app-binder/services/utils/TransactionParser.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var r=Object.defineProperty;var
|
|
1
|
+
"use strict";var r=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var c=(n,e,a,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of p(e))!l.call(n,t)&&t!==a&&r(n,t,{get:()=>e[t],enumerable:!(o=i(e,t))||o.enumerable});return n};var s=n=>c(r({},"__esModule",{value:!0}),n);var d={};module.exports=s(d);
|
|
2
2
|
//# sourceMappingURL=ProvisionTransactionCheckDeviceActionTypes.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/app-binder/ProvisionTransactionCheckDeviceActionTypes.ts"],
|
|
4
|
-
"sourcesContent": ["import { type ContextModule } from \"@ledgerhq/context-module\";\n\nimport {\n type SignTransactionDAIntermediateValue,\n type SignTransactionDASimpleIntermediateValue,\n} from \"@api/app-binder/SignTransactionDeviceActionTypes\";\nimport { type AppConfiguration } from \"@api/model/AppConfiguration\";\n\nexport type ProvisionTransactionCheckDAInput = {\n readonly derivationPath: string;\n readonly transaction: Uint8Array;\n readonly contextModule: ContextModule;\n // Supplied at invoke time (depends on parent's runtime state)\n readonly appConfig?: AppConfiguration;\n readonly serializedForTxCheck?: Uint8Array;\n};\n\n/**\n * Best-effort: the machine provisions the tx-check descriptor but never\n * signs; any failure is swallowed, so the output is always `Right`.\n */\nexport type ProvisionTransactionCheckDAOutput =
|
|
4
|
+
"sourcesContent": ["import { type ContextModule } from \"@ledgerhq/context-module\";\n\nimport {\n type SignTransactionDAIntermediateValue,\n type SignTransactionDASimpleIntermediateValue,\n} from \"@api/app-binder/SignTransactionDeviceActionTypes\";\nimport { type AppConfiguration } from \"@api/model/AppConfiguration\";\n\nexport type ProvisionTransactionCheckDAInput = {\n readonly derivationPath: string;\n readonly transaction: Uint8Array;\n readonly contextModule: ContextModule;\n // Supplied at invoke time (depends on parent's runtime state)\n readonly appConfig?: AppConfiguration;\n readonly serializedForTxCheck?: Uint8Array;\n};\n\n/**\n * Best-effort: the machine provisions the tx-check descriptor but never\n * signs; any failure is swallowed, so the output is always `Right`.\n * `transactionChecksEnabled` is the state after the opt-in prompt (if any),\n * so the parent can re-provision later without prompting again.\n */\nexport type ProvisionTransactionCheckDAOutput = {\n readonly transactionChecksEnabled: boolean;\n};\n\nexport type ProvisionTransactionCheckDAError = never;\n\n/**\n * Emits the full union so the opt-in-result step's `result` field is\n * preserved when the parent forwards child snapshots.\n */\nexport type ProvisionTransactionCheckDAIntermediateValue =\n SignTransactionDAIntermediateValue;\n\nexport type ProvisionTransactionCheckDAInternalState = {\n // Starts from input.appConfig; updated with transactionChecksEnabled after opt-in.\n readonly appConfig: AppConfiguration | null;\n};\n\nexport type ProvisionTransactionCheckDASimpleIntermediateValue =\n SignTransactionDASimpleIntermediateValue;\n"],
|
|
5
5
|
"mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
|
|
6
6
|
"names": ["ProvisionTransactionCheckDeviceActionTypes_exports", "__toCommonJS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var v=(o,e)=>{for(var i in e)p(o,i,{get:e[i],enumerable:!0})},I=(o,e,i,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of k(e))!T.call(o,n)&&n!==i&&p(o,n,{get:()=>e[n],enumerable:!(c=l(e,n))||c.enumerable});return o};var m=o=>I(p({},"__esModule",{value:!0}),o);var A={};v(A,{ProvisionTransactionCheckDeviceAction:()=>P});module.exports=m(A);var a=require("@ledgerhq/device-management-kit"),
|
|
1
|
+
"use strict";var p=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var v=(o,e)=>{for(var i in e)p(o,i,{get:e[i],enumerable:!0})},I=(o,e,i,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of k(e))!T.call(o,n)&&n!==i&&p(o,n,{get:()=>e[n],enumerable:!(c=l(e,n))||c.enumerable});return o};var m=o=>I(p({},"__esModule",{value:!0}),o);var A={};v(A,{ProvisionTransactionCheckDeviceAction:()=>P});module.exports=m(A);var a=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),r=require("xstate"),s=require("../../../api/app-binder/SignTransactionDeviceActionTypes"),h=require("../../app-binder/command/TransactionCheckOptInCommand"),u=require("../../app-binder/task/ProvideTransactionCheckTask");class P extends a.XStateDeviceAction{makeStateMachine(e){const{transactionCheckOptIn:i,provideTransactionCheck:c}=this.extractDependencies(e),n=this.getLoggerFactory(e)("ProvisionTransactionCheckDeviceAction");return(0,r.setup)({types:{input:{},context:{},output:{}},actors:{transactionCheckOptIn:(0,r.fromPromise)(i),provideTransactionCheck:(0,r.fromPromise)(c)},guards:{shouldOptIn:({context:t})=>!!t._internalState.appConfig&&!t._internalState.appConfig.transactionChecksEnabled&&!t._internalState.appConfig.transactionChecksOptIn,transactionChecksEnabled:({context:t})=>t._internalState.appConfig?.transactionChecksEnabled===!0}}).createMachine({id:"ProvisionTransactionCheckDeviceAction",initial:"OptInGate",context:({input:t})=>({input:t,intermediateValue:{requiredUserInteraction:a.UserInteractionRequired.None,step:s.signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN},_internalState:{appConfig:t.appConfig??null}}),states:{OptInGate:{always:[{target:"OptIn",guard:"shouldOptIn"},{target:"ProvideGate"}]},OptIn:{entry:(0,r.assign)({intermediateValue:()=>({requiredUserInteraction:a.UserInteractionRequired.Web3ChecksOptIn,step:s.signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN})}),invoke:{id:"transactionCheckOptIn",src:"transactionCheckOptIn",onDone:{target:"OptInResult",actions:[({event:t})=>{(0,a.isSuccessCommandResult)(t.output)||n.warn("[TransactionCheck] opt-in command returned error, proceeding without transaction-checks",{data:{error:t.output}})},(0,r.assign)({_internalState:({event:t,context:C})=>(0,a.isSuccessCommandResult)(t.output)?{appConfig:{...C._internalState.appConfig,transactionChecksEnabled:t.output.data.enabled}}:C._internalState})]},onError:{target:"OptInResult",actions:({event:t})=>n.info("[TransactionCheck] opt-in threw; proceeding without transaction-checks",{data:{error:String(t.error)}})}}},OptInResult:{entry:(0,r.assign)(({context:t})=>({intermediateValue:{requiredUserInteraction:a.UserInteractionRequired.None,step:s.signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN_RESULT,result:t._internalState.appConfig?.transactionChecksEnabled??!1}})),after:{0:{target:"ProvideGate"}}},ProvideGate:{always:[{target:"Provide",guard:"transactionChecksEnabled"},{target:"Done"}]},Provide:{entry:(0,r.assign)({intermediateValue:()=>({requiredUserInteraction:a.UserInteractionRequired.None,step:s.signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE})}),invoke:{id:"provideTransactionCheck",src:"provideTransactionCheck",input:({context:t})=>({derivationPath:t.input.derivationPath,transaction:t.input.transaction,contextModule:t.input.contextModule,serializedForTxCheck:t.input.serializedForTxCheck}),onDone:{target:"Done"},onError:{target:"Done",actions:({event:t})=>n.info("[TransactionCheck] provide threw; proceeding",{data:{error:String(t.error)}})}}},Done:{type:"final"}},output:({context:t})=>(0,d.Right)({transactionChecksEnabled:t._internalState.appConfig?.transactionChecksEnabled===!0})})}extractDependencies(e){return{transactionCheckOptIn:async()=>e.sendCommand(new h.TransactionCheckOptInCommand),provideTransactionCheck:async n=>new u.ProvideTransactionCheckTask(e,{derivationPath:n.input.derivationPath,transactionBytes:n.input.transaction,contextModule:n.input.contextModule,serializedTransactionForTransactionCheck:n.input.serializedForTxCheck,loggerFactory:this.getLoggerFactory(e)}).run()}}}0&&(module.exports={ProvisionTransactionCheckDeviceAction});
|
|
2
2
|
//# sourceMappingURL=ProvisionTransactionCheckDeviceAction.js.map
|
package/lib/cjs/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { type ContextModule } from \"@ledgerhq/context-module\";\nimport {\n type CommandResult,\n type DeviceActionStateMachine,\n type InternalApi,\n isSuccessCommandResult,\n type StateMachineTypes,\n UserInteractionRequired,\n XStateDeviceAction,\n} from \"@ledgerhq/device-management-kit\";\nimport { Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport {\n type ProvisionTransactionCheckDAError,\n type ProvisionTransactionCheckDAInput,\n type ProvisionTransactionCheckDAIntermediateValue,\n type ProvisionTransactionCheckDAInternalState,\n type ProvisionTransactionCheckDAOutput,\n} from \"@api/app-binder/ProvisionTransactionCheckDeviceActionTypes\";\nimport { signTransactionDAStateSteps } from \"@api/app-binder/SignTransactionDeviceActionTypes\";\nimport {\n TransactionCheckOptInCommand,\n type TransactionCheckOptInCommandResponse,\n} from \"@internal/app-binder/command/TransactionCheckOptInCommand\";\nimport { type SolanaAppErrorCodes } from \"@internal/app-binder/command/utils/SolanaApplicationErrors\";\nimport { ProvideTransactionCheckTask } from \"@internal/app-binder/task/ProvideTransactionCheckTask\";\n\nexport type MachineDependencies = {\n readonly transactionCheckOptIn: () => Promise<\n CommandResult<TransactionCheckOptInCommandResponse, SolanaAppErrorCodes>\n >;\n readonly provideTransactionCheck: (arg0: {\n input: {\n derivationPath: string;\n transaction: Uint8Array;\n contextModule: ContextModule;\n serializedForTxCheck?: Uint8Array;\n };\n }) => Promise<void>;\n};\n\nexport class ProvisionTransactionCheckDeviceAction extends XStateDeviceAction<\n ProvisionTransactionCheckDAOutput,\n ProvisionTransactionCheckDAInput,\n ProvisionTransactionCheckDAError,\n ProvisionTransactionCheckDAIntermediateValue,\n ProvisionTransactionCheckDAInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n ProvisionTransactionCheckDAOutput,\n ProvisionTransactionCheckDAInput,\n ProvisionTransactionCheckDAError,\n ProvisionTransactionCheckDAIntermediateValue,\n ProvisionTransactionCheckDAInternalState\n > {\n type types = StateMachineTypes<\n ProvisionTransactionCheckDAOutput,\n ProvisionTransactionCheckDAInput,\n ProvisionTransactionCheckDAError,\n ProvisionTransactionCheckDAIntermediateValue,\n ProvisionTransactionCheckDAInternalState\n >;\n\n const { transactionCheckOptIn, provideTransactionCheck } =\n this.extractDependencies(internalApi);\n\n const logger = this.getLoggerFactory(internalApi)(\n \"ProvisionTransactionCheckDeviceAction\",\n );\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n transactionCheckOptIn: fromPromise(transactionCheckOptIn),\n provideTransactionCheck: fromPromise(provideTransactionCheck),\n },\n guards: {\n shouldOptIn: ({ context }) =>\n !!context._internalState.appConfig &&\n !context._internalState.appConfig.transactionChecksEnabled &&\n !context._internalState.appConfig.transactionChecksOptIn,\n transactionChecksEnabled: ({ context }) =>\n context._internalState.appConfig?.transactionChecksEnabled === true,\n },\n }).createMachine({\n id: \"ProvisionTransactionCheckDeviceAction\",\n initial: \"OptInGate\",\n context: ({ input }) => ({\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN,\n },\n _internalState: {\n appConfig: input.appConfig ?? null,\n },\n }),\n states: {\n OptInGate: {\n always: [\n { target: \"OptIn\", guard: \"shouldOptIn\" },\n { target: \"ProvideGate\" },\n ],\n },\n OptIn: {\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.Web3ChecksOptIn,\n step: signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN,\n }),\n }),\n invoke: {\n id: \"transactionCheckOptIn\",\n src: \"transactionCheckOptIn\",\n onDone: {\n target: \"OptInResult\",\n actions: [\n ({ event }) => {\n if (!isSuccessCommandResult(event.output)) {\n logger.warn(\n \"[TransactionCheck] opt-in command returned error, proceeding without transaction-checks\",\n { data: { error: event.output } },\n );\n }\n },\n assign({\n _internalState: ({ event, context }) => {\n if (isSuccessCommandResult(event.output)) {\n return {\n appConfig: {\n ...context._internalState.appConfig!,\n transactionChecksEnabled: event.output.data.enabled,\n },\n };\n }\n return context._internalState;\n },\n }),\n ],\n },\n onError: {\n target: \"OptInResult\",\n actions: ({ event }) =>\n logger.info(\n \"[TransactionCheck] opt-in threw; proceeding without transaction-checks\",\n { data: { error: String(event.error) } },\n ),\n },\n },\n },\n OptInResult: {\n entry: assign(({ context }) => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN_RESULT,\n result:\n context._internalState.appConfig?.transactionChecksEnabled ??\n false,\n },\n })),\n // Zero-delay transition so the entry assign above is visible to\n // onSnapshot observers before the machine moves on.\n after: {\n 0: { target: \"ProvideGate\" },\n },\n },\n ProvideGate: {\n always: [\n { target: \"Provide\", guard: \"transactionChecksEnabled\" },\n { target: \"Done\" },\n ],\n },\n Provide: {\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE,\n }),\n }),\n invoke: {\n id: \"provideTransactionCheck\",\n src: \"provideTransactionCheck\",\n input: ({ context }) => ({\n derivationPath: context.input.derivationPath,\n transaction: context.input.transaction,\n contextModule: context.input.contextModule,\n serializedForTxCheck: context.input.serializedForTxCheck,\n }),\n onDone: { target: \"Done\" },\n onError: {\n target: \"Done\",\n actions: ({ event }) =>\n logger.info(\"[TransactionCheck] provide threw; proceeding\", {\n data: { error: String(event.error) },\n }),\n },\n },\n },\n Done: { type: \"final\" },\n },\n output: ()
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2CAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAQO,2CACPC,EAAsB,qBACtBC,EAA2C,kBAS3CC,EAA4C,4DAC5CC,EAGO,qEAEPC,EAA4C,iEAgBrC,MAAMP,UAA8C,oBAMzD,CACA,iBACEQ,EAOA,CASA,KAAM,CAAE,sBAAAC,EAAuB,wBAAAC,CAAwB,EACrD,KAAK,oBAAoBF,CAAW,EAEhCG,EAAS,KAAK,iBAAiBH,CAAW,EAC9C,uCACF,EAEA,SAAO,SAAM,CACX,MAAO,CACL,MAAO,CAAC,EACR,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,yBAAuB,eAAYC,CAAqB,EACxD,2BAAyB,eAAYC,CAAuB,CAC9D,EACA,OAAQ,CACN,YAAa,CAAC,CAAE,QAAAE,CAAQ,IACtB,CAAC,CAACA,EAAQ,eAAe,WACzB,CAACA,EAAQ,eAAe,UAAU,0BAClC,CAACA,EAAQ,eAAe,UAAU,uBACpC,yBAA0B,CAAC,CAAE,QAAAA,CAAQ,IACnCA,EAAQ,eAAe,WAAW,2BAA6B,EACnE,CACF,CAAC,EAAE,cAAc,CACf,GAAI,wCACJ,QAAS,YACT,QAAS,CAAC,CAAE,MAAAC,CAAM,KAAO,CACvB,MAAAA,EACA,kBAAmB,CACjB,wBAAyB,0BAAwB,KACjD,KAAM,8BAA4B,yBACpC,EACA,eAAgB,CACd,UAAWA,EAAM,WAAa,IAChC,CACF,GACA,OAAQ,CACN,UAAW,CACT,OAAQ,CACN,CAAE,OAAQ,QAAS,MAAO,aAAc,EACxC,CA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AAAA,CAAQ,KAAO,CACvB,eAAgBA,EAAQ,MAAM,eAC9B,YAAaA,EAAQ,MAAM,YAC3B,cAAeA,EAAQ,MAAM,cAC7B,qBAAsBA,EAAQ,MAAM,oBACtC,GACA,OAAQ,CAAE,OAAQ,MAAO,EACzB,QAAS,CACP,OAAQ,OACR,QAAS,CAAC,CAAE,MAAAE,CAAM,IAChBH,EAAO,KAAK,+CAAgD,CAC1D,KAAM,CAAE,MAAO,OAAOG,EAAM,KAAK,CAAE,CACrC,CAAC,CACL,CACF,CACF,EACA,KAAM,CAAE,KAAM,OAAQ,CACxB,EACA,OAAQ,
|
|
4
|
+
"sourcesContent": ["import { type ContextModule } from \"@ledgerhq/context-module\";\nimport {\n type CommandResult,\n type DeviceActionStateMachine,\n type InternalApi,\n isSuccessCommandResult,\n type StateMachineTypes,\n UserInteractionRequired,\n XStateDeviceAction,\n} from \"@ledgerhq/device-management-kit\";\nimport { Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport {\n type ProvisionTransactionCheckDAError,\n type ProvisionTransactionCheckDAInput,\n type ProvisionTransactionCheckDAIntermediateValue,\n type ProvisionTransactionCheckDAInternalState,\n type ProvisionTransactionCheckDAOutput,\n} from \"@api/app-binder/ProvisionTransactionCheckDeviceActionTypes\";\nimport { signTransactionDAStateSteps } from \"@api/app-binder/SignTransactionDeviceActionTypes\";\nimport {\n TransactionCheckOptInCommand,\n type TransactionCheckOptInCommandResponse,\n} from \"@internal/app-binder/command/TransactionCheckOptInCommand\";\nimport { type SolanaAppErrorCodes } from \"@internal/app-binder/command/utils/SolanaApplicationErrors\";\nimport { ProvideTransactionCheckTask } from \"@internal/app-binder/task/ProvideTransactionCheckTask\";\n\nexport type MachineDependencies = {\n readonly transactionCheckOptIn: () => Promise<\n CommandResult<TransactionCheckOptInCommandResponse, SolanaAppErrorCodes>\n >;\n readonly provideTransactionCheck: (arg0: {\n input: {\n derivationPath: string;\n transaction: Uint8Array;\n contextModule: ContextModule;\n serializedForTxCheck?: Uint8Array;\n };\n }) => Promise<void>;\n};\n\nexport class ProvisionTransactionCheckDeviceAction extends XStateDeviceAction<\n ProvisionTransactionCheckDAOutput,\n ProvisionTransactionCheckDAInput,\n ProvisionTransactionCheckDAError,\n ProvisionTransactionCheckDAIntermediateValue,\n ProvisionTransactionCheckDAInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n ProvisionTransactionCheckDAOutput,\n ProvisionTransactionCheckDAInput,\n ProvisionTransactionCheckDAError,\n ProvisionTransactionCheckDAIntermediateValue,\n ProvisionTransactionCheckDAInternalState\n > {\n type types = StateMachineTypes<\n ProvisionTransactionCheckDAOutput,\n ProvisionTransactionCheckDAInput,\n ProvisionTransactionCheckDAError,\n ProvisionTransactionCheckDAIntermediateValue,\n ProvisionTransactionCheckDAInternalState\n >;\n\n const { transactionCheckOptIn, provideTransactionCheck } =\n this.extractDependencies(internalApi);\n\n const logger = this.getLoggerFactory(internalApi)(\n \"ProvisionTransactionCheckDeviceAction\",\n );\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n transactionCheckOptIn: fromPromise(transactionCheckOptIn),\n provideTransactionCheck: fromPromise(provideTransactionCheck),\n },\n guards: {\n shouldOptIn: ({ context }) =>\n !!context._internalState.appConfig &&\n !context._internalState.appConfig.transactionChecksEnabled &&\n !context._internalState.appConfig.transactionChecksOptIn,\n transactionChecksEnabled: ({ context }) =>\n context._internalState.appConfig?.transactionChecksEnabled === true,\n },\n }).createMachine({\n id: \"ProvisionTransactionCheckDeviceAction\",\n initial: \"OptInGate\",\n context: ({ input }) => ({\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN,\n },\n _internalState: {\n appConfig: input.appConfig ?? null,\n },\n }),\n states: {\n OptInGate: {\n always: [\n { target: \"OptIn\", guard: \"shouldOptIn\" },\n { target: \"ProvideGate\" },\n ],\n },\n OptIn: {\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.Web3ChecksOptIn,\n step: signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN,\n }),\n }),\n invoke: {\n id: \"transactionCheckOptIn\",\n src: \"transactionCheckOptIn\",\n onDone: {\n target: \"OptInResult\",\n actions: [\n ({ event }) => {\n if (!isSuccessCommandResult(event.output)) {\n logger.warn(\n \"[TransactionCheck] opt-in command returned error, proceeding without transaction-checks\",\n { data: { error: event.output } },\n );\n }\n },\n assign({\n _internalState: ({ event, context }) => {\n if (isSuccessCommandResult(event.output)) {\n return {\n appConfig: {\n ...context._internalState.appConfig!,\n transactionChecksEnabled: event.output.data.enabled,\n },\n };\n }\n return context._internalState;\n },\n }),\n ],\n },\n onError: {\n target: \"OptInResult\",\n actions: ({ event }) =>\n logger.info(\n \"[TransactionCheck] opt-in threw; proceeding without transaction-checks\",\n { data: { error: String(event.error) } },\n ),\n },\n },\n },\n OptInResult: {\n entry: assign(({ context }) => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN_RESULT,\n result:\n context._internalState.appConfig?.transactionChecksEnabled ??\n false,\n },\n })),\n // Zero-delay transition so the entry assign above is visible to\n // onSnapshot observers before the machine moves on.\n after: {\n 0: { target: \"ProvideGate\" },\n },\n },\n ProvideGate: {\n always: [\n { target: \"Provide\", guard: \"transactionChecksEnabled\" },\n { target: \"Done\" },\n ],\n },\n Provide: {\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE,\n }),\n }),\n invoke: {\n id: \"provideTransactionCheck\",\n src: \"provideTransactionCheck\",\n input: ({ context }) => ({\n derivationPath: context.input.derivationPath,\n transaction: context.input.transaction,\n contextModule: context.input.contextModule,\n serializedForTxCheck: context.input.serializedForTxCheck,\n }),\n onDone: { target: \"Done\" },\n onError: {\n target: \"Done\",\n actions: ({ event }) =>\n logger.info(\"[TransactionCheck] provide threw; proceeding\", {\n data: { error: String(event.error) },\n }),\n },\n },\n },\n Done: { type: \"final\" },\n },\n output: ({ context }) =>\n Right({\n transactionChecksEnabled:\n context._internalState.appConfig?.transactionChecksEnabled === true,\n }),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const transactionCheckOptIn = async () =>\n internalApi.sendCommand(new TransactionCheckOptInCommand());\n\n const provideTransactionCheck = async (arg0: {\n input: {\n derivationPath: string;\n transaction: Uint8Array;\n contextModule: ContextModule;\n serializedForTxCheck?: Uint8Array;\n };\n }) =>\n new ProvideTransactionCheckTask(internalApi, {\n derivationPath: arg0.input.derivationPath,\n transactionBytes: arg0.input.transaction,\n contextModule: arg0.input.contextModule,\n serializedTransactionForTransactionCheck:\n arg0.input.serializedForTxCheck,\n loggerFactory: this.getLoggerFactory(internalApi),\n }).run();\n\n return { transactionCheckOptIn, provideTransactionCheck };\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2CAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAQO,2CACPC,EAAsB,qBACtBC,EAA2C,kBAS3CC,EAA4C,4DAC5CC,EAGO,qEAEPC,EAA4C,iEAgBrC,MAAMP,UAA8C,oBAMzD,CACA,iBACEQ,EAOA,CASA,KAAM,CAAE,sBAAAC,EAAuB,wBAAAC,CAAwB,EACrD,KAAK,oBAAoBF,CAAW,EAEhCG,EAAS,KAAK,iBAAiBH,CAAW,EAC9C,uCACF,EAEA,SAAO,SAAM,CACX,MAAO,CACL,MAAO,CAAC,EACR,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,yBAAuB,eAAYC,CAAqB,EACxD,2BAAyB,eAAYC,CAAuB,CAC9D,EACA,OAAQ,CACN,YAAa,CAAC,CAAE,QAAA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,KAAK,iBAAiBP,CAAW,CAClD,CAAC,EAAE,IAAI,CAE+C,CAC1D,CACF",
|
|
6
6
|
"names": ["ProvisionTransactionCheckDeviceAction_exports", "__export", "ProvisionTransactionCheckDeviceAction", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_xstate", "import_SignTransactionDeviceActionTypes", "import_TransactionCheckOptInCommand", "import_ProvideTransactionCheckTask", "internalApi", "transactionCheckOptIn", "provideTransactionCheck", "logger", "context", "input", "event", "arg0"]
|
|
7
7
|
}
|
package/lib/cjs/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.test.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var a=require("@ledgerhq/device-management-kit"),e=require("vitest"),l=require("../../../api/app-binder/SignTransactionDeviceActionTypes"),C=require("../../../api/model/PublicKeyDisplayMode"),v=require("./__test-utils__/makeInternalApi"),
|
|
1
|
+
"use strict";var a=require("@ledgerhq/device-management-kit"),e=require("vitest"),l=require("../../../api/app-binder/SignTransactionDeviceActionTypes"),C=require("../../../api/model/PublicKeyDisplayMode"),v=require("./__test-utils__/makeInternalApi"),h=require("./ProvisionTransactionCheckDeviceAction");const A="44'/501'/0'/0'",T=new Uint8Array([222,173,190,239]),D={getContexts:e.vi.fn()};function d(i={}){return{blindSigningEnabled:!0,pubKeyDisplayMode:C.PublicKeyDisplayMode.LONG,version:"1.16.0",transactionChecksEnabled:!1,transactionChecksOptIn:!1,...i}}let m,r,s;function P(){return{transactionCheckOptIn:r,provideTransactionCheck:s}}function c(i,t,n){const o=new h.ProvisionTransactionCheckDeviceAction({input:i});e.vi.spyOn(o,"extractDependencies").mockReturnValue(P());const{observable:f}=o._execute(m),u=[];f.subscribe({next:k=>u.push(k),error:n,complete:()=>t(u)})}function y(i){const t=[];for(const n of i){if(n.status!==a.DeviceActionStatus.Pending)continue;const o=n.intermediateValue.step;o&&t[t.length-1]!==o&&t.push(o)}return t}const p={derivationPath:A,transaction:T,contextModule:D,appConfig:d()};(0,e.describe)("ProvisionTransactionCheckDeviceAction",()=>{(0,e.beforeEach)(()=>{m=(0,v.makeDeviceActionInternalApiMock)(),r=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:{enabled:!0}})),s=e.vi.fn().mockResolvedValue(void 0)}),(0,e.it)("not opted-in: runs opt-in, then provide when enabled, then completes",()=>new Promise((i,t)=>{c(p,n=>{try{(0,e.expect)(r).toHaveBeenCalled(),(0,e.expect)(s).toHaveBeenCalled();const o=y(n);(0,e.expect)(o).toContain(l.signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN),(0,e.expect)(o).toContain(l.signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE),(0,e.expect)(o.indexOf(l.signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN)).toBeLessThan(o.indexOf(l.signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE)),(0,e.expect)(n[n.length-1]).toEqual({status:a.DeviceActionStatus.Completed,output:{transactionChecksEnabled:!0}}),i()}catch(o){t(o)}},t)})),(0,e.it)("not opted-in + opt-in returns disabled: skips provide",()=>new Promise((i,t)=>{r.mockResolvedValue((0,a.CommandResultFactory)({data:{enabled:!1}})),c(p,n=>{try{(0,e.expect)(r).toHaveBeenCalled(),(0,e.expect)(s).not.toHaveBeenCalled(),(0,e.expect)(n[n.length-1]).toEqual({status:a.DeviceActionStatus.Completed,output:{transactionChecksEnabled:!1}}),i()}catch(o){t(o)}},t)})),(0,e.it)("already enabled: skips opt-in, runs provide directly",()=>new Promise((i,t)=>{c({...p,appConfig:d({transactionChecksEnabled:!0,transactionChecksOptIn:!0})},n=>{try{(0,e.expect)(r).not.toHaveBeenCalled(),(0,e.expect)(s).toHaveBeenCalled(),(0,e.expect)(n[n.length-1].status).toBe(a.DeviceActionStatus.Completed),i()}catch(o){t(o)}},t)})),(0,e.it)("already opted-in but not enabled: skips both opt-in and provide",()=>new Promise((i,t)=>{c({...p,appConfig:d({transactionChecksEnabled:!1,transactionChecksOptIn:!0})},n=>{try{(0,e.expect)(r).not.toHaveBeenCalled(),(0,e.expect)(s).not.toHaveBeenCalled(),(0,e.expect)(n[n.length-1].status).toBe(a.DeviceActionStatus.Completed),i()}catch(o){t(o)}},t)})),(0,e.it)("opt-in throws: still completes without provide (best-effort)",()=>new Promise((i,t)=>{r.mockRejectedValue(new Error("transport error")),c(p,n=>{try{(0,e.expect)(r).toHaveBeenCalled(),(0,e.expect)(s).not.toHaveBeenCalled(),(0,e.expect)(n[n.length-1].status).toBe(a.DeviceActionStatus.Completed),i()}catch(o){t(o)}},t)})),(0,e.it)("provide throws: still completes (best-effort)",()=>new Promise((i,t)=>{s.mockRejectedValue(new Error("provide error")),c({...p,appConfig:d({transactionChecksEnabled:!0,transactionChecksOptIn:!0})},n=>{try{(0,e.expect)(s).toHaveBeenCalled(),(0,e.expect)(n[n.length-1].status).toBe(a.DeviceActionStatus.Completed),i()}catch(o){t(o)}},t)}))});
|
|
2
2
|
//# sourceMappingURL=ProvisionTransactionCheckDeviceAction.test.js.map
|
package/lib/cjs/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.test.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/device-action/ProvisionTransactionCheckDeviceAction.test.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n CommandResultFactory,\n type DeviceActionState,\n DeviceActionStatus,\n} from \"@ledgerhq/device-management-kit\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport {\n type ProvisionTransactionCheckDAError,\n type ProvisionTransactionCheckDAInput,\n type ProvisionTransactionCheckDAIntermediateValue,\n} from \"@api/app-binder/ProvisionTransactionCheckDeviceActionTypes\";\nimport { signTransactionDAStateSteps } from \"@api/app-binder/SignTransactionDeviceActionTypes\";\nimport { type AppConfiguration } from \"@api/model/AppConfiguration\";\nimport { PublicKeyDisplayMode } from \"@api/model/PublicKeyDisplayMode\";\n\nimport { makeDeviceActionInternalApiMock } from \"./__test-utils__/makeInternalApi\";\nimport { ProvisionTransactionCheckDeviceAction } from \"./ProvisionTransactionCheckDeviceAction\";\n\nconst defaultDerivation = \"44'/501'/0'/0'\";\nconst exampleTx = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);\n\nconst contextModuleStub = { getContexts: vi.fn() } as any; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nfunction makeAppConfig(\n overrides: Partial<AppConfiguration> = {},\n): AppConfiguration {\n return {\n blindSigningEnabled: true,\n pubKeyDisplayMode: PublicKeyDisplayMode.LONG,\n version: \"1.16.0\",\n transactionChecksEnabled: false,\n transactionChecksOptIn: false,\n ...overrides,\n };\n}\n\nlet apiMock: ReturnType<typeof makeDeviceActionInternalApiMock>;\nlet optInMock: ReturnType<typeof vi.fn>;\nlet provideMock: ReturnType<typeof vi.fn>;\n\nfunction extractDeps() {\n return {\n transactionCheckOptIn: optInMock,\n provideTransactionCheck: provideMock,\n };\n}\n\nfunction run(\n input: ProvisionTransactionCheckDAInput,\n onComplete: (\n states: DeviceActionState<\n
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAIO,2CACPC,EAAqD,
|
|
4
|
+
"sourcesContent": ["import {\n CommandResultFactory,\n type DeviceActionState,\n DeviceActionStatus,\n} from \"@ledgerhq/device-management-kit\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport {\n type ProvisionTransactionCheckDAError,\n type ProvisionTransactionCheckDAInput,\n type ProvisionTransactionCheckDAIntermediateValue,\n type ProvisionTransactionCheckDAOutput,\n} from \"@api/app-binder/ProvisionTransactionCheckDeviceActionTypes\";\nimport { signTransactionDAStateSteps } from \"@api/app-binder/SignTransactionDeviceActionTypes\";\nimport { type AppConfiguration } from \"@api/model/AppConfiguration\";\nimport { PublicKeyDisplayMode } from \"@api/model/PublicKeyDisplayMode\";\n\nimport { makeDeviceActionInternalApiMock } from \"./__test-utils__/makeInternalApi\";\nimport { ProvisionTransactionCheckDeviceAction } from \"./ProvisionTransactionCheckDeviceAction\";\n\nconst defaultDerivation = \"44'/501'/0'/0'\";\nconst exampleTx = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);\n\nconst contextModuleStub = { getContexts: vi.fn() } as any; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nfunction makeAppConfig(\n overrides: Partial<AppConfiguration> = {},\n): AppConfiguration {\n return {\n blindSigningEnabled: true,\n pubKeyDisplayMode: PublicKeyDisplayMode.LONG,\n version: \"1.16.0\",\n transactionChecksEnabled: false,\n transactionChecksOptIn: false,\n ...overrides,\n };\n}\n\nlet apiMock: ReturnType<typeof makeDeviceActionInternalApiMock>;\nlet optInMock: ReturnType<typeof vi.fn>;\nlet provideMock: ReturnType<typeof vi.fn>;\n\nfunction extractDeps() {\n return {\n transactionCheckOptIn: optInMock,\n provideTransactionCheck: provideMock,\n };\n}\n\nfunction run(\n input: ProvisionTransactionCheckDAInput,\n onComplete: (\n states: DeviceActionState<\n ProvisionTransactionCheckDAOutput,\n ProvisionTransactionCheckDAError,\n ProvisionTransactionCheckDAIntermediateValue\n >[],\n ) => void,\n onError: (e: unknown) => void,\n) {\n const action = new ProvisionTransactionCheckDeviceAction({ input });\n vi.spyOn(action, \"extractDependencies\").mockReturnValue(extractDeps() as any); // eslint-disable-line @typescript-eslint/no-explicit-any\n const { observable } = action._execute(apiMock);\n const states: DeviceActionState<\n ProvisionTransactionCheckDAOutput,\n ProvisionTransactionCheckDAError,\n ProvisionTransactionCheckDAIntermediateValue\n >[] = [];\n observable.subscribe({\n next: (s) => states.push(s),\n error: onError,\n complete: () => onComplete(states),\n });\n}\n\nfunction stepSequence(\n states: DeviceActionState<\n ProvisionTransactionCheckDAOutput,\n ProvisionTransactionCheckDAError,\n ProvisionTransactionCheckDAIntermediateValue\n >[],\n): string[] {\n const steps: string[] = [];\n for (const s of states) {\n if (s.status !== DeviceActionStatus.Pending) continue;\n const step = (s.intermediateValue as { step?: string }).step;\n if (step && steps[steps.length - 1] !== step) steps.push(step);\n }\n return steps;\n}\n\nconst baseInput: ProvisionTransactionCheckDAInput = {\n derivationPath: defaultDerivation,\n transaction: exampleTx,\n contextModule: contextModuleStub,\n appConfig: makeAppConfig(),\n};\n\ndescribe(\"ProvisionTransactionCheckDeviceAction\", () => {\n beforeEach(() => {\n apiMock = makeDeviceActionInternalApiMock();\n optInMock = vi\n .fn()\n .mockResolvedValue(CommandResultFactory({ data: { enabled: true } }));\n provideMock = vi.fn().mockResolvedValue(undefined);\n });\n\n it(\"not opted-in: runs opt-in, then provide when enabled, then completes\", () =>\n new Promise<void>((resolve, reject) => {\n run(\n baseInput, // transactionChecksEnabled: false, transactionChecksOptIn: false\n (states) => {\n try {\n expect(optInMock).toHaveBeenCalled();\n // opt-in returned enabled: true, so provide runs.\n expect(provideMock).toHaveBeenCalled();\n const steps = stepSequence(states);\n expect(steps).toContain(\n signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN,\n );\n expect(steps).toContain(\n signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE,\n );\n expect(\n steps.indexOf(\n signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN,\n ),\n ).toBeLessThan(\n steps.indexOf(\n signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE,\n ),\n );\n // The opt-in outcome is surfaced so the parent can re-provision\n // without prompting again.\n expect(states[states.length - 1]).toEqual({\n status: DeviceActionStatus.Completed,\n output: { transactionChecksEnabled: true },\n });\n resolve();\n } catch (e) {\n reject(e);\n }\n },\n reject,\n );\n }));\n\n it(\"not opted-in + opt-in returns disabled: skips provide\", () =>\n new Promise<void>((resolve, reject) => {\n optInMock.mockResolvedValue(\n CommandResultFactory({ data: { enabled: false } }),\n );\n run(\n baseInput,\n (states) => {\n try {\n expect(optInMock).toHaveBeenCalled();\n expect(provideMock).not.toHaveBeenCalled();\n expect(states[states.length - 1]).toEqual({\n status: DeviceActionStatus.Completed,\n output: { transactionChecksEnabled: false },\n });\n resolve();\n } catch (e) {\n reject(e);\n }\n },\n reject,\n );\n }));\n\n it(\"already enabled: skips opt-in, runs provide directly\", () =>\n new Promise<void>((resolve, reject) => {\n run(\n {\n ...baseInput,\n appConfig: makeAppConfig({\n transactionChecksEnabled: true,\n transactionChecksOptIn: true,\n }),\n },\n (states) => {\n try {\n expect(optInMock).not.toHaveBeenCalled();\n expect(provideMock).toHaveBeenCalled();\n expect(states[states.length - 1]!.status).toBe(\n DeviceActionStatus.Completed,\n );\n resolve();\n } catch (e) {\n reject(e);\n }\n },\n reject,\n );\n }));\n\n it(\"already opted-in but not enabled: skips both opt-in and provide\", () =>\n new Promise<void>((resolve, reject) => {\n run(\n {\n ...baseInput,\n appConfig: makeAppConfig({\n transactionChecksEnabled: false,\n transactionChecksOptIn: true,\n }),\n },\n (states) => {\n try {\n expect(optInMock).not.toHaveBeenCalled();\n expect(provideMock).not.toHaveBeenCalled();\n expect(states[states.length - 1]!.status).toBe(\n DeviceActionStatus.Completed,\n );\n resolve();\n } catch (e) {\n reject(e);\n }\n },\n reject,\n );\n }));\n\n it(\"opt-in throws: still completes without provide (best-effort)\", () =>\n new Promise<void>((resolve, reject) => {\n optInMock.mockRejectedValue(new Error(\"transport error\"));\n run(\n baseInput,\n (states) => {\n try {\n expect(optInMock).toHaveBeenCalled();\n expect(provideMock).not.toHaveBeenCalled();\n expect(states[states.length - 1]!.status).toBe(\n DeviceActionStatus.Completed,\n );\n resolve();\n } catch (e) {\n reject(e);\n }\n },\n reject,\n );\n }));\n\n it(\"provide throws: still completes (best-effort)\", () =>\n new Promise<void>((resolve, reject) => {\n provideMock.mockRejectedValue(new Error(\"provide error\"));\n run(\n {\n ...baseInput,\n appConfig: makeAppConfig({\n transactionChecksEnabled: true,\n transactionChecksOptIn: true,\n }),\n },\n (states) => {\n try {\n expect(provideMock).toHaveBeenCalled();\n expect(states[states.length - 1]!.status).toBe(\n DeviceActionStatus.Completed,\n );\n resolve();\n } catch (e) {\n reject(e);\n }\n },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gDAAiD,IAClD,IAAI,QAAc,CAACD,EAASC,IAAW,CACrCf,EAAY,kBAAkB,IAAI,MAAM,eAAe,CAAC,EACxDE,EACE,CACE,GAAGW,EACH,UAAWjB,EAAc,CACvB,yBAA0B,GAC1B,uBAAwB,EAC1B,CAAC,CACH,EACCY,GAAW,CACV,GAAI,IACF,UAAOR,CAAW,EAAE,iBAAiB,KACrC,UAAOQ,EAAOA,EAAO,OAAS,CAAC,EAAG,MAAM,EAAE,KACxC,qBAAmB,SACrB,EACAM,EAAQ,CACV,OAASE,EAAG,CACVD,EAAOC,CAAC,CACV,CACF,EACAD,CACF,CACF,CAAC,CAAC,CACN,CAAC",
|
|
6
6
|
"names": ["import_device_management_kit", "import_vitest", "import_SignTransactionDeviceActionTypes", "import_PublicKeyDisplayMode", "import_makeInternalApi", "import_ProvisionTransactionCheckDeviceAction", "defaultDerivation", "exampleTx", "contextModuleStub", "makeAppConfig", "overrides", "apiMock", "optInMock", "provideMock", "extractDeps", "run", "input", "onComplete", "onError", "action", "observable", "states", "s", "stepSequence", "steps", "step", "baseInput", "resolve", "reject", "e"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var G=(o,n)=>{for(var c in n)d(o,c,{get:n[c],enumerable:!0})},O=(o,n,c,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of B(n))!F.call(o,s)&&s!==c&&d(o,s,{get:()=>n[s],enumerable:!(l=E(n,s))||l.enumerable});return o};var z=o=>O(d({},"__esModule",{value:!0}),o);var N={};G(N,{SignTransactionDeviceAction:()=>w});module.exports=z(N);var i=require("@ledgerhq/device-management-kit"),u=require("purify-ts"),a=require("xstate"),p=require("../../../api/app-binder/SignTransactionDeviceActionTypes"),f=require("../../app-binder/command/GetAppConfigurationCommand"),h=require("../../app-binder/constants"),y=require("../../app-binder/services/TransactionInputNormaliser"),k=require("../../app-binder/SolanaApplicationResolver"),A=require("../../app-binder/task/SolanaSigningReportTask"),v=require("./ProvisionBasicClearSignDeviceAction"),D=require("./ProvisionGenericClearSignDeviceAction"),P=require("./ProvisionTransactionCheckDeviceAction"),_=require("./SignBasicClearSignDeviceAction"),I=require("./SignGenericClearSignDeviceAction");function T(o){return o.transactionOptions?.solanaRPCURL??o.solanaRPCURL}class w extends i.XStateDeviceAction{makeStateMachine(n){const{normalizeTransaction:c,getAppConfig:l,reportSign:s}=this.extractDependencies(n),g=this.getLoggerFactory(n),M=g("SignTransactionDeviceAction"),R=this.input.disabledFeatures?new Set(this.input.disabledFeatures):void 0,S=(e,t)=>(0,k.isSolanaSignerFeatureSupported)(n,e,t,R),m=e=>{const t=T(e.input),r=e.input.transactionOptions?.fetchBlockhash,C=!!!e.input.transactionOptions?.transactionResolutionContext?.templateId&&e.input.transactionOptions?.delayed===!0&&!!(t||r)&&S("delayedSigning",e._internalState.appConfig);return{rpcUrl:C?t:void 0,fetchBlockhash:C?r:void 0}};return(0,a.setup)({types:{input:{},context:{},output:{}},actors:{normalizeTransaction:(0,a.fromPromise)(c),reportSign:(0,a.fromPromise)(s),openAppStateMachine:new i.OpenAppDeviceAction({input:{appName:h.APP_NAME}}).makeStateMachine(n),getAppConfig:(0,a.fromPromise)(l),transactionCheckStateMachine:new P.ProvisionTransactionCheckDeviceAction({input:{derivationPath:this.input.derivationPath,transaction:this.input.transaction,contextModule:this.input.contextModule},loggerFactory:this.getLoggerFactory(n)}).makeStateMachine(n),provisionGenericClearSignStateMachine:new D.ProvisionGenericClearSignDeviceAction({input:{derivationPath:this.input.derivationPath,transaction:this.input.transaction,contextModule:this.input.contextModule},loggerFactory:this.getLoggerFactory(n)}).makeStateMachine(n),provisionBasicClearSignStateMachine:new v.ProvisionBasicClearSignDeviceAction({input:{derivationPath:this.input.derivationPath,transaction:this.input.transaction,contextModule:this.input.contextModule},loggerFactory:this.getLoggerFactory(n)}).makeStateMachine(n),signGenericClearSignStateMachine:new I.SignGenericClearSignDeviceAction({input:{derivationPath:this.input.derivationPath,transaction:this.input.transaction},loggerFactory:this.getLoggerFactory(n)}).makeStateMachine(n),signBasicClearSignStateMachine:new _.SignBasicClearSignDeviceAction({input:{derivationPath:this.input.derivationPath,transaction:this.input.transaction},loggerFactory:this.getLoggerFactory(n)}).makeStateMachine(n)},guards:{noInternalError:({context:e})=>e._internalState.error===null,skipOpenApp:({context:e})=>e.input.transactionOptions?.skipOpenApp||!1,isTransactionChecksSupported:({context:e})=>S("transactionChecks",e._internalState.appConfig),isGenericClearSignAvailable:({context:e})=>S("genericClearSign",e._internalState.appConfig),isClearSignPrepared:({context:e})=>e._internalState.clearSignPrepared,hasSignature:({context:e})=>e._internalState.signature!==null},actions:{assignErrorFromEvent:(0,a.assign)({_internalState:e=>({...e.context._internalState,error:new i.UnknownDAError(e.event.error instanceof Error?e.event.error.message:String(e.event.error))})})}}).createMachine({id:"SignTransactionDeviceAction",initial:"NormalizeTransaction",context:({input:e})=>({input:e,intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.None,step:p.signTransactionDAStateSteps.OPEN_APP},_internalState:{error:null,signature:null,appConfig:null,messageBytes:this.input.transaction,serializedForTxCheck:void 0,clearSignPrepared:!1,unrecognizedProgramIds:[],staleDescriptor:!1}}),states:{NormalizeTransaction:{entry:(0,a.assign)({intermediateValue:({context:e})=>({requiredUserInteraction:i.UserInteractionRequired.None,step:e.input.transactionOptions?.skipOpenApp?p.signTransactionDAStateSteps.GET_APP_CONFIG:p.signTransactionDAStateSteps.OPEN_APP})}),invoke:{id:"normalizeTransaction",src:"normalizeTransaction",onDone:[{target:"GetAppConfig",guard:"skipOpenApp",actions:(0,a.assign)({_internalState:({event:e,context:t})=>({...t._internalState,messageBytes:e.output.messageBytes,serializedForTxCheck:e.output.serializedForTxCheck})})},{target:"OpenAppDeviceAction",actions:(0,a.assign)({_internalState:({event:e,context:t})=>({...t._internalState,messageBytes:e.output.messageBytes,serializedForTxCheck:e.output.serializedForTxCheck})})}]}},OpenAppDeviceAction:{entry:(0,a.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.None,step:p.signTransactionDAStateSteps.OPEN_APP})}),invoke:{id:"openAppStateMachine",src:"openAppStateMachine",input:()=>({appName:h.APP_NAME}),onSnapshot:{actions:(0,a.assign)({intermediateValue:({event:e})=>({...e.snapshot.context.intermediateValue,step:p.signTransactionDAStateSteps.OPEN_APP})})},onDone:{target:"OpenAppResultCheck",actions:(0,a.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:()=>t._internalState,Left:r=>({...t._internalState,error:r})})})}}},OpenAppResultCheck:{always:[{target:"GetAppConfig",guard:"noInternalError"},{target:"Error"}]},GetAppConfig:{entry:(0,a.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.None,step:p.signTransactionDAStateSteps.GET_APP_CONFIG})}),invoke:{id:"getAppConfig",src:"getAppConfig",onDone:{target:"GetAppConfigResultCheck",actions:(0,a.assign)({_internalState:({event:e,context:t})=>(0,i.isSuccessCommandResult)(e.output)?{...t._internalState,appConfig:e.output.data}:{...t._internalState,error:e.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetAppConfigResultCheck:{always:[{target:"CheckTransactionCheckSupported",guard:"noInternalError"},{target:"Error"}]},CheckTransactionCheckSupported:{always:[{target:"TxCheck",guard:"isTransactionChecksSupported"},{target:"CheckGenericClearSignSupported"}]},TxCheck:{invoke:{id:"transactionCheckStateMachine",src:"transactionCheckStateMachine",input:({context:e})=>({appConfig:e._internalState.appConfig,derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,contextModule:e.input.contextModule,serializedForTxCheck:e._internalState.serializedForTxCheck}),onSnapshot:{actions:(0,a.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckGenericClearSignSupported"}}},CheckGenericClearSignSupported:{always:[{target:"GenericClearSign",guard:(0,a.and)(["noInternalError","isGenericClearSignAvailable"])},{target:"BasicClearSign",guard:"noInternalError"},{target:"Error"}]},GenericClearSign:{invoke:{id:"provisionGenericClearSignStateMachine",src:"provisionGenericClearSignStateMachine",input:({context:e})=>({derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,contextModule:e.input.contextModule}),onSnapshot:{actions:(0,a.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckGenericClearSignResult",actions:(0,a.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:r=>({...t._internalState,clearSignPrepared:r.status==="prepared",unrecognizedProgramIds:r.unrecognizedProgramIds,staleDescriptor:r.staleDescriptor}),Left:r=>({...t._internalState,error:r})})})},onError:{target:"BasicClearSign",actions:({event:e})=>M.info("[ClearSign] generic clear-sign threw; falling back to legacy",{data:{error:String(e.error)}})}}},CheckGenericClearSignResult:{always:[{target:"GenericTerminalSign",guard:(0,a.and)(["noInternalError","isClearSignPrepared"])},{target:"BasicClearSign",guard:"noInternalError"},{target:"Error"}]},GenericTerminalSign:{invoke:{id:"signGenericClearSignStateMachine",src:"signGenericClearSignStateMachine",input:({context:e})=>{const{rpcUrl:t,fetchBlockhash:r}=m(e);return{derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,rpcUrl:t,fetchBlockhash:r,userInputType:e.input.transactionOptions?.transactionResolutionContext?.userInputType,blockhashService:e.input.blockhashService}},onSnapshot:{actions:(0,a.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckGenericTerminalSignResult",actions:(0,a.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:r=>r==="degraded"?t._internalState:{...t._internalState,signature:r},Left:r=>({...t._internalState,error:r})})})}}},CheckGenericTerminalSignResult:{always:[{target:"Report",guard:"hasSignature"},{target:"BasicClearSign",guard:"noInternalError"},{target:"Report"}]},BasicClearSign:{invoke:{id:"provisionBasicClearSignStateMachine",src:"provisionBasicClearSignStateMachine",input:({context:e})=>({derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,contextModule:e.input.contextModule,appConfig:e._internalState.appConfig,rpcUrl:T(e.input),resolutionContext:e.input.transactionOptions?.transactionResolutionContext}),onSnapshot:{actions:(0,a.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"Report"},onError:{target:"Report"}}},Report:{invoke:{src:"reportSign",input:({context:e})=>{const t=n.getDeviceSessionState(),r=t.sessionStateType!==i.DeviceSessionStateType.Connected?t.firmwareVersion?.os??null:null;return{isBlindSign:e._internalState.signature===null&&e._internalState.error===null,messageBytes:e._internalState.messageBytes,unrecognizedProgramIds:e._internalState.unrecognizedProgramIds,staleDescriptor:e._internalState.staleDescriptor,contextModule:e.input.contextModule,signerAppVersion:e._internalState.appConfig.version,deviceModelId:t.deviceModelId,deviceVersion:r,loggerFactory:g}},onDone:[{target:"SignTransactionResultCheck",guard:"hasSignature"},{target:"Error",guard:({context:e})=>e._internalState.error!==null},{target:"BasicTerminalSign"}],onError:[{target:"SignTransactionResultCheck",guard:"hasSignature"},{target:"Error",guard:({context:e})=>e._internalState.error!==null},{target:"BasicTerminalSign"}]}},BasicTerminalSign:{invoke:{id:"signBasicClearSignStateMachine",src:"signBasicClearSignStateMachine",input:({context:e})=>{const{rpcUrl:t,fetchBlockhash:r}=m(e);return{derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,rpcUrl:t,fetchBlockhash:r,userInputType:e.input.transactionOptions?.transactionResolutionContext?.userInputType,blockhashService:e.input.blockhashService}},onSnapshot:{actions:(0,a.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"SignTransactionResultCheck",actions:(0,a.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:r=>({...t._internalState,signature:r}),Left:r=>({...t._internalState,error:r})})})}}},SignTransactionResultCheck:{always:[{guard:"noInternalError",target:"Success"},{target:"Error"}]},Success:{type:"final"},Error:{type:"final"}},output:({context:e})=>e._internalState.signature?(0,u.Right)(e._internalState.signature):(0,u.Left)(e._internalState.error||new i.UnknownDAError("No error or signature available"))})}extractDependencies(n){return{normalizeTransaction:async()=>{try{return new y.TransactionInputNormaliser().normalize(this.input.transaction)}catch(g){return this.getLoggerFactory(n)("NormalizeTransaction").warn("[normalizeTransaction] format detection failed; treating input as message bytes",{data:{error:String(g)}}),{messageBytes:this.input.transaction,serializedForTxCheck:void 0}}},getAppConfig:async()=>n.sendCommand(new f.GetAppConfigurationCommand),reportSign:async g=>new A.SolanaSigningReportTask(g.input).run()}}}0&&(module.exports={SignTransactionDeviceAction});
|
|
1
|
+
"use strict";var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var O=(o,a)=>{for(var c in a)d(o,c,{get:a[c],enumerable:!0})},G=(o,a,c,l)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of B(a))!F.call(o,s)&&s!==c&&d(o,s,{get:()=>a[s],enumerable:!(l=E(a,s))||l.enumerable});return o};var z=o=>G(d({},"__esModule",{value:!0}),o);var V={};O(V,{SignTransactionDeviceAction:()=>w});module.exports=z(V);var r=require("@ledgerhq/device-management-kit"),u=require("purify-ts"),n=require("xstate"),p=require("../../../api/app-binder/SignTransactionDeviceActionTypes"),k=require("../../app-binder/command/GetAppConfigurationCommand"),h=require("../../app-binder/constants"),f=require("../../app-binder/services/TransactionInputNormaliser"),y=require("../../app-binder/SolanaApplicationResolver"),v=require("../../app-binder/task/SolanaSigningReportTask"),A=require("./ProvisionBasicClearSignDeviceAction"),D=require("./ProvisionGenericClearSignDeviceAction"),_=require("./ProvisionTransactionCheckDeviceAction"),P=require("./SignBasicClearSignDeviceAction"),M=require("./SignGenericClearSignDeviceAction");function T(o){return o.transactionOptions?.solanaRPCURL??o.solanaRPCURL}class w extends r.XStateDeviceAction{makeStateMachine(a){const{normalizeTransaction:c,getAppConfig:l,reportSign:s}=this.extractDependencies(a),g=this.getLoggerFactory(a),I=g("SignTransactionDeviceAction"),R=this.input.disabledFeatures?new Set(this.input.disabledFeatures):void 0,S=(e,t)=>(0,y.isSolanaSignerFeatureSupported)(a,e,t,R),C=e=>{const t=T(e.input),i=e.input.transactionOptions?.fetchBlockhash,m=!!!e.input.transactionOptions?.transactionResolutionContext?.templateId&&e.input.transactionOptions?.delayed===!0&&!!(t||i)&&S("delayedSigning",e._internalState.appConfig);return{rpcUrl:m?t:void 0,fetchBlockhash:m?i:void 0}};return(0,n.setup)({types:{input:{},context:{},output:{}},actors:{normalizeTransaction:(0,n.fromPromise)(c),reportSign:(0,n.fromPromise)(s),openAppStateMachine:new r.OpenAppDeviceAction({input:{appName:h.APP_NAME}}).makeStateMachine(a),getAppConfig:(0,n.fromPromise)(l),transactionCheckStateMachine:new _.ProvisionTransactionCheckDeviceAction({input:{derivationPath:this.input.derivationPath,transaction:this.input.transaction,contextModule:this.input.contextModule},loggerFactory:this.getLoggerFactory(a)}).makeStateMachine(a),provisionGenericClearSignStateMachine:new D.ProvisionGenericClearSignDeviceAction({input:{derivationPath:this.input.derivationPath,transaction:this.input.transaction,contextModule:this.input.contextModule},loggerFactory:this.getLoggerFactory(a)}).makeStateMachine(a),provisionBasicClearSignStateMachine:new A.ProvisionBasicClearSignDeviceAction({input:{derivationPath:this.input.derivationPath,transaction:this.input.transaction,contextModule:this.input.contextModule},loggerFactory:this.getLoggerFactory(a)}).makeStateMachine(a),signGenericClearSignStateMachine:new M.SignGenericClearSignDeviceAction({input:{derivationPath:this.input.derivationPath,transaction:this.input.transaction},loggerFactory:this.getLoggerFactory(a)}).makeStateMachine(a),signBasicClearSignStateMachine:new P.SignBasicClearSignDeviceAction({input:{derivationPath:this.input.derivationPath,transaction:this.input.transaction},loggerFactory:this.getLoggerFactory(a)}).makeStateMachine(a)},guards:{noInternalError:({context:e})=>e._internalState.error===null,skipOpenApp:({context:e})=>e.input.transactionOptions?.skipOpenApp||!1,isTransactionChecksSupported:({context:e})=>S("transactionChecks",e._internalState.appConfig),isGenericClearSignAvailable:({context:e})=>S("genericClearSign",e._internalState.appConfig),isClearSignPrepared:({context:e})=>e._internalState.clearSignPrepared,hasSignature:({context:e})=>e._internalState.signature!==null},actions:{assignErrorFromEvent:(0,n.assign)({_internalState:e=>({...e.context._internalState,error:new r.UnknownDAError(e.event.error instanceof Error?e.event.error.message:String(e.event.error))})})}}).createMachine({id:"SignTransactionDeviceAction",initial:"NormalizeTransaction",context:({input:e})=>({input:e,intermediateValue:{requiredUserInteraction:r.UserInteractionRequired.None,step:p.signTransactionDAStateSteps.OPEN_APP},_internalState:{error:null,signature:null,appConfig:null,messageBytes:this.input.transaction,serializedForTxCheck:void 0,clearSignPrepared:!1,unrecognizedProgramIds:[],staleDescriptor:!1}}),states:{NormalizeTransaction:{entry:(0,n.assign)({intermediateValue:({context:e})=>({requiredUserInteraction:r.UserInteractionRequired.None,step:e.input.transactionOptions?.skipOpenApp?p.signTransactionDAStateSteps.GET_APP_CONFIG:p.signTransactionDAStateSteps.OPEN_APP})}),invoke:{id:"normalizeTransaction",src:"normalizeTransaction",onDone:[{target:"GetAppConfig",guard:"skipOpenApp",actions:(0,n.assign)({_internalState:({event:e,context:t})=>({...t._internalState,messageBytes:e.output.messageBytes,serializedForTxCheck:e.output.serializedForTxCheck})})},{target:"OpenAppDeviceAction",actions:(0,n.assign)({_internalState:({event:e,context:t})=>({...t._internalState,messageBytes:e.output.messageBytes,serializedForTxCheck:e.output.serializedForTxCheck})})}]}},OpenAppDeviceAction:{entry:(0,n.assign)({intermediateValue:()=>({requiredUserInteraction:r.UserInteractionRequired.None,step:p.signTransactionDAStateSteps.OPEN_APP})}),invoke:{id:"openAppStateMachine",src:"openAppStateMachine",input:()=>({appName:h.APP_NAME}),onSnapshot:{actions:(0,n.assign)({intermediateValue:({event:e})=>({...e.snapshot.context.intermediateValue,step:p.signTransactionDAStateSteps.OPEN_APP})})},onDone:{target:"OpenAppResultCheck",actions:(0,n.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:()=>t._internalState,Left:i=>({...t._internalState,error:i})})})}}},OpenAppResultCheck:{always:[{target:"GetAppConfig",guard:"noInternalError"},{target:"Error"}]},GetAppConfig:{entry:(0,n.assign)({intermediateValue:()=>({requiredUserInteraction:r.UserInteractionRequired.None,step:p.signTransactionDAStateSteps.GET_APP_CONFIG})}),invoke:{id:"getAppConfig",src:"getAppConfig",onDone:{target:"GetAppConfigResultCheck",actions:(0,n.assign)({_internalState:({event:e,context:t})=>(0,r.isSuccessCommandResult)(e.output)?{...t._internalState,appConfig:e.output.data}:{...t._internalState,error:e.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetAppConfigResultCheck:{always:[{target:"CheckTransactionCheckSupported",guard:"noInternalError"},{target:"Error"}]},CheckTransactionCheckSupported:{always:[{target:"TxCheck",guard:"isTransactionChecksSupported"},{target:"CheckGenericClearSignSupported"}]},TxCheck:{invoke:{id:"transactionCheckStateMachine",src:"transactionCheckStateMachine",input:({context:e})=>({appConfig:e._internalState.appConfig,derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,contextModule:e.input.contextModule,serializedForTxCheck:e._internalState.serializedForTxCheck}),onSnapshot:{actions:(0,n.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckGenericClearSignSupported",actions:(0,n.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:({transactionChecksEnabled:i})=>({...t._internalState,appConfig:{...t._internalState.appConfig,transactionChecksEnabled:i,transactionChecksOptIn:!0}}),Left:()=>t._internalState})})}}},CheckGenericClearSignSupported:{always:[{target:"GenericClearSign",guard:(0,n.and)(["noInternalError","isGenericClearSignAvailable"])},{target:"BasicClearSign",guard:"noInternalError"},{target:"Error"}]},GenericClearSign:{invoke:{id:"provisionGenericClearSignStateMachine",src:"provisionGenericClearSignStateMachine",input:({context:e})=>({derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,contextModule:e.input.contextModule}),onSnapshot:{actions:(0,n.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckGenericClearSignResult",actions:(0,n.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:i=>({...t._internalState,clearSignPrepared:i.status==="prepared",unrecognizedProgramIds:i.unrecognizedProgramIds,staleDescriptor:i.staleDescriptor}),Left:i=>({...t._internalState,error:i})})})},onError:{target:"CheckTxCheckReprovision",actions:({event:e})=>I.info("[ClearSign] generic clear-sign threw; falling back to legacy",{data:{error:String(e.error)}})}}},CheckGenericClearSignResult:{always:[{target:"GenericTerminalSign",guard:(0,n.and)(["noInternalError","isClearSignPrepared"])},{target:"CheckTxCheckReprovision",guard:"noInternalError"},{target:"Error"}]},GenericTerminalSign:{invoke:{id:"signGenericClearSignStateMachine",src:"signGenericClearSignStateMachine",input:({context:e})=>{const{rpcUrl:t,fetchBlockhash:i}=C(e);return{derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,rpcUrl:t,fetchBlockhash:i,userInputType:e.input.transactionOptions?.transactionResolutionContext?.userInputType,blockhashService:e.input.blockhashService}},onSnapshot:{actions:(0,n.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"CheckGenericTerminalSignResult",actions:(0,n.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:i=>i==="degraded"?t._internalState:{...t._internalState,signature:i},Left:i=>({...t._internalState,error:i})})})}}},CheckGenericTerminalSignResult:{always:[{target:"Report",guard:"hasSignature"},{target:"CheckTxCheckReprovision",guard:"noInternalError"},{target:"Report"}]},CheckTxCheckReprovision:{always:[{target:"TxCheckReprovision",guard:"isTransactionChecksSupported"},{target:"BasicClearSign"}]},TxCheckReprovision:{invoke:{id:"transactionCheckReprovisionStateMachine",src:"transactionCheckStateMachine",input:({context:e})=>({appConfig:e._internalState.appConfig,derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,contextModule:e.input.contextModule,serializedForTxCheck:e._internalState.serializedForTxCheck}),onSnapshot:{actions:(0,n.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"BasicClearSign"}}},BasicClearSign:{invoke:{id:"provisionBasicClearSignStateMachine",src:"provisionBasicClearSignStateMachine",input:({context:e})=>({derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,contextModule:e.input.contextModule,appConfig:e._internalState.appConfig,rpcUrl:T(e.input),resolutionContext:e.input.transactionOptions?.transactionResolutionContext}),onSnapshot:{actions:(0,n.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"Report"},onError:{target:"Report"}}},Report:{invoke:{src:"reportSign",input:({context:e})=>{const t=a.getDeviceSessionState(),i=t.sessionStateType!==r.DeviceSessionStateType.Connected?t.firmwareVersion?.os??null:null;return{isBlindSign:e._internalState.signature===null&&e._internalState.error===null,messageBytes:e._internalState.messageBytes,unrecognizedProgramIds:e._internalState.unrecognizedProgramIds,staleDescriptor:e._internalState.staleDescriptor,contextModule:e.input.contextModule,signerAppVersion:e._internalState.appConfig.version,deviceModelId:t.deviceModelId,deviceVersion:i,loggerFactory:g}},onDone:[{target:"SignTransactionResultCheck",guard:"hasSignature"},{target:"Error",guard:({context:e})=>e._internalState.error!==null},{target:"BasicTerminalSign"}],onError:[{target:"SignTransactionResultCheck",guard:"hasSignature"},{target:"Error",guard:({context:e})=>e._internalState.error!==null},{target:"BasicTerminalSign"}]}},BasicTerminalSign:{invoke:{id:"signBasicClearSignStateMachine",src:"signBasicClearSignStateMachine",input:({context:e})=>{const{rpcUrl:t,fetchBlockhash:i}=C(e);return{derivationPath:e.input.derivationPath,transaction:e._internalState.messageBytes,rpcUrl:t,fetchBlockhash:i,userInputType:e.input.transactionOptions?.transactionResolutionContext?.userInputType,blockhashService:e.input.blockhashService}},onSnapshot:{actions:(0,n.assign)({intermediateValue:({event:e})=>e.snapshot.context.intermediateValue})},onDone:{target:"SignTransactionResultCheck",actions:(0,n.assign)({_internalState:({event:e,context:t})=>e.output.caseOf({Right:i=>({...t._internalState,signature:i}),Left:i=>({...t._internalState,error:i})})})}}},SignTransactionResultCheck:{always:[{guard:"noInternalError",target:"Success"},{target:"Error"}]},Success:{type:"final"},Error:{type:"final"}},output:({context:e})=>e._internalState.signature?(0,u.Right)(e._internalState.signature):(0,u.Left)(e._internalState.error||new r.UnknownDAError("No error or signature available"))})}extractDependencies(a){return{normalizeTransaction:async()=>{try{return new f.TransactionInputNormaliser().normalize(this.input.transaction)}catch(g){return this.getLoggerFactory(a)("NormalizeTransaction").warn("[normalizeTransaction] format detection failed; treating input as message bytes",{data:{error:String(g)}}),{messageBytes:this.input.transaction,serializedForTxCheck:void 0}}},getAppConfig:async()=>a.sendCommand(new k.GetAppConfigurationCommand),reportSign:async g=>new v.SolanaSigningReportTask(g.input).run()}}}0&&(module.exports={SignTransactionDeviceAction});
|
|
2
2
|
//# sourceMappingURL=SignTransactionDeviceAction.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/device-action/SignTransactionDeviceAction.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type CommandResult,\n type DeviceActionStateMachine,\n DeviceSessionStateType,\n type InternalApi,\n isSuccessCommandResult,\n OpenAppDeviceAction,\n type StateMachineTypes,\n UnknownDAError,\n UserInteractionRequired,\n XStateDeviceAction,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { and, assign, fromPromise, setup } from \"xstate\";\n\nimport {\n type SignTransactionDAError,\n type SignTransactionDAInput,\n type SignTransactionDAIntermediateValue,\n type SignTransactionDAInternalState,\n type SignTransactionDAOutput,\n signTransactionDAStateSteps,\n} from \"@api/app-binder/SignTransactionDeviceActionTypes\";\nimport { type AppConfiguration } from \"@api/model/AppConfiguration\";\nimport { GetAppConfigurationCommand } from \"@internal/app-binder/command/GetAppConfigurationCommand\";\nimport { type SolanaAppErrorCodes } from \"@internal/app-binder/command/utils/SolanaApplicationErrors\";\nimport { APP_NAME } from \"@internal/app-binder/constants\";\nimport {\n type NormalizedTransactionInput,\n TransactionInputNormaliser,\n} from \"@internal/app-binder/services/TransactionInputNormaliser\";\nimport {\n isSolanaSignerFeatureSupported,\n type SolanaSignerFeaturesNames,\n} from \"@internal/app-binder/SolanaApplicationResolver\";\nimport {\n SolanaSigningReportTask,\n type SolanaSigningReportTaskArgs,\n} from \"@internal/app-binder/task/SolanaSigningReportTask\";\n\nimport { ProvisionBasicClearSignDeviceAction } from \"./ProvisionBasicClearSignDeviceAction\";\nimport { ProvisionGenericClearSignDeviceAction } from \"./ProvisionGenericClearSignDeviceAction\";\nimport { ProvisionTransactionCheckDeviceAction } from \"./ProvisionTransactionCheckDeviceAction\";\nimport { SignBasicClearSignDeviceAction } from \"./SignBasicClearSignDeviceAction\";\nimport { SignGenericClearSignDeviceAction } from \"./SignGenericClearSignDeviceAction\";\n\n/**\n * Per-sign `transactionOptions.solanaRPCURL` overrides the builder default\n * (`input.solanaRPCURL`) for inspection and delayed signing.\n */\nfunction resolveSolanaRpcUrl(\n input: SignTransactionDAInput,\n): string | undefined {\n return input.transactionOptions?.solanaRPCURL ?? input.solanaRPCURL;\n}\n\nexport type MachineDependencies = {\n readonly normalizeTransaction: () => Promise<NormalizedTransactionInput>;\n readonly getAppConfig: () => Promise<\n CommandResult<AppConfiguration, SolanaAppErrorCodes>\n >;\n readonly reportSign: (arg0: {\n input: SolanaSigningReportTaskArgs;\n }) => Promise<void>;\n};\n\nexport class SignTransactionDeviceAction extends XStateDeviceAction<\n SignTransactionDAOutput,\n SignTransactionDAInput,\n SignTransactionDAError,\n SignTransactionDAIntermediateValue,\n SignTransactionDAInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n SignTransactionDAOutput,\n SignTransactionDAInput,\n SignTransactionDAError,\n SignTransactionDAIntermediateValue,\n SignTransactionDAInternalState\n > {\n type types = StateMachineTypes<\n SignTransactionDAOutput,\n SignTransactionDAInput,\n SignTransactionDAError,\n SignTransactionDAIntermediateValue,\n SignTransactionDAInternalState\n >;\n\n const { normalizeTransaction, getAppConfig, reportSign } =\n this.extractDependencies(internalApi);\n\n const loggerFactory = this.getLoggerFactory(internalApi);\n const logger = loggerFactory(\"SignTransactionDeviceAction\");\n\n const disabledFeaturesSet:\n | ReadonlySet<SolanaSignerFeaturesNames>\n | undefined = this.input.disabledFeatures\n ? new Set(this.input.disabledFeatures)\n : undefined;\n\n const isSupported = (\n feature: SolanaSignerFeaturesNames,\n appConfig: AppConfiguration,\n ): boolean =>\n isSolanaSignerFeatureSupported(\n internalApi,\n feature,\n appConfig,\n disabledFeaturesSet,\n );\n\n // Blockhash refresh is opt-in and shared by both terminal-sign machines:\n // only when `delayed: true` is requested, a blockhash source exists, and\n // the app supports delayed signing. When it isn't allowed we withhold the\n // source so the signing machine signs the original transaction.\n //\n // Template-based swaps (LiFi, etc.) always sign with the original blockhash:\n // CAL-provided e016 descriptors are computed for the original transaction, so\n // refreshing the blockhash would invalidate them and make the Exchange app\n // reject the sign with a descriptor-mismatch error.\n const resolveRefreshSource = (\n context: types[\"context\"],\n ): {\n rpcUrl: string | undefined;\n fetchBlockhash: (() => Promise<Uint8Array>) | undefined;\n } => {\n const rpcUrl = resolveSolanaRpcUrl(context.input);\n const fetchBlockhash = context.input.transactionOptions?.fetchBlockhash;\n const isTemplateSwap =\n !!context.input.transactionOptions?.transactionResolutionContext\n ?.templateId;\n const refreshBlockhash =\n !isTemplateSwap &&\n context.input.transactionOptions?.delayed === true &&\n !!(rpcUrl || fetchBlockhash) &&\n isSupported(\"delayedSigning\", context._internalState.appConfig!);\n return {\n rpcUrl: refreshBlockhash ? rpcUrl : undefined,\n fetchBlockhash: refreshBlockhash ? fetchBlockhash : undefined,\n };\n };\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n normalizeTransaction: fromPromise(normalizeTransaction),\n reportSign: fromPromise(reportSign),\n openAppStateMachine: new OpenAppDeviceAction({\n input: { appName: APP_NAME },\n }).makeStateMachine(internalApi),\n getAppConfig: fromPromise(getAppConfig),\n transactionCheckStateMachine: new ProvisionTransactionCheckDeviceAction(\n {\n input: {\n derivationPath: this.input.derivationPath,\n transaction: this.input.transaction,\n contextModule: this.input.contextModule,\n },\n loggerFactory: this.getLoggerFactory(internalApi),\n },\n ).makeStateMachine(internalApi),\n provisionGenericClearSignStateMachine:\n new ProvisionGenericClearSignDeviceAction({\n input: {\n derivationPath: this.input.derivationPath,\n transaction: this.input.transaction,\n contextModule: this.input.contextModule,\n },\n loggerFactory: this.getLoggerFactory(internalApi),\n }).makeStateMachine(internalApi),\n provisionBasicClearSignStateMachine:\n new ProvisionBasicClearSignDeviceAction({\n // `appConfig` is unknown at construction; it is supplied at invoke\n // time (see the BasicClearSign state input below).\n input: {\n derivationPath: this.input.derivationPath,\n transaction: this.input.transaction,\n contextModule: this.input.contextModule,\n },\n loggerFactory: this.getLoggerFactory(internalApi),\n }).makeStateMachine(internalApi),\n signGenericClearSignStateMachine: new SignGenericClearSignDeviceAction({\n input: {\n derivationPath: this.input.derivationPath,\n transaction: this.input.transaction,\n },\n loggerFactory: this.getLoggerFactory(internalApi),\n }).makeStateMachine(internalApi),\n signBasicClearSignStateMachine: new SignBasicClearSignDeviceAction({\n input: {\n derivationPath: this.input.derivationPath,\n transaction: this.input.transaction,\n },\n loggerFactory: this.getLoggerFactory(internalApi),\n }).makeStateMachine(internalApi),\n },\n guards: {\n noInternalError: ({ context }) => context._internalState.error === null,\n skipOpenApp: ({ context }) =>\n context.input.transactionOptions?.skipOpenApp || false,\n isTransactionChecksSupported: ({ context }) =>\n isSupported(\"transactionChecks\", context._internalState.appConfig!),\n // Generic clear-signing terminates via SIGN MESSAGE DELAYED (0x09) on\n // the original message, so it only needs the capability bit \u2014 no RPC /\n // blockhash prerequisite.\n isGenericClearSignAvailable: ({ context }) =>\n isSupported(\"genericClearSign\", context._internalState.appConfig!),\n // Generic clear-sign child streamed + finalized the descriptors (its\n // Right(\"prepared\") outcome was folded into the context by the\n // GenericClearSign onDone).\n isClearSignPrepared: ({ context }) =>\n context._internalState.clearSignPrepared,\n hasSignature: ({ context }) =>\n context._internalState.signature !== null,\n },\n actions: {\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new UnknownDAError(\n _.event[\"error\"] instanceof Error\n ? _.event[\"error\"].message\n : String(_.event[\"error\"]),\n ),\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QGUCWUB2AVATgQw1jwGMAXVAewwBEwA3VYsAQTMowDoBJDVcvADbJSeUmADEAbQAMAXUSgADhVh92CkAA9EARgDsAZg4AOAJzSAbAYAsOgKymdN08YA0IAJ67LxjnbvWxjoW-kGGxgC+Ee5omLgERGxUtAxMrORU3Lz8QiJiUjrySCDKqhkYGtoI+kZmljb2js5unojmRgbS1haG0o5OllEx6Nj4hCTlKYwsSZwA8opgGMyKilNps+IQVGAcqBh0FADWuxSLy6vComAAsiQAFvtgMkVKKmpUlYh6dgBMHL8bJ0LKY7AZOr87O4vAhjHpTCZfkEDHo+nprL8ekMQLFRgkJux1jNyhwFksVooAEpwACuAlIAGF7mBiEcpHINKUPhVilUdL9gn5TCjfr9rNJ+X8WjDzAi9AKDGLwb94RZrNjcfFxrMiel2KTzhTqbA6YzmayCq8Su9yl9qgKLEKRWKJZCkdDEEE-NIffLAX8LPUNSMtYlJvRpnrMgBxMCkCkMqgAM3QWx2ewOx12MHjq0TGBTUBenJt6l5uj9JmsBjhxjhdn0pg91S61gB1kCPT0aosxiRwbiYzDhIjGxJsdzinzhfEYBwOAoOA4igEoiTi4Athwcwnk+hi8Uubby9VK8Zq7X643m78fRwfT7+fCxQ2B3jteHUsT9RPdwX0MappMiybIHm8ZRlqAVQCuYHAWJClj8qYSpQq0LZ6HoHA2D2PpwuCphvqGBLJKO34xnGf6FoB9LARakiFCWEGfCeMHSHBCEWEhKHNt2dj3ghdh9FYgLGHYhFDsRNCkVGn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DG+p44pIwEpHy1N-6aSqCEQUQIGbymMOCMEBVgZgjVNEkELNuixyGURa2ViOATJGdM2KatyGVzGosx0yyehInWQYehCJtkdkZn8YO0Soh2QwBQCAcANDnIls5OpI06ZVAALQWGbLC+8D4kXIrVBY0ZV9OA8DUDki6cz-pVAxM2HQlg2I1hmtIES61Bn2WSSMyWJIyQXDWOCzSkLNZ2EdICasAs-imIMKCAq-g-ABHgv0Wwok0X0v1Iyo0tIaKxTxVC7wFL7z2EEsEUWcNuzQwlMKjewozDNJ0JKll5FJzTnQIqu0OhxSYQbKLLogJ4agleWhYlxKTB1iaYZDsARDk0uGWCsZZrKIATlcpVkVqTw6GFP7FmoIBQrTWToIllg+LmRtaiTmqJlQmuDZwfaMUQJHR4FGsaYonAg1yhCBs2VGapv5feFm-K4lOA3nmjFdUDrFu+uGstAMDJmA4MS8GQRRSKnMgVbKZl4Z9H5KKJEgQO2nOlgQzxH8lYU0gP2qoUc+JjvZhKZC8E4VoX6Iw5EfY4nVmNUkwNJy0n21TvYzAO7EA1jWdQn4GEzD6HlAVOEJgwS3lwvG9hd7jlINqjYyRdiZGvpuYEglok+Iit3lYfoKa0ImzMsBroyF9BxOXWkjJPVslCBGG+hA-gGz3lncLMUBlXUwnhm2Qx0SNrBHMtS0FD7oO90mZckCVH4J-DMgKeUIQwHswKvoLCeyJQbXgvKYj0GaTECYLAeAiG6kLPlJhTEgR5QNxVMxz0oo-AM26PBYI-KzGqZcgAUTajgET+mAQ7OMwKUzzYlqYXDhytZ6q8Lqj+UAA */\n id: \"SignTransactionDeviceAction\",\n initial: \"NormalizeTransaction\",\n context: ({ input }) => ({\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.OPEN_APP,\n },\n _internalState: {\n error: null,\n signature: null,\n appConfig: null,\n messageBytes: this.input.transaction,\n serializedForTxCheck: undefined,\n clearSignPrepared: false,\n unrecognizedProgramIds: [],\n staleDescriptor: false,\n },\n }),\n states: {\n NormalizeTransaction: {\n // Emit the correct first step immediately so the snapshot produced\n // while the actor runs already reflects where we are headed.\n entry: assign({\n intermediateValue: ({ context }) => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: context.input.transactionOptions?.skipOpenApp\n ? signTransactionDAStateSteps.GET_APP_CONFIG\n : signTransactionDAStateSteps.OPEN_APP,\n }),\n }),\n invoke: {\n id: \"normalizeTransaction\",\n src: \"normalizeTransaction\",\n onDone: [\n {\n target: \"GetAppConfig\",\n guard: \"skipOpenApp\",\n actions: assign({\n _internalState: ({ event, context }) => ({\n ...context._internalState,\n messageBytes: event.output.messageBytes,\n serializedForTxCheck: event.output.serializedForTxCheck,\n }),\n }),\n },\n {\n target: \"OpenAppDeviceAction\",\n actions: assign({\n _internalState: ({ event, context }) => ({\n ...context._internalState,\n messageBytes: event.output.messageBytes,\n serializedForTxCheck: event.output.serializedForTxCheck,\n }),\n }),\n },\n ],\n },\n },\n OpenAppDeviceAction: {\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.OPEN_APP,\n }),\n }),\n invoke: {\n id: \"openAppStateMachine\",\n src: \"openAppStateMachine\",\n input: () => ({ appName: APP_NAME }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) => ({\n ...event.snapshot.context.intermediateValue,\n step: signTransactionDAStateSteps.OPEN_APP,\n }),\n }),\n },\n onDone: {\n target: \"OpenAppResultCheck\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf({\n Right: () => context._internalState,\n Left: (error) => ({\n ...context._internalState,\n error,\n }),\n }),\n }),\n },\n },\n },\n OpenAppResultCheck: {\n always: [\n { target: \"GetAppConfig\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n GetAppConfig: {\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.GET_APP_CONFIG,\n }),\n }),\n invoke: {\n id: \"getAppConfig\",\n src: \"getAppConfig\",\n onDone: {\n target: \"GetAppConfigResultCheck\",\n actions: assign({\n _internalState: ({ event, context }) =>\n isSuccessCommandResult(event.output)\n ? {\n ...context._internalState,\n appConfig: event.output.data,\n }\n : { ...context._internalState, error: event.output.error },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetAppConfigResultCheck: {\n always: [\n {\n target: \"CheckTransactionCheckSupported\",\n guard: \"noInternalError\",\n },\n { target: \"Error\" },\n ],\n },\n CheckTransactionCheckSupported: {\n always: [\n // Feature supported: delegate opt-in + provide to the child machine.\n {\n target: \"TxCheck\",\n guard: \"isTransactionChecksSupported\",\n },\n // Feature not supported: skip the child machine entirely.\n { target: \"CheckGenericClearSignSupported\" },\n ],\n },\n // Web3-checks child machine: handles opt-in prompt and scan-descriptor\n // provisioning. Only reached when the feature is supported; opt-in and\n // provide decisions are made internally.\n TxCheck: {\n invoke: {\n id: \"transactionCheckStateMachine\",\n src: \"transactionCheckStateMachine\",\n // The scan descriptor must hash the exact message the device\n // reviews, i.e. the original bytes (blockhash included).\n input: ({ context }) => ({\n appConfig: context._internalState.appConfig!,\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n contextModule: context.input.contextModule,\n serializedForTxCheck: context._internalState.serializedForTxCheck,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: { target: \"CheckGenericClearSignSupported\" },\n },\n },\n CheckGenericClearSignSupported: {\n always: [\n {\n target: \"GenericClearSign\",\n guard: and([\"noInternalError\", \"isGenericClearSignAvailable\"]),\n },\n { target: \"BasicClearSign\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n // Generic clear-sign child: streams + validates the descriptors (no\n // signing, no UI). `\"prepared\"` runs the generic terminal sign;\n // `\"degraded\"` falls back to legacy basic provisioning.\n GenericClearSign: {\n invoke: {\n id: \"provisionGenericClearSignStateMachine\",\n src: \"provisionGenericClearSignStateMachine\",\n input: ({ context }) => ({\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n contextModule: context.input.contextModule,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n // Fold the child's Either output into the context here (where\n // xstate types `event.output`), then branch on the context in\n // CheckGenericClearSignResult \u2014 no event cast in the guards.\n onDone: {\n target: \"CheckGenericClearSignResult\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<SignTransactionDAInternalState>({\n Right: (outcome) => ({\n ...context._internalState,\n clearSignPrepared: outcome.status === \"prepared\",\n unrecognizedProgramIds: outcome.unrecognizedProgramIds,\n staleDescriptor: outcome.staleDescriptor,\n }),\n // Left never occurs (the prepare phase has no UI), but stay\n // defensive and surface it.\n Left: (error) => ({ ...context._internalState, error }),\n }),\n }),\n },\n onError: {\n target: \"BasicClearSign\",\n actions: ({ event }) =>\n logger.info(\n \"[ClearSign] generic clear-sign threw; falling back to legacy\",\n { data: { error: String(event.error) } },\n ),\n },\n },\n },\n CheckGenericClearSignResult: {\n always: [\n // Prepared: run the generic terminal sign; report fires after.\n {\n target: \"GenericTerminalSign\",\n guard: and([\"noInternalError\", \"isClearSignPrepared\"]),\n },\n // Degraded (Right(\"degraded\")): fall back to the legacy path.\n { target: \"BasicClearSign\", guard: \"noInternalError\" },\n // Defensive: surface an unexpected Left.\n { target: \"Error\" },\n ],\n },\n // Generic terminal sign: prompt + best-effort blockhash refresh +\n // delayed sign. A user cancel / signing failure surfaces; a non-cancel\n // prompt failure resolves to `\"degraded\"` and falls back to the legacy\n // basic path.\n GenericTerminalSign: {\n invoke: {\n id: \"signGenericClearSignStateMachine\",\n src: \"signGenericClearSignStateMachine\",\n input: ({ context }) => {\n const { rpcUrl, fetchBlockhash } = resolveRefreshSource(context);\n return {\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n rpcUrl,\n fetchBlockhash,\n userInputType:\n context.input.transactionOptions?.transactionResolutionContext\n ?.userInputType,\n blockhashService: context.input.blockhashService,\n };\n },\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckGenericTerminalSignResult\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<SignTransactionDAInternalState>({\n // Right(Signature) on success; Right(\"degraded\") when the\n // prompt failed for a non-cancel reason (leave signature\n // unset so the result check falls back to legacy).\n Right: (signatureOrDegraded) =>\n signatureOrDegraded === \"degraded\"\n ? context._internalState\n : {\n ...context._internalState,\n signature: signatureOrDegraded,\n },\n // Left: the user cancelled or signing failed; surface it.\n Left: (error) => ({ ...context._internalState, error }),\n }),\n }),\n },\n },\n },\n CheckGenericTerminalSignResult: {\n always: [\n // Signed: report (isBlindSign: false) then surface result.\n { target: \"Report\", guard: \"hasSignature\" },\n // Degraded (no signature, no error): fall back to the legacy path.\n { target: \"BasicClearSign\", guard: \"noInternalError\" },\n // User cancel / signing failure: report (isBlindSign: false) then surface error.\n { target: \"Report\" },\n ],\n },\n // Legacy SPL / token provisioning child (best-effort, never signs). It\n // streams descriptors; control always proceeds to the basic terminal\n // sign.\n BasicClearSign: {\n invoke: {\n id: \"provisionBasicClearSignStateMachine\",\n src: \"provisionBasicClearSignStateMachine\",\n input: ({ context }) => ({\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n contextModule: context.input.contextModule,\n appConfig: context._internalState.appConfig!,\n rpcUrl: resolveSolanaRpcUrl(context.input),\n resolutionContext:\n context.input.transactionOptions?.transactionResolutionContext,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: { target: \"Report\" },\n onError: { target: \"Report\" },\n },\n },\n // Single report state for all paths.\n // isBlindSign is derived from context: false when a signature or error is\n // already set (clear-sign path \u2014 success or cancel), true otherwise\n // (basic/legacy path, neither has run yet).\n // Routes to: SignTransactionResultCheck (clear-sign success),\n // Error (clear-sign cancel/failure), or\n // BasicTerminalSign (basic path).\n Report: {\n invoke: {\n src: \"reportSign\",\n input: ({ context }) => {\n const sessionState = internalApi.getDeviceSessionState();\n const deviceVersion =\n sessionState.sessionStateType !==\n DeviceSessionStateType.Connected\n ? (sessionState.firmwareVersion?.os ?? null)\n : null;\n return {\n isBlindSign:\n context._internalState.signature === null &&\n context._internalState.error === null,\n messageBytes: context._internalState.messageBytes,\n unrecognizedProgramIds:\n context._internalState.unrecognizedProgramIds,\n staleDescriptor: context._internalState.staleDescriptor,\n contextModule: context.input.contextModule,\n signerAppVersion: context._internalState.appConfig!.version,\n deviceModelId: sessionState.deviceModelId,\n deviceVersion,\n loggerFactory,\n } satisfies SolanaSigningReportTaskArgs;\n },\n onDone: [\n {\n target: \"SignTransactionResultCheck\",\n guard: \"hasSignature\",\n },\n {\n target: \"Error\",\n guard: ({ context }) => context._internalState.error !== null,\n },\n { target: \"BasicTerminalSign\" },\n ],\n onError: [\n {\n target: \"SignTransactionResultCheck\",\n guard: \"hasSignature\",\n },\n {\n target: \"Error\",\n guard: ({ context }) => context._internalState.error !== null,\n },\n { target: \"BasicTerminalSign\" },\n ],\n },\n },\n // Basic terminal sign: the legacy preview/one-shot path. It decides\n // delayed-vs-one-shot from the blockhash source (opt-in refresh).\n BasicTerminalSign: {\n invoke: {\n id: \"signBasicClearSignStateMachine\",\n src: \"signBasicClearSignStateMachine\",\n input: ({ context }) => {\n const { rpcUrl, fetchBlockhash } = resolveRefreshSource(context);\n return {\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n rpcUrl,\n fetchBlockhash,\n userInputType:\n context.input.transactionOptions?.transactionResolutionContext\n ?.userInputType,\n blockhashService: context.input.blockhashService,\n };\n },\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"SignTransactionResultCheck\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<SignTransactionDAInternalState>({\n Right: (signature) => ({\n ...context._internalState,\n signature,\n }),\n Left: (error) => ({ ...context._internalState, error }),\n }),\n }),\n },\n },\n },\n SignTransactionResultCheck: {\n always: [\n { guard: \"noInternalError\", target: \"Success\" },\n { target: \"Error\" },\n ],\n },\n Success: { type: \"final\" },\n Error: { type: \"final\" },\n },\n output: ({ context }) =>\n context._internalState.signature\n ? Right(context._internalState.signature)\n : Left(\n context._internalState.error ||\n new UnknownDAError(`No error or signature available`),\n ),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const normalizeTransaction = async () => {\n try {\n return new TransactionInputNormaliser().normalize(\n this.input.transaction,\n );\n } catch (error) {\n this.getLoggerFactory(internalApi)(\"NormalizeTransaction\").warn(\n \"[normalizeTransaction] format detection failed; treating input as message bytes\",\n { data: { error: String(error) } },\n );\n return {\n messageBytes: this.input.transaction,\n serializedForTxCheck: undefined,\n };\n }\n };\n\n const getAppConfig = async () =>\n internalApi.sendCommand(new GetAppConfigurationCommand());\n\n const reportSign = async (arg0: { input: SolanaSigningReportTaskArgs }) =>\n new SolanaSigningReportTask(arg0.input).run();\n\n return {\n normalizeTransaction,\n getAppConfig,\n reportSign,\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAWO,2CACPC,EAA4B,qBAC5BC,EAAgD,kBAEhDC,EAOO,4DAEPC,EAA2C,mEAE3CC,EAAyB,0CACzBC,EAGO,oEACPC,EAGO,0DACPC,EAGO,6DAEPC,EAAoD,iDACpDC,EAAsD,mDACtDC,EAAsD,mDACtDC,EAA+C,4CAC/CC,EAAiD,8CAMjD,SAASC,EACPC,EACoB,CACpB,OAAOA,EAAM,oBAAoB,cAAgBA,EAAM,YACzD,CAYO,MAAMjB,UAAoC,oBAM/C,CACA,iBACEkB,EAOA,CASA,KAAM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M,cAC7B,qBAAsBA,EAAQ,eAAe,oBAC/C,GACA,WAAY,CACV,WAAS,UAAO,CACd,kBAAmB,CAAC,CAAE,MAAAK,CAAM,IAC1BA,EAAM,SAAS,QAAQ,iBAC3B,CAAC,CACH,
|
|
6
|
-
"names": ["SignTransactionDeviceAction_exports", "__export", "SignTransactionDeviceAction", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_xstate", "import_SignTransactionDeviceActionTypes", "import_GetAppConfigurationCommand", "import_constants", "import_TransactionInputNormaliser", "import_SolanaApplicationResolver", "import_SolanaSigningReportTask", "import_ProvisionBasicClearSignDeviceAction", "import_ProvisionGenericClearSignDeviceAction", "import_ProvisionTransactionCheckDeviceAction", "import_SignBasicClearSignDeviceAction", "import_SignGenericClearSignDeviceAction", "resolveSolanaRpcUrl", "input", "internalApi", "normalizeTransaction", "getAppConfig", "reportSign", "loggerFactory", "logger", "disabledFeaturesSet", "isSupported", "feature", "appConfig", "resolveRefreshSource", "context", "rpcUrl", "fetchBlockhash", "refreshBlockhash", "_", "event", "error", "outcome", "signatureOrDegraded", "sessionState", "deviceVersion", "signature", "arg0"]
|
|
4
|
+
"sourcesContent": ["import {\n type CommandResult,\n type DeviceActionStateMachine,\n DeviceSessionStateType,\n type InternalApi,\n isSuccessCommandResult,\n OpenAppDeviceAction,\n type StateMachineTypes,\n UnknownDAError,\n UserInteractionRequired,\n XStateDeviceAction,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { and, assign, fromPromise, setup } from \"xstate\";\n\nimport {\n type SignTransactionDAError,\n type SignTransactionDAInput,\n type SignTransactionDAIntermediateValue,\n type SignTransactionDAInternalState,\n type SignTransactionDAOutput,\n signTransactionDAStateSteps,\n} from \"@api/app-binder/SignTransactionDeviceActionTypes\";\nimport { type AppConfiguration } from \"@api/model/AppConfiguration\";\nimport { GetAppConfigurationCommand } from \"@internal/app-binder/command/GetAppConfigurationCommand\";\nimport { type SolanaAppErrorCodes } from \"@internal/app-binder/command/utils/SolanaApplicationErrors\";\nimport { APP_NAME } from \"@internal/app-binder/constants\";\nimport {\n type NormalizedTransactionInput,\n TransactionInputNormaliser,\n} from \"@internal/app-binder/services/TransactionInputNormaliser\";\nimport {\n isSolanaSignerFeatureSupported,\n type SolanaSignerFeaturesNames,\n} from \"@internal/app-binder/SolanaApplicationResolver\";\nimport {\n SolanaSigningReportTask,\n type SolanaSigningReportTaskArgs,\n} from \"@internal/app-binder/task/SolanaSigningReportTask\";\n\nimport { ProvisionBasicClearSignDeviceAction } from \"./ProvisionBasicClearSignDeviceAction\";\nimport { ProvisionGenericClearSignDeviceAction } from \"./ProvisionGenericClearSignDeviceAction\";\nimport { ProvisionTransactionCheckDeviceAction } from \"./ProvisionTransactionCheckDeviceAction\";\nimport { SignBasicClearSignDeviceAction } from \"./SignBasicClearSignDeviceAction\";\nimport { SignGenericClearSignDeviceAction } from \"./SignGenericClearSignDeviceAction\";\n\n/**\n * Per-sign `transactionOptions.solanaRPCURL` overrides the builder default\n * (`input.solanaRPCURL`) for inspection and delayed signing.\n */\nfunction resolveSolanaRpcUrl(\n input: SignTransactionDAInput,\n): string | undefined {\n return input.transactionOptions?.solanaRPCURL ?? input.solanaRPCURL;\n}\n\nexport type MachineDependencies = {\n readonly normalizeTransaction: () => Promise<NormalizedTransactionInput>;\n readonly getAppConfig: () => Promise<\n CommandResult<AppConfiguration, SolanaAppErrorCodes>\n >;\n readonly reportSign: (arg0: {\n input: SolanaSigningReportTaskArgs;\n }) => Promise<void>;\n};\n\nexport class SignTransactionDeviceAction extends XStateDeviceAction<\n SignTransactionDAOutput,\n SignTransactionDAInput,\n SignTransactionDAError,\n SignTransactionDAIntermediateValue,\n SignTransactionDAInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n SignTransactionDAOutput,\n SignTransactionDAInput,\n SignTransactionDAError,\n SignTransactionDAIntermediateValue,\n SignTransactionDAInternalState\n > {\n type types = StateMachineTypes<\n SignTransactionDAOutput,\n SignTransactionDAInput,\n SignTransactionDAError,\n SignTransactionDAIntermediateValue,\n SignTransactionDAInternalState\n >;\n\n const { normalizeTransaction, getAppConfig, reportSign } =\n this.extractDependencies(internalApi);\n\n const loggerFactory = this.getLoggerFactory(internalApi);\n const logger = loggerFactory(\"SignTransactionDeviceAction\");\n\n const disabledFeaturesSet:\n | ReadonlySet<SolanaSignerFeaturesNames>\n | undefined = this.input.disabledFeatures\n ? new Set(this.input.disabledFeatures)\n : undefined;\n\n const isSupported = (\n feature: SolanaSignerFeaturesNames,\n appConfig: AppConfiguration,\n ): boolean =>\n isSolanaSignerFeatureSupported(\n internalApi,\n feature,\n appConfig,\n disabledFeaturesSet,\n );\n\n // Blockhash refresh is opt-in and shared by both terminal-sign machines:\n // only when `delayed: true` is requested, a blockhash source exists, and\n // the app supports delayed signing. When it isn't allowed we withhold the\n // source so the signing machine signs the original transaction.\n //\n // Template-based swaps (LiFi, etc.) always sign with the original blockhash:\n // CAL-provided e016 descriptors are computed for the original transaction, so\n // refreshing the blockhash would invalidate them and make the Exchange app\n // reject the sign with a descriptor-mismatch error.\n const resolveRefreshSource = (\n context: types[\"context\"],\n ): {\n rpcUrl: string | undefined;\n fetchBlockhash: (() => Promise<Uint8Array>) | undefined;\n } => {\n const rpcUrl = resolveSolanaRpcUrl(context.input);\n const fetchBlockhash = context.input.transactionOptions?.fetchBlockhash;\n const isTemplateSwap =\n !!context.input.transactionOptions?.transactionResolutionContext\n ?.templateId;\n const refreshBlockhash =\n !isTemplateSwap &&\n context.input.transactionOptions?.delayed === true &&\n !!(rpcUrl || fetchBlockhash) &&\n isSupported(\"delayedSigning\", context._internalState.appConfig!);\n return {\n rpcUrl: refreshBlockhash ? rpcUrl : undefined,\n fetchBlockhash: refreshBlockhash ? fetchBlockhash : undefined,\n };\n };\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n normalizeTransaction: fromPromise(normalizeTransaction),\n reportSign: fromPromise(reportSign),\n openAppStateMachine: new OpenAppDeviceAction({\n input: { appName: APP_NAME },\n }).makeStateMachine(internalApi),\n getAppConfig: fromPromise(getAppConfig),\n transactionCheckStateMachine: new ProvisionTransactionCheckDeviceAction(\n {\n input: {\n derivationPath: this.input.derivationPath,\n transaction: this.input.transaction,\n contextModule: this.input.contextModule,\n },\n loggerFactory: this.getLoggerFactory(internalApi),\n },\n ).makeStateMachine(internalApi),\n provisionGenericClearSignStateMachine:\n new ProvisionGenericClearSignDeviceAction({\n input: {\n derivationPath: this.input.derivationPath,\n transaction: this.input.transaction,\n contextModule: this.input.contextModule,\n },\n loggerFactory: this.getLoggerFactory(internalApi),\n }).makeStateMachine(internalApi),\n provisionBasicClearSignStateMachine:\n new ProvisionBasicClearSignDeviceAction({\n // `appConfig` is unknown at construction; it is supplied at invoke\n // time (see the BasicClearSign state input below).\n input: {\n derivationPath: this.input.derivationPath,\n transaction: this.input.transaction,\n contextModule: this.input.contextModule,\n },\n loggerFactory: this.getLoggerFactory(internalApi),\n }).makeStateMachine(internalApi),\n signGenericClearSignStateMachine: new SignGenericClearSignDeviceAction({\n input: {\n derivationPath: this.input.derivationPath,\n transaction: this.input.transaction,\n },\n loggerFactory: this.getLoggerFactory(internalApi),\n }).makeStateMachine(internalApi),\n signBasicClearSignStateMachine: new SignBasicClearSignDeviceAction({\n input: {\n derivationPath: this.input.derivationPath,\n transaction: this.input.transaction,\n },\n loggerFactory: this.getLoggerFactory(internalApi),\n }).makeStateMachine(internalApi),\n },\n guards: {\n noInternalError: ({ context }) => context._internalState.error === null,\n skipOpenApp: ({ context }) =>\n context.input.transactionOptions?.skipOpenApp || false,\n isTransactionChecksSupported: ({ context }) =>\n isSupported(\"transactionChecks\", context._internalState.appConfig!),\n // Generic clear-signing terminates via SIGN MESSAGE DELAYED (0x09) on\n // the original message, so it only needs the capability bit \u2014 no RPC /\n // blockhash prerequisite.\n isGenericClearSignAvailable: ({ context }) =>\n isSupported(\"genericClearSign\", context._internalState.appConfig!),\n // Generic clear-sign child streamed + finalized the descriptors (its\n // Right(\"prepared\") outcome was folded into the context by the\n // GenericClearSign onDone).\n isClearSignPrepared: ({ context }) =>\n context._internalState.clearSignPrepared,\n hasSignature: ({ context }) =>\n context._internalState.signature !== null,\n },\n actions: {\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new UnknownDAError(\n _.event[\"error\"] instanceof Error\n ? _.event[\"error\"].message\n : String(_.event[\"error\"]),\n ),\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QGUCWUB2AVATgQw1jwGMAXVAewwBEwA3VYsAQTMowDoBJDVcvADbJSeUmADEAbQAMAXUSgADhVh92CkAA9EARgDsAZg4AOAJzSAbAYAsOgKymdN08YA0IAJ67LxjnbvWxjoW-kGGxgC+Ee5omLgERGxUtAxMrORU3Lz8QiJiUjrySCDKqhkYGtoI+kZmljb2js5unojmRgbS1haG0o5OllEx6Nj4hCTlKYwsSZwA8opgGMyKilNps+IQVGAcqBh0FADWuxSLy6vComAAsiQAFvtgMkVKKmpUlYh6dgBMHL8bJ0LKY7AZOr87O4vAhjHpTCZfkEDHo+nprL8ekMQLFRgkJux1jNyhwFksVooAEpwACuAlIAGF7mBiEcpHINKUPhVilUdL9gn5TCjfr9rNJ+X8WjDzAi9AKDGLwb94RZrNjcfFxrMiel2KTzhTqbA6YzmayCq8Su9yl9qgKLEKRWKJZCkdDEEE-NIffLAX8LPUNSMtYlJvRpnrMgBxMCkCkMqgAM3QWx2ewOx12MHjq0TGBTUBenJt6l5uj9JmsBjhxjhdn0pg91S61gB1kCPT0aosxiRwbiYzDhIjGxJsdzinzhfEYBwOAoOA4igEoiTi4Athwcwnk+hi8Uubby9VK8Zq7X643m78fRwfT7+fCxQ2B3jteHUsT9RPdwX0MappMiybIHm8ZRlqAVQCuYHAWJClj8qYSpQq0LZ6HoHA2D2PpwuCphvqGBLJKO34xnGf6FoB9LARaki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osBvEkIUUvABQTsqYWkBhdENhzxql+DxUEcFqyr26Bibs3cz7vjRlJDG+p44pIwEpHy1N-6aSqCEQUQIGbymMOCMEBVgZgjVNEkELNuixyGURa2ViOATJGdM2KatyGVzGosx0yyehInWQYehCJtkdkZn8YO0Soh2QwBQCAcANDnIls5OpI06ZVAALQWGbLC+8D4kXIrVBY0ZV9OA8DUDki6cz-pVAxM2HQlg2I1hmtIES61Bn2WSSMyWJIyQXDWOCzSkLNZ2EdICasAs-imIMKCAq-g-ABHgv0Wwok0X0v1Iyo0tIaKxTxVC7wFL7z2EEsEUWcNuzQwlMKjewozDNJ0JKll5FJzTnQIqu0OhxSYQbKLLogJ4agleWhYlxKTB1iaYZDsARDk0uGWCsZZrKIATlcpVkVqTw6GFP7FmoIBQrTWToIllg+LmRtaiTmqJlQmuDZwfaMUQJHR4FGsaYonAg1yhCBs2VGapv5feFm-K4lOA3nmjFdUDrFu+uGstAMDJmA4MS8GQRRSKnMgVbKZl4Z9H5KKJEgQO2nOlgQzxH8lYU0gP2qoUc+JjvZhKZC8E4VoX6Iw5EfY4nVmNUkwNJy0n21TvYzAO7EA1jWdQn4GEzD6HlAVOEJgwS3lwvG9hd7jlINqjYyRdiZGvpuYEglok+Iit3lYfoKa0ImzMsBroyF9BxOXWkjJPVslCBGG+hA-gGz3lncLMUBlXUwnhm2Qx0SNrBHMtS0FD7oO90mZckCVH4J-DMgKeUIQwHswKvoLCeyJQbXgvKYj0GaTECYLAeAiG6kLPlJhTEgR5QNxVMxz0oo-AM26PBYI-KzGqZcgAUTajgET+mAQ7OMwKUzzYlqYXDhytZ6q8Lqj+UAA */\n id: \"SignTransactionDeviceAction\",\n initial: \"NormalizeTransaction\",\n context: ({ input }) => ({\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.OPEN_APP,\n },\n _internalState: {\n error: null,\n signature: null,\n appConfig: null,\n messageBytes: this.input.transaction,\n serializedForTxCheck: undefined,\n clearSignPrepared: false,\n unrecognizedProgramIds: [],\n staleDescriptor: false,\n },\n }),\n states: {\n NormalizeTransaction: {\n // Emit the correct first step immediately so the snapshot produced\n // while the actor runs already reflects where we are headed.\n entry: assign({\n intermediateValue: ({ context }) => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: context.input.transactionOptions?.skipOpenApp\n ? signTransactionDAStateSteps.GET_APP_CONFIG\n : signTransactionDAStateSteps.OPEN_APP,\n }),\n }),\n invoke: {\n id: \"normalizeTransaction\",\n src: \"normalizeTransaction\",\n onDone: [\n {\n target: \"GetAppConfig\",\n guard: \"skipOpenApp\",\n actions: assign({\n _internalState: ({ event, context }) => ({\n ...context._internalState,\n messageBytes: event.output.messageBytes,\n serializedForTxCheck: event.output.serializedForTxCheck,\n }),\n }),\n },\n {\n target: \"OpenAppDeviceAction\",\n actions: assign({\n _internalState: ({ event, context }) => ({\n ...context._internalState,\n messageBytes: event.output.messageBytes,\n serializedForTxCheck: event.output.serializedForTxCheck,\n }),\n }),\n },\n ],\n },\n },\n OpenAppDeviceAction: {\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.OPEN_APP,\n }),\n }),\n invoke: {\n id: \"openAppStateMachine\",\n src: \"openAppStateMachine\",\n input: () => ({ appName: APP_NAME }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) => ({\n ...event.snapshot.context.intermediateValue,\n step: signTransactionDAStateSteps.OPEN_APP,\n }),\n }),\n },\n onDone: {\n target: \"OpenAppResultCheck\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf({\n Right: () => context._internalState,\n Left: (error) => ({\n ...context._internalState,\n error,\n }),\n }),\n }),\n },\n },\n },\n OpenAppResultCheck: {\n always: [\n { target: \"GetAppConfig\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n GetAppConfig: {\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: signTransactionDAStateSteps.GET_APP_CONFIG,\n }),\n }),\n invoke: {\n id: \"getAppConfig\",\n src: \"getAppConfig\",\n onDone: {\n target: \"GetAppConfigResultCheck\",\n actions: assign({\n _internalState: ({ event, context }) =>\n isSuccessCommandResult(event.output)\n ? {\n ...context._internalState,\n appConfig: event.output.data,\n }\n : { ...context._internalState, error: event.output.error },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetAppConfigResultCheck: {\n always: [\n {\n target: \"CheckTransactionCheckSupported\",\n guard: \"noInternalError\",\n },\n { target: \"Error\" },\n ],\n },\n CheckTransactionCheckSupported: {\n always: [\n // Feature supported: delegate opt-in + provide to the child machine.\n {\n target: \"TxCheck\",\n guard: \"isTransactionChecksSupported\",\n },\n // Feature not supported: skip the child machine entirely.\n { target: \"CheckGenericClearSignSupported\" },\n ],\n },\n // Web3-checks child machine: handles opt-in prompt and scan-descriptor\n // provisioning. Only reached when the feature is supported; opt-in and\n // provide decisions are made internally.\n TxCheck: {\n invoke: {\n id: \"transactionCheckStateMachine\",\n src: \"transactionCheckStateMachine\",\n // The scan descriptor must hash the exact message the device\n // reviews, i.e. the original bytes (blockhash included).\n input: ({ context }) => ({\n appConfig: context._internalState.appConfig!,\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n contextModule: context.input.contextModule,\n serializedForTxCheck: context._internalState.serializedForTxCheck,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n // The opt-in has now been answered (or skipped): record the outcome\n // so the re-provision after a generic fallback never prompts again.\n onDone: {\n target: \"CheckGenericClearSignSupported\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<SignTransactionDAInternalState>({\n Right: ({ transactionChecksEnabled }) => ({\n ...context._internalState,\n appConfig: {\n ...context._internalState.appConfig!,\n transactionChecksEnabled,\n transactionChecksOptIn: true,\n },\n }),\n Left: () => context._internalState,\n }),\n }),\n },\n },\n },\n CheckGenericClearSignSupported: {\n always: [\n {\n target: \"GenericClearSign\",\n guard: and([\"noInternalError\", \"isGenericClearSignAvailable\"]),\n },\n { target: \"BasicClearSign\", guard: \"noInternalError\" },\n { target: \"Error\" },\n ],\n },\n // Generic clear-sign child: streams + validates the descriptors (no\n // signing, no UI). `\"prepared\"` runs the generic terminal sign;\n // `\"degraded\"` falls back to legacy basic provisioning.\n GenericClearSign: {\n invoke: {\n id: \"provisionGenericClearSignStateMachine\",\n src: \"provisionGenericClearSignStateMachine\",\n input: ({ context }) => ({\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n contextModule: context.input.contextModule,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n // Fold the child's Either output into the context here (where\n // xstate types `event.output`), then branch on the context in\n // CheckGenericClearSignResult \u2014 no event cast in the guards.\n onDone: {\n target: \"CheckGenericClearSignResult\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<SignTransactionDAInternalState>({\n Right: (outcome) => ({\n ...context._internalState,\n clearSignPrepared: outcome.status === \"prepared\",\n unrecognizedProgramIds: outcome.unrecognizedProgramIds,\n staleDescriptor: outcome.staleDescriptor,\n }),\n // Left never occurs (the prepare phase has no UI), but stay\n // defensive and surface it.\n Left: (error) => ({ ...context._internalState, error }),\n }),\n }),\n },\n onError: {\n target: \"CheckTxCheckReprovision\",\n actions: ({ event }) =>\n logger.info(\n \"[ClearSign] generic clear-sign threw; falling back to legacy\",\n { data: { error: String(event.error) } },\n ),\n },\n },\n },\n CheckGenericClearSignResult: {\n always: [\n // Prepared: run the generic terminal sign; report fires after.\n {\n target: \"GenericTerminalSign\",\n guard: and([\"noInternalError\", \"isClearSignPrepared\"]),\n },\n // Degraded (Right(\"degraded\")): fall back to the legacy path.\n { target: \"CheckTxCheckReprovision\", guard: \"noInternalError\" },\n // Defensive: surface an unexpected Left.\n { target: \"Error\" },\n ],\n },\n // Generic terminal sign: prompt + best-effort blockhash refresh +\n // delayed sign. A user cancel / signing failure surfaces; a non-cancel\n // prompt failure resolves to `\"degraded\"` and falls back to the legacy\n // basic path.\n GenericTerminalSign: {\n invoke: {\n id: \"signGenericClearSignStateMachine\",\n src: \"signGenericClearSignStateMachine\",\n input: ({ context }) => {\n const { rpcUrl, fetchBlockhash } = resolveRefreshSource(context);\n return {\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n rpcUrl,\n fetchBlockhash,\n userInputType:\n context.input.transactionOptions?.transactionResolutionContext\n ?.userInputType,\n blockhashService: context.input.blockhashService,\n };\n },\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckGenericTerminalSignResult\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<SignTransactionDAInternalState>({\n // Right(Signature) on success; Right(\"degraded\") when the\n // prompt failed for a non-cancel reason (leave signature\n // unset so the result check falls back to legacy).\n Right: (signatureOrDegraded) =>\n signatureOrDegraded === \"degraded\"\n ? context._internalState\n : {\n ...context._internalState,\n signature: signatureOrDegraded,\n },\n // Left: the user cancelled or signing failed; surface it.\n Left: (error) => ({ ...context._internalState, error }),\n }),\n }),\n },\n },\n },\n CheckGenericTerminalSignResult: {\n always: [\n // Signed: report (isBlindSign: false) then surface result.\n { target: \"Report\", guard: \"hasSignature\" },\n // Degraded (no signature, no error): fall back to the legacy path.\n { target: \"CheckTxCheckReprovision\", guard: \"noInternalError\" },\n // User cancel / signing failure: report (isBlindSign: false) then surface error.\n { target: \"Report\" },\n ],\n },\n // A failed generic clear-sign attempt wipes the device's provisioned\n // context, including the tx-check descriptor sent in TxCheck. Provide\n // it again before falling back to the basic path. The opt-in was\n // already answered in TxCheck, so this pass never prompts.\n CheckTxCheckReprovision: {\n always: [\n {\n target: \"TxCheckReprovision\",\n guard: \"isTransactionChecksSupported\",\n },\n { target: \"BasicClearSign\" },\n ],\n },\n TxCheckReprovision: {\n invoke: {\n id: \"transactionCheckReprovisionStateMachine\",\n src: \"transactionCheckStateMachine\",\n input: ({ context }) => ({\n appConfig: context._internalState.appConfig!,\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n contextModule: context.input.contextModule,\n serializedForTxCheck: context._internalState.serializedForTxCheck,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: { target: \"BasicClearSign\" },\n },\n },\n // Legacy SPL / token provisioning child (best-effort, never signs). It\n // streams descriptors; control always proceeds to the basic terminal\n // sign.\n BasicClearSign: {\n invoke: {\n id: \"provisionBasicClearSignStateMachine\",\n src: \"provisionBasicClearSignStateMachine\",\n input: ({ context }) => ({\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n contextModule: context.input.contextModule,\n appConfig: context._internalState.appConfig!,\n rpcUrl: resolveSolanaRpcUrl(context.input),\n resolutionContext:\n context.input.transactionOptions?.transactionResolutionContext,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: { target: \"Report\" },\n onError: { target: \"Report\" },\n },\n },\n // Single report state for all paths.\n // isBlindSign is derived from context: false when a signature or error is\n // already set (clear-sign path \u2014 success or cancel), true otherwise\n // (basic/legacy path, neither has run yet).\n // Routes to: SignTransactionResultCheck (clear-sign success),\n // Error (clear-sign cancel/failure), or\n // BasicTerminalSign (basic path).\n Report: {\n invoke: {\n src: \"reportSign\",\n input: ({ context }) => {\n const sessionState = internalApi.getDeviceSessionState();\n const deviceVersion =\n sessionState.sessionStateType !==\n DeviceSessionStateType.Connected\n ? (sessionState.firmwareVersion?.os ?? null)\n : null;\n return {\n isBlindSign:\n context._internalState.signature === null &&\n context._internalState.error === null,\n messageBytes: context._internalState.messageBytes,\n unrecognizedProgramIds:\n context._internalState.unrecognizedProgramIds,\n staleDescriptor: context._internalState.staleDescriptor,\n contextModule: context.input.contextModule,\n signerAppVersion: context._internalState.appConfig!.version,\n deviceModelId: sessionState.deviceModelId,\n deviceVersion,\n loggerFactory,\n } satisfies SolanaSigningReportTaskArgs;\n },\n onDone: [\n {\n target: \"SignTransactionResultCheck\",\n guard: \"hasSignature\",\n },\n {\n target: \"Error\",\n guard: ({ context }) => context._internalState.error !== null,\n },\n { target: \"BasicTerminalSign\" },\n ],\n onError: [\n {\n target: \"SignTransactionResultCheck\",\n guard: \"hasSignature\",\n },\n {\n target: \"Error\",\n guard: ({ context }) => context._internalState.error !== null,\n },\n { target: \"BasicTerminalSign\" },\n ],\n },\n },\n // Basic terminal sign: the legacy preview/one-shot path. It decides\n // delayed-vs-one-shot from the blockhash source (opt-in refresh).\n BasicTerminalSign: {\n invoke: {\n id: \"signBasicClearSignStateMachine\",\n src: \"signBasicClearSignStateMachine\",\n input: ({ context }) => {\n const { rpcUrl, fetchBlockhash } = resolveRefreshSource(context);\n return {\n derivationPath: context.input.derivationPath,\n transaction: context._internalState.messageBytes,\n rpcUrl,\n fetchBlockhash,\n userInputType:\n context.input.transactionOptions?.transactionResolutionContext\n ?.userInputType,\n blockhashService: context.input.blockhashService,\n };\n },\n onSnapshot: {\n actions: assign({\n intermediateValue: ({ event }) =>\n event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"SignTransactionResultCheck\",\n actions: assign({\n _internalState: ({ event, context }) =>\n event.output.caseOf<SignTransactionDAInternalState>({\n Right: (signature) => ({\n ...context._internalState,\n signature,\n }),\n Left: (error) => ({ ...context._internalState, error }),\n }),\n }),\n },\n },\n },\n SignTransactionResultCheck: {\n always: [\n { guard: \"noInternalError\", target: \"Success\" },\n { target: \"Error\" },\n ],\n },\n Success: { type: \"final\" },\n Error: { type: \"final\" },\n },\n output: ({ context }) =>\n context._internalState.signature\n ? Right(context._internalState.signature)\n : Left(\n context._internalState.error ||\n new UnknownDAError(`No error or signature available`),\n ),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const normalizeTransaction = async () => {\n try {\n return new TransactionInputNormaliser().normalize(\n this.input.transaction,\n );\n } catch (error) {\n this.getLoggerFactory(internalApi)(\"NormalizeTransaction\").warn(\n \"[normalizeTransaction] format detection failed; treating input as message bytes\",\n { data: { error: String(error) } },\n );\n return {\n messageBytes: this.input.transaction,\n serializedForTxCheck: undefined,\n };\n }\n };\n\n const getAppConfig = async () =>\n internalApi.sendCommand(new GetAppConfigurationCommand());\n\n const reportSign = async (arg0: { input: SolanaSigningReportTaskArgs }) =>\n new SolanaSigningReportTask(arg0.input).run();\n\n return {\n normalizeTransaction,\n getAppConfig,\n reportSign,\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAWO,2CACPC,EAA4B,qBAC5BC,EAAgD,kBAEhDC,EAOO,4DAEPC,EAA2C,mEAE3CC,EAAyB,0CACzBC,EAGO,oEACPC,EAGO,0DACPC,EAGO,6DAEPC,EAAoD,iDACpDC,EAAsD,mDACtDC,EAAsD,mDACtDC,EAA+C,4CAC/CC,EAAiD,8CAMjD,SAASC,EACPC,EACoB,CACpB,OAAOA,EAAM,oBAAoB,cAAgBA,EAAM,YACzD,CAYO,MAAMjB,UAAoC,oBAM/C,CACA,iBACEkB,EAOA,CASA,KAAM,CAAE,qBAAAC,EAAsB,aAAAC,EAAc,WAAAC,CAAW,EACrD,KAAK,oBAAoBH,CAAW,EAEhCI,EAAgB,KAAK,iBAAiBJ,CAAW,EACjDK,EAASD,EAAc,6BAA6B,EAEpDE,EAEU,KAAK,MAAM,iBACvB,IAAI,IAAI,KAAK,MAAM,gBAAgB,EACnC,OAEEC,EAAc,CAClBC,EACAC,OAEA,kCACET,EACAQ,EACAC,EACAH,CACF,EAWII,EACJC,GAIG,CACH,MAAMC,EAASd,EAAoBa,EAAQ,KAAK,EAC1CE,EAAiBF,EAAQ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A,EAAQ,eAAe,OACrB,IAAI,iBAAe,iCAAiC,CACxD,CACR,CAAC,CACH,CAEA,oBAAoBX,EAA+C,CAwBjE,MAAO,CACL,qBAxB2B,SAAY,CACvC,GAAI,CACF,OAAO,IAAI,6BAA2B,EAAE,UACtC,KAAK,MAAM,WACb,CACF,OAASiB,EAAO,CACd,YAAK,iBAAiBjB,CAAW,EAAE,sBAAsB,EAAE,KACzD,kFACA,CAAE,KAAM,CAAE,MAAO,OAAOiB,CAAK,CAAE,CAAE,CACnC,EACO,CACL,aAAc,KAAK,MAAM,YACzB,qBAAsB,MACxB,CACF,CACF,EAUE,aARmB,SACnBjB,EAAY,YAAY,IAAI,4BAA4B,EAQxD,WANiB,MAAOwB,GACxB,IAAI,0BAAwBA,EAAK,KAAK,EAAE,IAAI,CAM9C,CACF,CACF",
|
|
6
|
+
"names": ["SignTransactionDeviceAction_exports", "__export", "SignTransactionDeviceAction", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_xstate", "import_SignTransactionDeviceActionTypes", "import_GetAppConfigurationCommand", "import_constants", "import_TransactionInputNormaliser", "import_SolanaApplicationResolver", "import_SolanaSigningReportTask", "import_ProvisionBasicClearSignDeviceAction", "import_ProvisionGenericClearSignDeviceAction", "import_ProvisionTransactionCheckDeviceAction", "import_SignBasicClearSignDeviceAction", "import_SignGenericClearSignDeviceAction", "resolveSolanaRpcUrl", "input", "internalApi", "normalizeTransaction", "getAppConfig", "reportSign", "loggerFactory", "logger", "disabledFeaturesSet", "isSupported", "feature", "appConfig", "resolveRefreshSource", "context", "rpcUrl", "fetchBlockhash", "refreshBlockhash", "_", "event", "error", "transactionChecksEnabled", "outcome", "signatureOrDegraded", "sessionState", "deviceVersion", "signature", "arg0"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var a=require("@ledgerhq/device-management-kit"),I=require("purify-ts"),e=require("vitest"),k=require("../../../api/app-binder/SignClearSignDeviceActionTypes"),m=require("../../../api/app-binder/SignTransactionDeviceActionTypes"),b=require("../../../api/model/PublicKeyDisplayMode"),D=require("../../app-binder/command/utils/SolanaApplicationErrors"),O=require("../../app-binder/services/TransactionInspector"),r=require("../../app-binder/SolanaApplicationResolver"),H=require("./__test-utils__/makeInternalApi"),N=require("./ProvisionBasicClearSignDeviceAction"),w=require("./ProvisionGenericClearSignDeviceAction"),M=require("./ProvisionTransactionCheckDeviceAction"),G=require("./SignBasicClearSignDeviceAction"),L=require("./SignGenericClearSignDeviceAction"),U=require("./SignTransactionDeviceAction");const ee="44'/501'/0'/0'",z=new Uint8Array([222,173,190,239]),V=new Uint8Array([170,187]),E=new Uint8Array([119,136]),_="1.15.5",ne={getContexts:e.vi.fn()};let l,c,p,q,F,y,K,X,v,h,A,g,C,S,Y,W,J,Z,Q,$;function d(i){return{blindSigningEnabled:!0,pubKeyDisplayMode:b.PublicKeyDisplayMode.LONG,version:i,transactionChecksEnabled:!1,transactionChecksOptIn:!1}}function u(i,t=a.DeviceModelId.NANO_X){return{sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Solana",version:i},deviceModelId:t,isSecureConnectionAllowed:!0}}function te(){W=e.vi.spyOn(w.ProvisionGenericClearSignDeviceAction.prototype,"extractDependencies").mockReturnValue({buildGenericClearSignContext:p,provideGenericClearSignContext:q,finalizeGenericClearSign:F}),J=e.vi.spyOn(N.ProvisionBasicClearSignDeviceAction.prototype,"extractDependencies").mockReturnValue({inspectTransaction:y,buildBasicClearSignContext:K,provideBasicClearSignContext:X}),Z=e.vi.spyOn(M.ProvisionTransactionCheckDeviceAction.prototype,"extractDependencies").mockReturnValue({transactionCheckOptIn:e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:{enabled:!0}})),provideTransactionCheck:e.vi.fn().mockResolvedValue(void 0)}),Q=e.vi.spyOn(L.SignGenericClearSignDeviceAction.prototype,"extractDependencies").mockReturnValue({promptUiDisplay:h,refreshBlockhash:S,delayedSignTransaction:g}),$=e.vi.spyOn(G.SignBasicClearSignDeviceAction.prototype,"extractDependencies").mockReturnValue({previewTransaction:A,refreshBlockhash:S,delayedSignTransaction:g,signTransaction:C})}function s(i,t,n){const o=new U.SignTransactionDeviceAction({input:i});Y=e.vi.spyOn(o,"extractDependencies").mockReturnValue({normalizeTransaction:e.vi.fn().mockResolvedValue({messageBytes:z,serializedForTxCheck:void 0}),getAppConfig:c,reportSign:v});const{observable:R}=o._execute(l),x=[];R.subscribe({next:j=>x.push(j),error:n,complete:()=>t(x)})}const f={derivationPath:ee,transaction:z,transactionOptions:{skipOpenApp:!0},contextModule:ne},B={...f,solanaRPCURL:"https://api.devnet.solana.com"},T={...B,transactionOptions:{...f.transactionOptions,delayed:!0}};function P(i){const t=[];for(const n of i){if(n.status!==a.DeviceActionStatus.Pending)continue;const o=n.intermediateValue.step;t[t.length-1]!==o&&t.push(o)}return t}(0,e.describe)("SignTransactionDeviceAction (Solana) \u2013 orchestration",()=>{(0,e.beforeEach)(()=>{l=(0,H.makeDeviceActionInternalApiMock)(),l.getDeviceSessionState.mockReturnValue(u(_)),c=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:d(_)})),p=e.vi.fn().mockResolvedValue({mode:"none",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),q=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),F=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),h=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),y=e.vi.fn().mockResolvedValue({transactionType:O.SolanaTransactionTypes.STANDARD}),K=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:{loadersResults:[],contextErrorCount:0}})),X=e.vi.fn().mockResolvedValue(void 0),A=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:I.Nothing})),S=e.vi.fn().mockImplementation(async i=>i.input.transaction),g=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:(0,I.Just)(E)})),C=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:(0,I.Just)(V)})),v=e.vi.fn().mockResolvedValue(void 0),te()}),(0,e.afterEach)(()=>{Y?.mockRestore(),W.mockRestore(),J.mockRestore(),Z.mockRestore(),Q.mockRestore(),$.mockRestore()}),(0,e.it)("generic unavailable then basic provisions then terminal one-shot sign (no RPC)",()=>new Promise((i,t)=>{s(f,n=>{try{(0,e.expect)(p).not.toHaveBeenCalled(),(0,e.expect)(y).toHaveBeenCalled(),(0,e.expect)(C).toHaveBeenCalled(),(0,e.expect)(g).not.toHaveBeenCalled();const o=n[n.length-1];(0,e.expect)(o.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(o.status===a.DeviceActionStatus.Completed&&o.output).toEqual(V),i()}catch(o){t(o)}},t)})),(0,e.it)("generic available + armed then terminal delayed sign (alreadyArmed, refreshed)",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),c.mockResolvedValue((0,a.CommandResultFactory)({data:d(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),p.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),s(T,n=>{try{(0,e.expect)(p).toHaveBeenCalled(),(0,e.expect)(h).toHaveBeenCalled(),(0,e.expect)(A).not.toHaveBeenCalled(),(0,e.expect)(S).toHaveBeenCalled(),(0,e.expect)(S.mock.calls[0][0].input.rpcUrl).toBeDefined(),(0,e.expect)(g).toHaveBeenCalled(),(0,e.expect)(y).not.toHaveBeenCalled();const o=n[n.length-1];(0,e.expect)(o.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(o.status===a.DeviceActionStatus.Completed&&o.output).toEqual(E),i()}catch(o){t(o)}},t)})),(0,e.it)("generic available + armed, RPC but no delayed then delayed sign on original (no refresh)",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),c.mockResolvedValue((0,a.CommandResultFactory)({data:d(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),p.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),s(B,n=>{try{(0,e.expect)(h).toHaveBeenCalled(),(0,e.expect)(A).not.toHaveBeenCalled(),(0,e.expect)(S.mock.calls[0][0].input.rpcUrl).toBeUndefined(),(0,e.expect)(g).toHaveBeenCalled(),(0,e.expect)(C).not.toHaveBeenCalled();const o=n[n.length-1];(0,e.expect)(o.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(o.status===a.DeviceActionStatus.Completed&&o.output).toEqual(E),i()}catch(o){t(o)}},t)})),(0,e.it)("not armed, RPC but no delayed then terminal one-shot sign (no refresh)",()=>new Promise((i,t)=>{s(B,n=>{try{(0,e.expect)(C).toHaveBeenCalled(),(0,e.expect)(A).not.toHaveBeenCalled(),(0,e.expect)(S).not.toHaveBeenCalled(),(0,e.expect)(g).not.toHaveBeenCalled();const o=n[n.length-1];(0,e.expect)(o.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(o.status===a.DeviceActionStatus.Completed&&o.output).toEqual(V),i()}catch(o){t(o)}},t)})),(0,e.it)("delayed requested + RPC but app lacks delayed-signing then one-shot sign (refresh withheld)",()=>new Promise((i,t)=>{const n="1.13.0";l.getDeviceSessionState.mockReturnValue(u(n)),c.mockResolvedValue((0,a.CommandResultFactory)({data:d(n)})),s(T,o=>{try{(0,e.expect)(C).toHaveBeenCalled(),(0,e.expect)(A).not.toHaveBeenCalled(),(0,e.expect)(S).not.toHaveBeenCalled(),(0,e.expect)(g).not.toHaveBeenCalled();const R=o[o.length-1];(0,e.expect)(R.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(R.status===a.DeviceActionStatus.Completed&&R.output).toEqual(V),i()}catch(R){t(R)}},t)})),(0,e.it)("generic degraded then basic then terminal",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),c.mockResolvedValue((0,a.CommandResultFactory)({data:d(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),s(T,n=>{try{(0,e.expect)(p).toHaveBeenCalled(),(0,e.expect)(y).toHaveBeenCalled(),(0,e.expect)(A).toHaveBeenCalled(),(0,e.expect)(g).toHaveBeenCalled(),(0,e.expect)(n[n.length-1].status).toBe(a.DeviceActionStatus.Completed),i()}catch(o){t(o)}},t)})),(0,e.it)("generic user cancel (6985) then error, no basic / no terminal",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),c.mockResolvedValue((0,a.CommandResultFactory)({data:d(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),p.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),h.mockResolvedValue((0,a.CommandResultFactory)({error:new D.SolanaAppCommandError({errorCode:"6985",message:"Canceled by user"})})),s(B,n=>{try{(0,e.expect)(y).not.toHaveBeenCalled(),(0,e.expect)(g).not.toHaveBeenCalled(),(0,e.expect)(C).not.toHaveBeenCalled(),(0,e.expect)(n[n.length-1].status).toBe(a.DeviceActionStatus.Error),i()}catch(o){t(o)}},t)})),(0,e.it)("terminal sign failure then error",()=>new Promise((i,t)=>{C.mockResolvedValue((0,a.CommandResultFactory)({error:new D.SolanaAppCommandError({errorCode:"6f01",message:"sign failed"})})),s(f,n=>{try{(0,e.expect)(C).toHaveBeenCalled(),(0,e.expect)(n[n.length-1].status).toBe(a.DeviceActionStatus.Error),i()}catch(o){t(o)}},t)})),(0,e.it)("getAppConfig error then error",()=>new Promise((i,t)=>{c.mockResolvedValue((0,a.CommandResultFactory)({error:new D.SolanaAppCommandError({errorCode:"6e00",message:"no app config"})})),s(f,n=>{try{(0,e.expect)(y).not.toHaveBeenCalled(),(0,e.expect)(n[n.length-1].status).toBe(a.DeviceActionStatus.Error),i()}catch(o){t(o)}},t)})),(0,e.it)("ProvisionTransactionCheckDeviceAction child is invoked when feature is supported",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_TRANSACTION_CHECKS_VERSION,a.DeviceModelId.FLEX)),c.mockResolvedValue((0,a.CommandResultFactory)({data:{...d(r.SOLANA_MIN_TRANSACTION_CHECKS_VERSION),transactionChecksEnabled:!0,transactionChecksOptIn:!0}})),s(f,n=>{try{const o=P(n);(0,e.expect)(o).toContain(m.signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE),(0,e.expect)(n[n.length-1].status).toBe(a.DeviceActionStatus.Completed),i()}catch(o){t(o)}},t)})),(0,e.it)("skips transaction-checks when transactionChecks is in disabledFeatures",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_TRANSACTION_CHECKS_VERSION,a.DeviceModelId.FLEX)),c.mockResolvedValue((0,a.CommandResultFactory)({data:{...d(r.SOLANA_MIN_TRANSACTION_CHECKS_VERSION),transactionChecksEnabled:!1,transactionChecksOptIn:!1}})),s({...f,disabledFeatures:["transactionChecks"]},n=>{try{const o=P(n);(0,e.expect)(o).not.toContain(m.signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN),(0,e.expect)(o).not.toContain(m.signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE),(0,e.expect)(n[n.length-1].status).toBe(a.DeviceActionStatus.Completed),i()}catch(o){t(o)}},t)})),(0,e.it)("e2e sequence: legacy SPL path with RPC then basic provisioning then delayed terminal",()=>new Promise((i,t)=>{y.mockResolvedValue({transactionType:O.SolanaTransactionTypes.SPL,data:{tokenAddress:null,createATA:!1}}),s(T,n=>{try{(0,e.expect)(P(n)).toEqual([m.signTransactionDAStateSteps.GET_APP_CONFIG,m.signTransactionDAStateSteps.INSPECT_TRANSACTION,m.signTransactionDAStateSteps.BUILD_BASIC_CLEAR_SIGN_CONTEXT,m.signTransactionDAStateSteps.PROVIDE_BASIC_CLEAR_SIGN_CONTEXT,k.signClearSignDAStateSteps.PREVIEW_TRANSACTION,k.signClearSignDAStateSteps.FETCH_BLOCKHASH,k.signClearSignDAStateSteps.DELAYED_SIGN]);const o=n[n.length-1];(0,e.expect)(o.status).toBe(a.DeviceActionStatus.Completed),i()}catch(o){t(o)}},t)})),(0,e.it)("e2e sequence: generic clear-sign armed then terminal refresh + delayed sign",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),c.mockResolvedValue((0,a.CommandResultFactory)({data:d(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),p.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),s(T,n=>{try{(0,e.expect)(P(n)).toEqual([m.signTransactionDAStateSteps.GET_APP_CONFIG,m.signTransactionDAStateSteps.BUILD_GENERIC_CLEAR_SIGN_CONTEXT,m.signTransactionDAStateSteps.PROVIDE_GENERIC_CLEAR_SIGN_CONTEXT,m.signTransactionDAStateSteps.FINALIZE_GENERIC_CLEAR_SIGN,k.signClearSignDAStateSteps.PROMPT_UI_DISPLAY,k.signClearSignDAStateSteps.FETCH_BLOCKHASH,k.signClearSignDAStateSteps.DELAYED_SIGN]);const o=n[n.length-1];(0,e.expect)(o.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(o.status===a.DeviceActionStatus.Completed&&o.output).toEqual(E),i()}catch(o){t(o)}},t)})),(0,e.describe)("Report state \u2014 isBlindSign contract",()=>{(0,e.it)("legacy path (generic gate skipped) \u2192 isBlindSign: true, reportSign called once",()=>new Promise((i,t)=>{s(f,()=>{try{(0,e.expect)(v).toHaveBeenCalledOnce();const n=v.mock.calls[0][0];(0,e.expect)(n.input.isBlindSign).toBe(!0),i()}catch(n){t(n)}},t)})),(0,e.it)("generic clear-sign success \u2192 isBlindSign: false, reportSign called once",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),c.mockResolvedValue((0,a.CommandResultFactory)({data:d(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),p.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),s(T,()=>{try{(0,e.expect)(v).toHaveBeenCalledOnce();const n=v.mock.calls[0][0];(0,e.expect)(n.input.isBlindSign).toBe(!1),i()}catch(n){t(n)}},t)})),(0,e.it)("generic cancel (6985) \u2192 isBlindSign: false, reportSign called once",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),c.mockResolvedValue((0,a.CommandResultFactory)({data:d(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),p.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),h.mockResolvedValue((0,a.CommandResultFactory)({error:new D.SolanaAppCommandError({errorCode:"6985",message:"Canceled by user"})})),s(B,()=>{try{(0,e.expect)(v).toHaveBeenCalledOnce();const n=v.mock.calls[0][0];(0,e.expect)(n.input.isBlindSign).toBe(!1),i()}catch(n){t(n)}},t)})),(0,e.it)("generic non-cancel prompt failure degrades to basic \u2192 isBlindSign: true, reportSign called once",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),c.mockResolvedValue((0,a.CommandResultFactory)({data:d(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),p.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),h.mockResolvedValue((0,a.CommandResultFactory)({error:new D.SolanaAppCommandError({errorCode:"6f01",message:"Display error"})})),s(B,()=>{try{(0,e.expect)(v).toHaveBeenCalledOnce();const n=v.mock.calls[0][0];(0,e.expect)(n.input.isBlindSign).toBe(!0),i()}catch(n){t(n)}},t)})),(0,e.it)("generic build degrades with staleDescriptor \u2192 reportSign receives staleDescriptor: true",()=>new Promise((i,t)=>{l.getDeviceSessionState.mockReturnValue(u(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),c.mockResolvedValue((0,a.CommandResultFactory)({data:d(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),p.mockResolvedValue({mode:"none",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[],staleDescriptor:!0}),s(B,()=>{try{(0,e.expect)(v).toHaveBeenCalledOnce();const n=v.mock.calls[0][0];(0,e.expect)(n.input.isBlindSign).toBe(!0),(0,e.expect)(n.input.staleDescriptor).toBe(!0),i()}catch(n){t(n)}},t)}))})});
|
|
1
|
+
"use strict";var a=require("@ledgerhq/device-management-kit"),b=require("purify-ts"),e=require("vitest"),A=require("../../../api/app-binder/SignClearSignDeviceActionTypes"),y=require("../../../api/app-binder/SignTransactionDeviceActionTypes"),N=require("../../../api/model/PublicKeyDisplayMode"),I=require("../../app-binder/command/utils/SolanaApplicationErrors"),_=require("../../app-binder/services/TransactionInspector"),r=require("../../app-binder/SolanaApplicationResolver"),G=require("./__test-utils__/makeInternalApi"),M=require("./ProvisionBasicClearSignDeviceAction"),L=require("./ProvisionGenericClearSignDeviceAction"),U=require("./ProvisionTransactionCheckDeviceAction"),z=require("./SignBasicClearSignDeviceAction"),F=require("./SignGenericClearSignDeviceAction"),q=require("./SignTransactionDeviceAction");const te="44'/501'/0'/0'",X=new Uint8Array([222,173,190,239]),P=new Uint8Array([170,187]),H=new Uint8Array([119,136]),w="1.15.5",oe={getContexts:e.vi.fn()};let u,p,d,K,Y,f,W,J,O,S,k,h,D,R,B,T,Z,Q,$,j,ee,ne;function m(i){return{blindSigningEnabled:!0,pubKeyDisplayMode:N.PublicKeyDisplayMode.LONG,version:i,transactionChecksEnabled:!1,transactionChecksOptIn:!1}}function v(i,o=a.DeviceModelId.NANO_X){return{sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Solana",version:i},deviceModelId:o,isSecureConnectionAllowed:!0}}function ae(){Q=e.vi.spyOn(L.ProvisionGenericClearSignDeviceAction.prototype,"extractDependencies").mockReturnValue({buildGenericClearSignContext:d,provideGenericClearSignContext:K,finalizeGenericClearSign:Y}),$=e.vi.spyOn(M.ProvisionBasicClearSignDeviceAction.prototype,"extractDependencies").mockReturnValue({inspectTransaction:f,buildBasicClearSignContext:W,provideBasicClearSignContext:J}),j=e.vi.spyOn(U.ProvisionTransactionCheckDeviceAction.prototype,"extractDependencies").mockReturnValue({transactionCheckOptIn:O,provideTransactionCheck:S}),ee=e.vi.spyOn(F.SignGenericClearSignDeviceAction.prototype,"extractDependencies").mockReturnValue({promptUiDisplay:h,refreshBlockhash:T,delayedSignTransaction:R}),ne=e.vi.spyOn(z.SignBasicClearSignDeviceAction.prototype,"extractDependencies").mockReturnValue({previewTransaction:D,refreshBlockhash:T,delayedSignTransaction:R,signTransaction:B})}function s(i,o,t){const n=new q.SignTransactionDeviceAction({input:i});Z=e.vi.spyOn(n,"extractDependencies").mockReturnValue({normalizeTransaction:e.vi.fn().mockResolvedValue({messageBytes:X,serializedForTxCheck:void 0}),getAppConfig:p,reportSign:k});const{observable:l}=n._execute(u),c=[];l.subscribe({next:g=>c.push(g),error:t,complete:()=>o(c)})}const C={derivationPath:te,transaction:X,transactionOptions:{skipOpenApp:!0},contextModule:oe},V={...C,solanaRPCURL:"https://api.devnet.solana.com"},E={...V,transactionOptions:{...C.transactionOptions,delayed:!0}};function x(i){const o=[];for(const t of i){if(t.status!==a.DeviceActionStatus.Pending)continue;const n=t.intermediateValue.step;o[o.length-1]!==n&&o.push(n)}return o}(0,e.describe)("SignTransactionDeviceAction (Solana) \u2013 orchestration",()=>{(0,e.beforeEach)(()=>{u=(0,G.makeDeviceActionInternalApiMock)(),u.getDeviceSessionState.mockReturnValue(v(w)),p=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:m(w)})),d=e.vi.fn().mockResolvedValue({mode:"none",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),K=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),Y=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),h=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),f=e.vi.fn().mockResolvedValue({transactionType:_.SolanaTransactionTypes.STANDARD}),W=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:{loadersResults:[],contextErrorCount:0}})),J=e.vi.fn().mockResolvedValue(void 0),D=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:b.Nothing})),T=e.vi.fn().mockImplementation(async i=>i.input.transaction),R=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:(0,b.Just)(H)})),B=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:(0,b.Just)(P)})),O=e.vi.fn().mockResolvedValue((0,a.CommandResultFactory)({data:{enabled:!0}})),S=e.vi.fn().mockResolvedValue(void 0),k=e.vi.fn().mockResolvedValue(void 0),ae()}),(0,e.afterEach)(()=>{Z?.mockRestore(),Q.mockRestore(),$.mockRestore(),j.mockRestore(),ee.mockRestore(),ne.mockRestore()}),(0,e.it)("generic unavailable then basic provisions then terminal one-shot sign (no RPC)",()=>new Promise((i,o)=>{s(C,t=>{try{(0,e.expect)(d).not.toHaveBeenCalled(),(0,e.expect)(f).toHaveBeenCalled(),(0,e.expect)(B).toHaveBeenCalled(),(0,e.expect)(R).not.toHaveBeenCalled();const n=t[t.length-1];(0,e.expect)(n.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(n.status===a.DeviceActionStatus.Completed&&n.output).toEqual(P),i()}catch(n){o(n)}},o)})),(0,e.it)("generic available + armed then terminal delayed sign (alreadyArmed, refreshed)",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),p.mockResolvedValue((0,a.CommandResultFactory)({data:m(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),d.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),s(E,t=>{try{(0,e.expect)(d).toHaveBeenCalled(),(0,e.expect)(h).toHaveBeenCalled(),(0,e.expect)(D).not.toHaveBeenCalled(),(0,e.expect)(T).toHaveBeenCalled(),(0,e.expect)(T.mock.calls[0][0].input.rpcUrl).toBeDefined(),(0,e.expect)(R).toHaveBeenCalled(),(0,e.expect)(f).not.toHaveBeenCalled();const n=t[t.length-1];(0,e.expect)(n.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(n.status===a.DeviceActionStatus.Completed&&n.output).toEqual(H),i()}catch(n){o(n)}},o)})),(0,e.it)("generic available + armed, RPC but no delayed then delayed sign on original (no refresh)",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),p.mockResolvedValue((0,a.CommandResultFactory)({data:m(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),d.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),s(V,t=>{try{(0,e.expect)(h).toHaveBeenCalled(),(0,e.expect)(D).not.toHaveBeenCalled(),(0,e.expect)(T.mock.calls[0][0].input.rpcUrl).toBeUndefined(),(0,e.expect)(R).toHaveBeenCalled(),(0,e.expect)(B).not.toHaveBeenCalled();const n=t[t.length-1];(0,e.expect)(n.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(n.status===a.DeviceActionStatus.Completed&&n.output).toEqual(H),i()}catch(n){o(n)}},o)})),(0,e.it)("not armed, RPC but no delayed then terminal one-shot sign (no refresh)",()=>new Promise((i,o)=>{s(V,t=>{try{(0,e.expect)(B).toHaveBeenCalled(),(0,e.expect)(D).not.toHaveBeenCalled(),(0,e.expect)(T).not.toHaveBeenCalled(),(0,e.expect)(R).not.toHaveBeenCalled();const n=t[t.length-1];(0,e.expect)(n.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(n.status===a.DeviceActionStatus.Completed&&n.output).toEqual(P),i()}catch(n){o(n)}},o)})),(0,e.it)("delayed requested + RPC but app lacks delayed-signing then one-shot sign (refresh withheld)",()=>new Promise((i,o)=>{const t="1.13.0";u.getDeviceSessionState.mockReturnValue(v(t)),p.mockResolvedValue((0,a.CommandResultFactory)({data:m(t)})),s(E,n=>{try{(0,e.expect)(B).toHaveBeenCalled(),(0,e.expect)(D).not.toHaveBeenCalled(),(0,e.expect)(T).not.toHaveBeenCalled(),(0,e.expect)(R).not.toHaveBeenCalled();const l=n[n.length-1];(0,e.expect)(l.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(l.status===a.DeviceActionStatus.Completed&&l.output).toEqual(P),i()}catch(l){o(l)}},o)})),(0,e.it)("generic degraded then basic then terminal",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),p.mockResolvedValue((0,a.CommandResultFactory)({data:m(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),s(E,t=>{try{(0,e.expect)(d).toHaveBeenCalled(),(0,e.expect)(f).toHaveBeenCalled(),(0,e.expect)(D).toHaveBeenCalled(),(0,e.expect)(R).toHaveBeenCalled(),(0,e.expect)(t[t.length-1].status).toBe(a.DeviceActionStatus.Completed),i()}catch(n){o(n)}},o)})),(0,e.it)("generic user cancel (6985) then error, no basic / no terminal",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),p.mockResolvedValue((0,a.CommandResultFactory)({data:m(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),d.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),h.mockResolvedValue((0,a.CommandResultFactory)({error:new I.SolanaAppCommandError({errorCode:"6985",message:"Canceled by user"})})),s(V,t=>{try{(0,e.expect)(f).not.toHaveBeenCalled(),(0,e.expect)(R).not.toHaveBeenCalled(),(0,e.expect)(B).not.toHaveBeenCalled(),(0,e.expect)(t[t.length-1].status).toBe(a.DeviceActionStatus.Error),i()}catch(n){o(n)}},o)})),(0,e.it)("terminal sign failure then error",()=>new Promise((i,o)=>{B.mockResolvedValue((0,a.CommandResultFactory)({error:new I.SolanaAppCommandError({errorCode:"6f01",message:"sign failed"})})),s(C,t=>{try{(0,e.expect)(B).toHaveBeenCalled(),(0,e.expect)(t[t.length-1].status).toBe(a.DeviceActionStatus.Error),i()}catch(n){o(n)}},o)})),(0,e.it)("getAppConfig error then error",()=>new Promise((i,o)=>{p.mockResolvedValue((0,a.CommandResultFactory)({error:new I.SolanaAppCommandError({errorCode:"6e00",message:"no app config"})})),s(C,t=>{try{(0,e.expect)(f).not.toHaveBeenCalled(),(0,e.expect)(t[t.length-1].status).toBe(a.DeviceActionStatus.Error),i()}catch(n){o(n)}},o)})),(0,e.it)("ProvisionTransactionCheckDeviceAction child is invoked when feature is supported",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_TRANSACTION_CHECKS_VERSION,a.DeviceModelId.FLEX)),p.mockResolvedValue((0,a.CommandResultFactory)({data:{...m(r.SOLANA_MIN_TRANSACTION_CHECKS_VERSION),transactionChecksEnabled:!0,transactionChecksOptIn:!0}})),s(C,t=>{try{const n=x(t);(0,e.expect)(n).toContain(y.signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE),(0,e.expect)(t[t.length-1].status).toBe(a.DeviceActionStatus.Completed),i()}catch(n){o(n)}},o)})),(0,e.it)("skips transaction-checks when transactionChecks is in disabledFeatures",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_TRANSACTION_CHECKS_VERSION,a.DeviceModelId.FLEX)),p.mockResolvedValue((0,a.CommandResultFactory)({data:{...m(r.SOLANA_MIN_TRANSACTION_CHECKS_VERSION),transactionChecksEnabled:!1,transactionChecksOptIn:!1}})),s({...C,disabledFeatures:["transactionChecks"]},t=>{try{const n=x(t);(0,e.expect)(n).not.toContain(y.signTransactionDAStateSteps.TRANSACTION_CHECKS_OPT_IN),(0,e.expect)(n).not.toContain(y.signTransactionDAStateSteps.TRANSACTION_CHECKS_PROVIDE),(0,e.expect)(t[t.length-1].status).toBe(a.DeviceActionStatus.Completed),i()}catch(n){o(n)}},o)})),(0,e.describe)("transaction-check re-provision after a generic fallback",()=>{const i=r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION;function o(n){u.getDeviceSessionState.mockReturnValue(v(i,a.DeviceModelId.FLEX)),p.mockResolvedValue((0,a.CommandResultFactory)({data:{...m(i),...n}}))}const t={mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]};(0,e.it)("generic degraded \u2192 tx-check provided again before basic",()=>new Promise((n,l)=>{o({transactionChecksEnabled:!0,transactionChecksOptIn:!0}),s(C,c=>{try{(0,e.expect)(d).toHaveBeenCalled(),(0,e.expect)(S).toHaveBeenCalledTimes(2),(0,e.expect)(O).not.toHaveBeenCalled(),(0,e.expect)(S.mock.invocationCallOrder[1]).toBeGreaterThan(d.mock.invocationCallOrder[0]),(0,e.expect)(S.mock.invocationCallOrder[1]).toBeLessThan(f.mock.invocationCallOrder[0]),(0,e.expect)(c[c.length-1].status).toBe(a.DeviceActionStatus.Completed),n()}catch(g){l(g)}},l)})),(0,e.it)("generic prompt failure (non-cancel) \u2192 tx-check provided again before basic",()=>new Promise((n,l)=>{o({transactionChecksEnabled:!0,transactionChecksOptIn:!0}),d.mockResolvedValue(t),h.mockResolvedValue((0,a.CommandResultFactory)({error:new I.SolanaAppCommandError({errorCode:"6a80",message:"bad descriptor"})})),s(C,c=>{try{(0,e.expect)(h).toHaveBeenCalled(),(0,e.expect)(S).toHaveBeenCalledTimes(2),(0,e.expect)(S.mock.invocationCallOrder[1]).toBeGreaterThan(h.mock.invocationCallOrder[0]),(0,e.expect)(f).toHaveBeenCalled(),(0,e.expect)(c[c.length-1].status).toBe(a.DeviceActionStatus.Completed),n()}catch(g){l(g)}},l)})),(0,e.it)("opt-in accepted on first pass \u2192 re-provision does not prompt again",()=>new Promise((n,l)=>{o({transactionChecksEnabled:!1,transactionChecksOptIn:!1}),s(C,c=>{try{(0,e.expect)(O).toHaveBeenCalledTimes(1),(0,e.expect)(S).toHaveBeenCalledTimes(2),(0,e.expect)(c[c.length-1].status).toBe(a.DeviceActionStatus.Completed),n()}catch(g){l(g)}},l)})),(0,e.it)("opt-in declined on first pass \u2192 no prompt and no provide on fallback",()=>new Promise((n,l)=>{o({transactionChecksEnabled:!1,transactionChecksOptIn:!1}),O.mockResolvedValue((0,a.CommandResultFactory)({data:{enabled:!1}})),s(C,c=>{try{(0,e.expect)(O).toHaveBeenCalledTimes(1),(0,e.expect)(S).not.toHaveBeenCalled(),(0,e.expect)(f).toHaveBeenCalled(),(0,e.expect)(c[c.length-1].status).toBe(a.DeviceActionStatus.Completed),n()}catch(g){l(g)}},l)})),(0,e.it)("generic prepared + signed \u2192 tx-check provided once",()=>new Promise((n,l)=>{o({transactionChecksEnabled:!0,transactionChecksOptIn:!0}),d.mockResolvedValue(t),s(C,c=>{try{(0,e.expect)(S).toHaveBeenCalledTimes(1),(0,e.expect)(f).not.toHaveBeenCalled(),(0,e.expect)(c[c.length-1].status).toBe(a.DeviceActionStatus.Completed),n()}catch(g){l(g)}},l)})),(0,e.it)("generic unavailable \u2192 tx-check provided once before basic",()=>new Promise((n,l)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_TRANSACTION_CHECKS_VERSION,a.DeviceModelId.FLEX)),p.mockResolvedValue((0,a.CommandResultFactory)({data:{...m(r.SOLANA_MIN_TRANSACTION_CHECKS_VERSION),transactionChecksEnabled:!0,transactionChecksOptIn:!0}})),s(C,c=>{try{(0,e.expect)(d).not.toHaveBeenCalled(),(0,e.expect)(S).toHaveBeenCalledTimes(1),(0,e.expect)(f).toHaveBeenCalled(),(0,e.expect)(c[c.length-1].status).toBe(a.DeviceActionStatus.Completed),n()}catch(g){l(g)}},l)}))}),(0,e.it)("e2e sequence: legacy SPL path with RPC then basic provisioning then delayed terminal",()=>new Promise((i,o)=>{f.mockResolvedValue({transactionType:_.SolanaTransactionTypes.SPL,data:{tokenAddress:null,createATA:!1}}),s(E,t=>{try{(0,e.expect)(x(t)).toEqual([y.signTransactionDAStateSteps.GET_APP_CONFIG,y.signTransactionDAStateSteps.INSPECT_TRANSACTION,y.signTransactionDAStateSteps.BUILD_BASIC_CLEAR_SIGN_CONTEXT,y.signTransactionDAStateSteps.PROVIDE_BASIC_CLEAR_SIGN_CONTEXT,A.signClearSignDAStateSteps.PREVIEW_TRANSACTION,A.signClearSignDAStateSteps.FETCH_BLOCKHASH,A.signClearSignDAStateSteps.DELAYED_SIGN]);const n=t[t.length-1];(0,e.expect)(n.status).toBe(a.DeviceActionStatus.Completed),i()}catch(n){o(n)}},o)})),(0,e.it)("e2e sequence: generic clear-sign armed then terminal refresh + delayed sign",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),p.mockResolvedValue((0,a.CommandResultFactory)({data:m(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),d.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),s(E,t=>{try{(0,e.expect)(x(t)).toEqual([y.signTransactionDAStateSteps.GET_APP_CONFIG,y.signTransactionDAStateSteps.BUILD_GENERIC_CLEAR_SIGN_CONTEXT,y.signTransactionDAStateSteps.PROVIDE_GENERIC_CLEAR_SIGN_CONTEXT,y.signTransactionDAStateSteps.FINALIZE_GENERIC_CLEAR_SIGN,A.signClearSignDAStateSteps.PROMPT_UI_DISPLAY,A.signClearSignDAStateSteps.FETCH_BLOCKHASH,A.signClearSignDAStateSteps.DELAYED_SIGN]);const n=t[t.length-1];(0,e.expect)(n.status).toBe(a.DeviceActionStatus.Completed),(0,e.expect)(n.status===a.DeviceActionStatus.Completed&&n.output).toEqual(H),i()}catch(n){o(n)}},o)})),(0,e.describe)("Report state \u2014 isBlindSign contract",()=>{(0,e.it)("legacy path (generic gate skipped) \u2192 isBlindSign: true, reportSign called once",()=>new Promise((i,o)=>{s(C,()=>{try{(0,e.expect)(k).toHaveBeenCalledOnce();const t=k.mock.calls[0][0];(0,e.expect)(t.input.isBlindSign).toBe(!0),i()}catch(t){o(t)}},o)})),(0,e.it)("generic clear-sign success \u2192 isBlindSign: false, reportSign called once",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),p.mockResolvedValue((0,a.CommandResultFactory)({data:m(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),d.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),s(E,()=>{try{(0,e.expect)(k).toHaveBeenCalledOnce();const t=k.mock.calls[0][0];(0,e.expect)(t.input.isBlindSign).toBe(!1),i()}catch(t){o(t)}},o)})),(0,e.it)("generic cancel (6985) \u2192 isBlindSign: false, reportSign called once",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),p.mockResolvedValue((0,a.CommandResultFactory)({data:m(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),d.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),h.mockResolvedValue((0,a.CommandResultFactory)({error:new I.SolanaAppCommandError({errorCode:"6985",message:"Canceled by user"})})),s(V,()=>{try{(0,e.expect)(k).toHaveBeenCalledOnce();const t=k.mock.calls[0][0];(0,e.expect)(t.input.isBlindSign).toBe(!1),i()}catch(t){o(t)}},o)})),(0,e.it)("generic non-cancel prompt failure degrades to basic \u2192 isBlindSign: true, reportSign called once",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),p.mockResolvedValue((0,a.CommandResultFactory)({data:m(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),d.mockResolvedValue({mode:"full",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[]}),h.mockResolvedValue((0,a.CommandResultFactory)({error:new I.SolanaAppCommandError({errorCode:"6f01",message:"Display error"})})),s(V,()=>{try{(0,e.expect)(k).toHaveBeenCalledOnce();const t=k.mock.calls[0][0];(0,e.expect)(t.input.isBlindSign).toBe(!0),i()}catch(t){o(t)}},o)})),(0,e.it)("generic build degrades with staleDescriptor \u2192 reportSign receives staleDescriptor: true",()=>new Promise((i,o)=>{u.getDeviceSessionState.mockReturnValue(v(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)),p.mockResolvedValue((0,a.CommandResultFactory)({data:m(r.SOLANA_MIN_GENERIC_CLEAR_SIGN_VERSION)})),d.mockResolvedValue({mode:"none",poolContexts:[],instructionInfoContexts:[],unrecognizedProgramIds:[],staleDescriptor:!0}),s(V,()=>{try{(0,e.expect)(k).toHaveBeenCalledOnce();const t=k.mock.calls[0][0];(0,e.expect)(t.input.isBlindSign).toBe(!0),(0,e.expect)(t.input.staleDescriptor).toBe(!0),i()}catch(t){o(t)}},o)}))})});
|
|
2
2
|
//# sourceMappingURL=SignTransactionDeviceAction.test.js.map
|