diff --git a/tee-worker/identity/client-api/parachain-api/README.md b/tee-worker/identity/client-api/parachain-api/README.md index e301ec6e1d..ee44e92b6b 100644 --- a/tee-worker/identity/client-api/parachain-api/README.md +++ b/tee-worker/identity/client-api/parachain-api/README.md @@ -15,9 +15,15 @@ These types were auto generated using [Polkadot.js Type Generation](https://polk 2. Extend and decorate the API's types with: ```typescript - import { identity, vc, trusted_operations, sidechain } from "parachain-api"; - - const types = { ...identity.types, ...vc.types, ...trusted_operations.types, ...sidechain.types }; + import { identity, vc, trusted_operations, sidechain, omniAccount } from "parachain-api"; + + const types = { + ...identity.types, + ...vc.types, + ...omniAccount.types, + ...trusted_operations.types, + ...sidechain.types, + }; const api = await ApiPromise.create({ provider, diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/CHANGELOG.md b/tee-worker/identity/client-sdk/packages/client-sdk/CHANGELOG.md index 9409c9e713..e2db89cd2f 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/CHANGELOG.md +++ b/tee-worker/identity/client-sdk/packages/client-sdk/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Add OmniAccount requestors for `createAccountStore`, `remark`, `transferNative`, `transferEthereum`, and `callEthereum`. + ## 2024-10-14 Initial version. Merge [@litentry/enclave](https://www.npmjs.com/package/@litentry/enclave) and [@litentry/vc-sdk](https://www.npmjs.com/package/@litentry/vc-sdk) into this one. diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/package.json b/tee-worker/identity/client-sdk/packages/client-sdk/package.json index f643c864b0..c38531fcfd 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/package.json +++ b/tee-worker/identity/client-sdk/packages/client-sdk/package.json @@ -1,15 +1,15 @@ { "name": "@litentry/client-sdk", "description": "This package provides helpers for dApps to interact with the Litentry Protocol.", - "version": "1.0.0", + "version": "1.0.0-next.0", "license": "GPL-3.0-or-later", "dependencies": {}, "devDependencies": { "@polkadot/rpc-provider": "^10.9.1" }, "peerDependencies": { - "@litentry/parachain-api": "0.9.20-4.1", - "@litentry/sidechain-api": "0.9.20-4", + "@litentry/parachain-api": "0.9.20-next.5", + "@litentry/sidechain-api": "0.9.20-next.5", "@litentry/chaindata": "*", "@polkadot/api": "^10.9.1", "@polkadot/types": "^10.9.1", diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/index.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/index.ts index 714c913dc8..dc81833719 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/index.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/index.ts @@ -19,9 +19,9 @@ export { ID_GRAPH_STRUCT } from './lib/type-creators/id-graph'; // vc export { validateVc, - VerifiableCredentialLike, + type VerifiableCredentialLike, } from './lib/vc-validator/validator'; -export { +export type { ValidationResultDetail, ValidationResult, } from './lib/vc-validator/validator.types'; diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/call-ethereum.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/call-ethereum.request.ts new file mode 100644 index 0000000000..ca0ebc7ea0 --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/call-ethereum.request.ts @@ -0,0 +1,108 @@ +import { assert, hexToU8a } from '@polkadot/util'; +import { randomAsHex } from '@polkadot/util-crypto'; + +import type { ApiPromise } from '@polkadot/api'; +import type { + LitentryIdentity, + WorkerRpcReturnValue, +} from '@litentry/parachain-api'; + +import { enclave } from '../enclave'; +import { createPayloadToSign } from '../util/create-payload-to-sign'; +import { createTrustedCallType } from '../type-creators/trusted-call'; +import { createRequestType } from '../type-creators/request'; + +import type { JsonRpcRequest } from '../util/types'; +import type { U8aLike } from '@polkadot/util/types'; + +/** + * OmniAccount: Call an Ethereum contract. + */ +export async function callEthereum( + /** Litentry Parachain API instance from Polkadot.js */ + api: ApiPromise, + data: { + /** The user's omniAccount. Use `createLitentryIdentityType` helper to create this struct */ + omniAccount: LitentryIdentity; + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + /** Ethereum contract address */ + address: string; + /** Contract input data */ + input: U8aLike; + } +): Promise<{ + payloadToSign: string; + txHash: string; + send: (args: { signedPayload: string }) => Promise<{ + response: Array; + txHash: string; + }>; +}> { + const { who, omniAccount } = data; + + assert(omniAccount.isSubstrate, 'OmniAccount must be a Substrate identity'); + + const shard = await enclave.getShard(api); + const shardU8 = hexToU8a(shard); + const txHash = randomAsHex(); + + const { call } = await createTrustedCallType(api.registry, { + method: 'request_intent', + params: { + who, + intent: api.createType('Intent', { + CallEthereum: api.createType('IntentCallEthereum', { + address: data.address, + input: data.input, + }), + }), + }, + }); + + const nonce = await api.rpc.system.accountNextIndex(omniAccount.asSubstrate); + + const payloadToSign = createPayloadToSign({ + who, + call, + nonce, + shard: shardU8, + }); + + const send = async (args: { + signedPayload: string; + }): Promise<{ + response: Array; + txHash: string; + }> => { + // prepare and encrypt request + + const request = await createRequestType(api, { + signer: who, + signature: args.signedPayload, + call, + nonce, + shard: shardU8, + }); + + // send the request to the Enclave + const rpcRequest: JsonRpcRequest = { + jsonrpc: '2.0', + method: 'author_submitNativeRequest', + params: [request.toHex()], + }; + + const enclaveResult = await enclave.send(api, rpcRequest); + + return { + txHash, + response: enclaveResult, + }; + }; + + return { + txHash, + payloadToSign, + send, + }; +} diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/create-account-store.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/create-account-store.request.ts new file mode 100644 index 0000000000..3932dd96df --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/create-account-store.request.ts @@ -0,0 +1,97 @@ +import { hexToU8a } from '@polkadot/util'; +import { randomAsHex } from '@polkadot/util-crypto'; + +import type { ApiPromise } from '@polkadot/api'; +import type { + LitentryIdentity, + WorkerRpcReturnValue, +} from '@litentry/parachain-api'; + +import { enclave } from '../enclave'; +import { createPayloadToSign } from '../util/create-payload-to-sign'; +import { createTrustedCallType } from '../type-creators/trusted-call'; +import { createRequestType } from '../type-creators/request'; + +import type { JsonRpcRequest } from '../util/types'; + +/** + * OmniAccount: Create the OmniAccount for the given Identity + */ +export async function createAccountStore( + /** Litentry Parachain API instance from Polkadot.js */ + api: ApiPromise, + data: { + /** The user's OmniAccount. Use `createLitentryIdentityType` helper to create this struct */ + omniAccount: LitentryIdentity; + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + } +): Promise<{ + payloadToSign: string; + txHash: string; + send: (args: { signedPayload: string }) => Promise<{ + response: Array; + txHash: string; + }>; +}> { + const { who, omniAccount } = data; + + const shard = await enclave.getShard(api); + const shardU8 = hexToU8a(shard); + const txHash = randomAsHex(); + + const { call } = await createTrustedCallType(api.registry, { + method: 'create_account_store', + params: { + who, + }, + }); + + const nonce = await api.rpc.system.accountNextIndex( + omniAccount.asSubstrate.toHex() + ); + + const payloadToSign = createPayloadToSign({ + who, + call, + nonce, + shard: shardU8, + }); + + const send = async (args: { + signedPayload: string; + }): Promise<{ + response: Array; + txHash: string; + }> => { + // prepare and encrypt request + + const request = await createRequestType(api, { + signer: who, + signature: args.signedPayload, + call, + nonce, + shard: shardU8, + }); + + // send the request to the Enclave + const rpcRequest: JsonRpcRequest = { + jsonrpc: '2.0', + method: 'author_submitNativeRequest', + params: [request.toHex()], + }; + + const enclaveResult = await enclave.send(api, rpcRequest); + + return { + txHash, + response: enclaveResult, + }; + }; + + return { + txHash, + payloadToSign, + send, + }; +} diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/get-last-registered-enclave.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/get-last-registered-enclave.ts index d903a1a60c..94cad65f97 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/get-last-registered-enclave.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/get-last-registered-enclave.ts @@ -1,8 +1,8 @@ import type { ApiPromise } from '@polkadot/api'; import { AccountId32 } from '@polkadot/types/interfaces'; import type { - PalletTeebagEnclave, - PalletTeebagWorkerType, + CorePrimitivesTeebagTypesEnclave, + CorePrimitivesTeebagTypesWorkerType, } from '@polkadot/types/lookup'; /** @@ -10,8 +10,11 @@ import type { */ export async function getLastRegisteredEnclave( api: ApiPromise, - workerType: PalletTeebagWorkerType['type'] = 'Identity' -): Promise<{ account: AccountId32; enclave: PalletTeebagEnclave }> { + workerType: CorePrimitivesTeebagTypesWorkerType['type'] = 'Identity' +): Promise<{ + account: AccountId32; + enclave: CorePrimitivesTeebagTypesEnclave; +}> { const identifiers = await api.query.teebag.enclaveIdentifier(workerType); const latestEnclaveId = identifiers[identifiers.length - 1]; diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/index.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/index.ts index 4e974ad5ad..3d08758f77 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/index.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/index.ts @@ -2,6 +2,12 @@ export { createChallengeCode, linkIdentity } from './link-identity.request'; export { linkIdentityCallback } from './link-identity-callback.request'; export { setIdentityNetworks } from './set-identity-networks.request'; export { requestBatchVC } from './request-batch-vc.request'; +export { remark } from './remark.request'; +export { transferNative } from './transfer-native.request'; +export { transferEthereum } from './transfer-ethereum.request'; +export { callEthereum } from './call-ethereum.request'; + +export { createAccountStore } from './create-account-store.request'; export { getIdGraph } from './get-id-graph.request'; export { getIdGraphHash } from './get-id-graph-hash'; export { getLastRegisteredEnclave } from './get-last-registered-enclave'; diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/remark.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/remark.request.ts new file mode 100644 index 0000000000..831354ff7e --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/remark.request.ts @@ -0,0 +1,104 @@ +import { assert, hexToU8a, stringToHex } from '@polkadot/util'; +import { randomAsHex } from '@polkadot/util-crypto'; + +import type { ApiPromise } from '@polkadot/api'; +import type { + LitentryIdentity, + WorkerRpcReturnValue, +} from '@litentry/parachain-api'; + +import { enclave } from '../enclave'; +import { createPayloadToSign } from '../util/create-payload-to-sign'; +import { createTrustedCallType } from '../type-creators/trusted-call'; +import { createRequestType } from '../type-creators/request'; + +import type { JsonRpcRequest } from '../util/types'; + +/** + * OmniAccount: Make a remark + */ +export async function remark( + /** Litentry Parachain API instance from Polkadot.js */ + api: ApiPromise, + data: { + /** The user's omniAccount. Use `createLitentryIdentityType` helper to create this struct */ + omniAccount: LitentryIdentity; + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + /** the message to be sent */ + message: string; + } +): Promise<{ + payloadToSign: string; + txHash: string; + send: (args: { signedPayload: string }) => Promise<{ + response: Array; + txHash: string; + }>; +}> { + const { who, message, omniAccount } = data; + + const shard = await enclave.getShard(api); + const shardU8 = hexToU8a(shard); + const txHash = randomAsHex(); + + const { call } = await createTrustedCallType(api.registry, { + method: 'request_intent', + params: { + who, + intent: api.createType('Intent', { + SystemRemark: stringToHex(message), + }), + }, + }); + + assert(omniAccount.isSubstrate, 'OmniAccount must be a Substrate identity'); + + const nonce = await api.rpc.system.accountNextIndex( + omniAccount.asSubstrate.toHex() + ); + + const payloadToSign = createPayloadToSign({ + who, + call, + nonce, + shard: shardU8, + }); + + const send = async (args: { + signedPayload: string; + }): Promise<{ + response: Array; + txHash: string; + }> => { + // prepare and encrypt request + + const request = await createRequestType(api, { + signer: who, + signature: args.signedPayload, + call, + nonce, + shard: shardU8, + }); + + // send the request to the Enclave + const rpcRequest: JsonRpcRequest = { + jsonrpc: '2.0', + method: 'author_submitNativeRequest', + params: [request.toHex()], + }; + + const enclaveResult = await enclave.send(api, rpcRequest); + + return { + txHash, + response: enclaveResult, + }; + }; + + return { + txHash, + payloadToSign, + send, + }; +} diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/transfer-ethereum.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/transfer-ethereum.request.ts new file mode 100644 index 0000000000..f880b281b7 --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/transfer-ethereum.request.ts @@ -0,0 +1,107 @@ +import { assert, hexToU8a } from '@polkadot/util'; +import { randomAsHex } from '@polkadot/util-crypto'; + +import type { ApiPromise } from '@polkadot/api'; +import type { + LitentryIdentity, + WorkerRpcReturnValue, +} from '@litentry/parachain-api'; + +import { enclave } from '../enclave'; +import { createPayloadToSign } from '../util/create-payload-to-sign'; +import { createTrustedCallType } from '../type-creators/trusted-call'; +import { createRequestType } from '../type-creators/request'; + +import type { JsonRpcRequest } from '../util/types'; + +/** + * OmniAccount: Transfer funds to Ethereum Network. + */ +export async function transferEthereum( + /** Litentry Parachain API instance from Polkadot.js */ + api: ApiPromise, + data: { + /** The user's omniAccount. Use `createLitentryIdentityType` helper to create this struct */ + omniAccount: LitentryIdentity; + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + /** Ethereum address destination */ + to: string; + /** Amount to send */ + amount: bigint; + } +): Promise<{ + payloadToSign: string; + txHash: string; + send: (args: { signedPayload: string }) => Promise<{ + response: Array; + txHash: string; + }>; +}> { + const { who, omniAccount } = data; + + assert(omniAccount.isSubstrate, 'OmniAccount must be a Substrate identity'); + + const shard = await enclave.getShard(api); + const shardU8 = hexToU8a(shard); + const txHash = randomAsHex(); + + const { call } = await createTrustedCallType(api.registry, { + method: 'request_intent', + params: { + who, + intent: api.createType('Intent', { + TransferEthereum: api.createType('IntentTransferEthereum', { + to: data.to, + value: data.amount, + }), + }), + }, + }); + + const nonce = await api.rpc.system.accountNextIndex(omniAccount.asSubstrate); + + const payloadToSign = createPayloadToSign({ + who, + call, + nonce, + shard: shardU8, + }); + + const send = async (args: { + signedPayload: string; + }): Promise<{ + response: Array; + txHash: string; + }> => { + // prepare and encrypt request + + const request = await createRequestType(api, { + signer: who, + signature: args.signedPayload, + call, + nonce, + shard: shardU8, + }); + + // send the request to the Enclave + const rpcRequest: JsonRpcRequest = { + jsonrpc: '2.0', + method: 'author_submitNativeRequest', + params: [request.toHex()], + }; + + const enclaveResult = await enclave.send(api, rpcRequest); + + return { + txHash, + response: enclaveResult, + }; + }; + + return { + txHash, + payloadToSign, + send, + }; +} diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/transfer-native.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/transfer-native.request.ts new file mode 100644 index 0000000000..2aff5e2b63 --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/transfer-native.request.ts @@ -0,0 +1,107 @@ +import { assert, hexToU8a } from '@polkadot/util'; +import { randomAsHex } from '@polkadot/util-crypto'; + +import type { ApiPromise } from '@polkadot/api'; +import type { + LitentryIdentity, + WorkerRpcReturnValue, +} from '@litentry/parachain-api'; + +import { enclave } from '../enclave'; +import { createPayloadToSign } from '../util/create-payload-to-sign'; +import { createTrustedCallType } from '../type-creators/trusted-call'; +import { createRequestType } from '../type-creators/request'; + +import type { JsonRpcRequest } from '../util/types'; + +/** + * OmniAccount: Transfer funds within the Litentry Network. + */ +export async function transferNative( + /** Litentry Parachain API instance from Polkadot.js */ + api: ApiPromise, + data: { + /** The user's omniAccount. Use `createLitentryIdentityType` helper to create this struct */ + omniAccount: LitentryIdentity; + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + /** Account destination in hex or ss58 formatted address */ + to: string; + /** Amount to send */ + amount: bigint; + } +): Promise<{ + payloadToSign: string; + txHash: string; + send: (args: { signedPayload: string }) => Promise<{ + response: Array; + txHash: string; + }>; +}> { + const { who, omniAccount } = data; + + assert(omniAccount.isSubstrate, 'OmniAccount must be a Substrate identity'); + + const shard = await enclave.getShard(api); + const shardU8 = hexToU8a(shard); + const txHash = randomAsHex(); + + const { call } = await createTrustedCallType(api.registry, { + method: 'request_intent', + params: { + who, + intent: api.createType('Intent', { + TransferNative: api.createType('IntentTransferNative', { + to: data.to, + value: data.amount, + }), + }), + }, + }); + + const nonce = await api.rpc.system.accountNextIndex(omniAccount.asSubstrate); + + const payloadToSign = createPayloadToSign({ + who, + call, + nonce, + shard: shardU8, + }); + + const send = async (args: { + signedPayload: string; + }): Promise<{ + response: Array; + txHash: string; + }> => { + // prepare and encrypt request + + const request = await createRequestType(api, { + signer: who, + signature: args.signedPayload, + call, + nonce, + shard: shardU8, + }); + + // send the request to the Enclave + const rpcRequest: JsonRpcRequest = { + jsonrpc: '2.0', + method: 'author_submitNativeRequest', + params: [request.toHex()], + }; + + const enclaveResult = await enclave.send(api, rpcRequest); + + return { + txHash, + response: enclaveResult, + }; + }; + + return { + txHash, + payloadToSign, + send, + }; +} diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/request.ts index a4ab6a79d5..8e9074244f 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/request.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/request.ts @@ -48,21 +48,41 @@ export async function createRequestType( signature: signedPayload, }); - const signedCall = api.createType('TrustedCallSigned', { - call, - index: nonce, - signature: signature, - }); + let operationU8a = new Uint8Array(); - const operation = api.createType('TrustedOperation', { - direct_call: signedCall, - }); + if (isNativeRequest(call)) { + const callAuthenticated = api.createType('TrustedCallAuthenticated', { + call, + nonce, + authentication: api.createType('TCAuthentication', { + Web3: signature, + }), + }); + + const operation = api.createType('TrustedOperation', { + direct_call: callAuthenticated, + }); + + operationU8a = operation.toU8a(); + } else { + const signedCall = api.createType('TrustedCallSigned', { + call, + index: nonce, + signature: signature, + }); + + const operation = api.createType('TrustedOperation', { + direct_call: signedCall, + }); + + operationU8a = operation.toU8a(); + } // Encrypt the operation call using the client shielding key const encryptionNonce = generateNonce12(); const { ciphertext: encryptedOperation } = await encrypt( { - cleartext: operation.toU8a(), + cleartext: operationU8a, nonce: encryptionNonce, }, encryptionKey @@ -86,3 +106,7 @@ export async function createRequestType( payload: encryptedPayload, }); } + +function isNativeRequest(call: TrustedCall): boolean { + return call.isRequestIntent || call.isCreateAccountStore; +} diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/trusted-call.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/trusted-call.ts index 3156b4bb4c..e4fdc3b413 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/trusted-call.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/trusted-call.ts @@ -2,7 +2,7 @@ import { compactAddLength } from '@polkadot/util'; import type { Registry } from '@polkadot/types-codec/types'; -import { trusted_operations } from '@litentry/parachain-api'; +import { trusted_operations, type Intent } from '@litentry/parachain-api'; import type { TrustedCall, LitentryIdentity, @@ -66,6 +66,17 @@ type SetIdentityNetworksParams = { hash: `0x${string}`; }; +// LitentryIdentity, Intent +type RequestIntentParams = { + who: LitentryIdentity; + intent: Intent; +}; + +// LitentryIdentity +type RequestCreateAccountStoreParams = { + who: LitentryIdentity; +}; + /** * Creates the TrustedCall for the given method and provide the `param's` types expected for them. * @@ -104,6 +115,20 @@ export async function createTrustedCallType( params: RequestBatchVcParams; } ): Promise<{ call: TrustedCall; key: CryptoKey }>; +export async function createTrustedCallType( + registry: Registry, + data: { + method: 'request_intent'; + params: RequestIntentParams; + } +): Promise<{ call: TrustedCall; key: CryptoKey }>; +export async function createTrustedCallType( + registry: Registry, + data: { + method: 'create_account_store'; + params: RequestCreateAccountStoreParams; + } +): Promise<{ call: TrustedCall; key: CryptoKey }>; export async function createTrustedCallType( registry: Registry, data: { @@ -219,6 +244,32 @@ export async function createTrustedCallType( return { call, key }; } + if (isRequestIntentCall(method, params)) { + const { who, intent } = params; + + const call = registry.createType('TrustedCall', { + [trustedCallMethodsMap.request_intent]: registry.createType( + trusted_operations.types.TrustedCall._enum.request_intent, + [who, intent] + ), + }) as TrustedCall; + + return { call, key }; + } + + if (isRequestCreateAccountStoreParams(method, params)) { + const { who } = params; + + const call = registry.createType('TrustedCall', { + [trustedCallMethodsMap.create_account_store]: registry.createType( + trusted_operations.types.TrustedCall._enum.create_account_store, + who + ), + }) as TrustedCall; + + return { call, key }; + } + throw new Error(`trusted call method: ${data.method} is not supported`); } @@ -253,3 +304,15 @@ function isRequestBatchVcCall( ): params is RequestBatchVcParams { return method === 'request_batch_vc'; } +function isRequestIntentCall( + method: TrustedCallMethod, + params: Record +): params is RequestIntentParams { + return method === 'request_intent'; +} +function isRequestCreateAccountStoreParams( + method: TrustedCallMethod, + params: Record +): params is RequestCreateAccountStoreParams { + return method === 'create_account_store'; +} diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/vc-validator/validator.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/vc-validator/validator.ts index 9df35ad019..70b7764da5 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/vc-validator/validator.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/vc-validator/validator.ts @@ -2,7 +2,7 @@ import { ApiPromise } from '@polkadot/api'; import { hexToU8a, stringToU8a } from '@polkadot/util'; import { base58Decode, signatureVerify } from '@polkadot/util-crypto'; -import type { PalletTeebagEnclave } from '@litentry/parachain-api'; +import type { CorePrimitivesTeebagTypesEnclave } from '@litentry/parachain-api'; import { RUNTIME_ENCLAVE_REGISTRY } from './runtime-enclave-registry'; @@ -298,8 +298,8 @@ export function validateVcWithTrustedTeeDevEnclave( api: ApiPromise, vc: VerifiableCredentialLike ): true | string { - const enclave: PalletTeebagEnclave = api.createType( - 'PalletTeebagEnclave', + const enclave: CorePrimitivesTeebagTypesEnclave = api.createType( + 'CorePrimitivesTeebagTypesEnclave', RUNTIME_ENCLAVE_REGISTRY ); diff --git a/tee-worker/identity/client-sdk/pnpm-lock.yaml b/tee-worker/identity/client-sdk/pnpm-lock.yaml index f8267a6271..421e70eff3 100644 --- a/tee-worker/identity/client-sdk/pnpm-lock.yaml +++ b/tee-worker/identity/client-sdk/pnpm-lock.yaml @@ -87,11 +87,11 @@ importers: dependencies: tslib: 2.6.2 - packages/enclave: + packages/client-sdk: specifiers: '@litentry/chaindata': '*' - '@litentry/parachain-api': 0.9.20-4.1 - '@litentry/sidechain-api': 0.9.20-4 + '@litentry/parachain-api': 0.9.20-next.5 + '@litentry/sidechain-api': 0.9.20-next.5 '@polkadot/api': ^10.9.1 '@polkadot/rpc-provider': ^10.9.1 '@polkadot/types': ^10.9.1 @@ -101,8 +101,8 @@ importers: tslib: ^2.3.0 dependencies: '@litentry/chaindata': link:../chaindata - '@litentry/parachain-api': 0.9.20-4.1 - '@litentry/sidechain-api': 0.9.20-4 + '@litentry/parachain-api': 0.9.20-next.5 + '@litentry/sidechain-api': 0.9.20-next.5 '@polkadot/api': 10.13.1 '@polkadot/types': 10.13.1 '@polkadot/types-codec': 10.13.1 @@ -112,25 +112,6 @@ importers: devDependencies: '@polkadot/rpc-provider': 10.13.1 - packages/vc-sdk: - specifiers: - '@litentry/parachain-api': 0.9.20-4.1 - '@litentry/sidechain-api': 0.9.20-4 - '@polkadot/api': ^10.9.1 - '@polkadot/util': ^12.5.1 - '@polkadot/util-crypto': ^12.5.1 - fast-glob: ^3.3.2 - tslib: ^2.3.0 - dependencies: - '@litentry/parachain-api': 0.9.20-4.1 - '@litentry/sidechain-api': 0.9.20-4 - '@polkadot/api': 10.13.1 - '@polkadot/util': 12.6.2 - '@polkadot/util-crypto': 12.6.2_@polkadot+util@12.6.2 - tslib: 2.6.2 - devDependencies: - fast-glob: 3.3.2 - packages: /@aashutoshrathi/word-wrap/1.2.6: @@ -1760,8 +1741,8 @@ packages: '@jridgewell/resolve-uri': 3.1.1 '@jridgewell/sourcemap-codec': 1.4.15 - /@litentry/parachain-api/0.9.20-4.1: - resolution: {integrity: sha512-IL3E86EXlc3YdzHghxHwy0+a+1cWAjyQ8Ynyku4BtD6lL5b/bLgS3tFRmAYhkmmIFfJnx9vLRw2gZ3LVEudcJg==} + /@litentry/parachain-api/0.9.20-next.5: + resolution: {integrity: sha512-FnK4Jb/i2+sV0V0qy4iT7aswk8JzOXDtyW76VGVFva5vb7IXEz9TC4CmEKFTVE1o0mvBB8+eRbu2HYliq/3i4w==} dependencies: '@polkadot/api': 10.13.1 '@polkadot/api-augment': 10.13.1 @@ -1783,8 +1764,8 @@ packages: - utf-8-validate dev: false - /@litentry/sidechain-api/0.9.20-4: - resolution: {integrity: sha512-wYIS8FStKL7Nw/ViRlRMijSpZgVxJr2OKQlSRO1j9rBdNiCiOw0M5Y5Uo3eeSO7y4R04gPaSm7q0FvjByvGEMw==} + /@litentry/sidechain-api/0.9.20-next.5: + resolution: {integrity: sha512-wJTsPq9DJGSD2PSpR4AFdAmta/RDR/L2iAUnMQxYd49H/a1Pl/X6X7Ml50QR9OIftJLfah0SIwlKhdsMaOenvg==} dependencies: '@polkadot/api': 10.13.1 '@polkadot/api-augment': 10.13.1