From 7a5f0b2379d6b538888915233edbc765fe768be4 Mon Sep 17 00:00:00 2001 From: Francisco Silva Date: Fri, 15 Nov 2024 20:36:31 +0100 Subject: [PATCH] Updating client-sdk types and bug fixes (#3179) --- .../packages/client-sdk/docs/README.md | 88 +++++-- .../client-sdk/docs/modules/request.md | 233 +++++++++++++++++- .../packages/client-sdk/package.json | 46 ++-- .../src/lib/requests/call-ethereum.request.ts | 10 +- .../requests/create-account-store.request.ts | 4 +- .../link-identity-callback.request.ts | 4 +- .../src/lib/requests/link-identity.request.ts | 4 +- .../src/lib/requests/remark.request.ts | 4 +- .../lib/requests/request-batch-vc.request.ts | 4 +- .../requests/set-identity-networks.request.ts | 4 +- .../lib/requests/transfer-ethereum.request.ts | 4 +- .../lib/requests/transfer-native.request.ts | 4 +- .../src/lib/type-creators/request.ts | 45 +++- .../type-creators/tc-authentication.test.ts | 14 +- .../lib/type-creators/tc-authentication.ts | 12 +- 15 files changed, 396 insertions(+), 84 deletions(-) diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/docs/README.md b/tee-worker/identity/client-sdk/packages/client-sdk/docs/README.md index 65fcecc0b3..a1c8e4c65d 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/docs/README.md +++ b/tee-worker/identity/client-sdk/packages/client-sdk/docs/README.md @@ -41,6 +41,7 @@ - [createLitentryIdentityType](README.md#createlitentryidentitytype) - [createLitentryValidationDataType](README.md#createlitentryvalidationdatatype) - [createRequestType](README.md#createrequesttype) +- [createTCAuthenticationType](README.md#createtcauthenticationtype) - [createTrustedCallType](README.md#createtrustedcalltype) - [toPublicKey](README.md#topublickey) - [validateVc](README.md#validatevc) @@ -505,23 +506,44 @@ The shielding key is encrypted using the Enclave's shielding key and attached in #### Parameters +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | - | +| `data` | `Object` | - | +| `data.authentication` | `string` | signature or verification code based on the identity type | +| `data.call` | `TrustedCall` | - | +| `data.nonce` | `Index` | - | +| `data.sender` | `LitentryIdentity` | - | +| `data.shard` | `Uint8Array` | - | + +#### Returns + +`Promise`\<`AesRequest`\> + +#### Defined in + +[lib/type-creators/request.ts:32](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/request.ts#L32) + +___ + +### createTCAuthenticationType + +▸ **createTCAuthenticationType**(`registry`, `data`): `TCAuthentication` + +#### Parameters + | Name | Type | | :------ | :------ | -| `api` | `ApiPromise` | -| `data` | `Object` | -| `data.call` | `TrustedCall` | -| `data.nonce` | `Index` | -| `data.shard` | `Uint8Array` | -| `data.signature` | `string` | -| `data.signer` | `LitentryIdentity` | +| `registry` | `Registry` | +| `data` | `AuthenticationData` | #### Returns -`Promise`\<`AesRequest`\> +`TCAuthentication` #### Defined in -[lib/type-creators/request.ts:30](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/request.ts#L30) +[lib/type-creators/tc-authentication.ts:16](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/tc-authentication.ts#L16) ___ @@ -556,7 +578,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:79](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L79) +[lib/type-creators/trusted-call.ts:90](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L90) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -575,7 +597,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:86](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L86) +[lib/type-creators/trusted-call.ts:97](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L97) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -594,7 +616,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:93](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L93) +[lib/type-creators/trusted-call.ts:104](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L104) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -613,7 +635,45 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:100](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L100) +[lib/type-creators/trusted-call.ts:111](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L111) + +▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `registry` | `Registry` | +| `data` | `Object` | +| `data.method` | ``"request_intent"`` | +| `data.params` | `RequestIntentParams` | + +#### Returns + +`Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> + +#### Defined in + +[lib/type-creators/trusted-call.ts:118](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L118) + +▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `registry` | `Registry` | +| `data` | `Object` | +| `data.method` | ``"create_account_store"`` | +| `data.params` | `RequestCreateAccountStoreParams` | + +#### Returns + +`Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> + +#### Defined in + +[lib/type-creators/trusted-call.ts:125](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L125) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -632,7 +692,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:107](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L107) +[lib/type-creators/trusted-call.ts:132](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L132) ___ diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/docs/modules/request.md b/tee-worker/identity/client-sdk/packages/client-sdk/docs/modules/request.md index 85c5cec485..0bb02d3b42 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/docs/modules/request.md +++ b/tee-worker/identity/client-sdk/packages/client-sdk/docs/modules/request.md @@ -8,17 +8,100 @@ requests ### Functions +- [callEthereum](request.md#callethereum) +- [createAccountStore](request.md#createaccountstore) - [createChallengeCode](request.md#createchallengecode) - [getIdGraph](request.md#getidgraph) - [getIdGraphHash](request.md#getidgraphhash) - [getLastRegisteredEnclave](request.md#getlastregisteredenclave) - [linkIdentity](request.md#linkidentity) - [linkIdentityCallback](request.md#linkidentitycallback) +- [remark](request.md#remark) - [requestBatchVC](request.md#requestbatchvc) +- [requestVerificationCode](request.md#requestverificationcode) - [setIdentityNetworks](request.md#setidentitynetworks) +- [transferEthereum](request.md#transferethereum) +- [transferNative](request.md#transfernative) ## Functions +### callEthereum + +▸ **callEthereum**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +OmniAccount: Call an Ethereum contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.address` | `string` | Ethereum contract address | +| `data.input` | `U8aLike` | Contract input data | +| `data.omniAccount` | `LitentryIdentity` | The user's omniAccount. Use `createLitentryIdentityType` helper to create this struct | +| `data.who` | `LitentryIdentity` | The user's account. Use `createLitentryIdentityType` helper to create this struct | + +#### Returns + +`Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +- A promise that resolves to an object containing the payload to signature +(if applicable) and a send function. + +[payloadToSign] - The payload to sign if who is not an email identity. + +send - A function to send the request to the Enclave. + +send.args - The arguments required to send the request. + +send.args.authentication - The authentication string. If who is an +email identity, this is the email verification code. If the who is not an email identity, this +is the signed payload. + +#### Defined in + +[lib/requests/call-ethereum.request.ts:31](https://github.com/litentry/client-sdk/blob/develop/lib/requests/call-ethereum.request.ts#L31) + +___ + +### createAccountStore + +▸ **createAccountStore**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +Creates an account store on the Litentry Parachain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.omniAccount` | `LitentryIdentity` | The user's OmniAccount. Use `createLitentryIdentityType` helper to create this struct | +| `data.who` | `LitentryIdentity` | The user's account. Use `createLitentryIdentityType` helper to create this struct | + +#### Returns + +`Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +- A promise that resolves to an object containing the payload to sign (if applicable) and a send function. + +[payloadToSign] - The payload to sign if who is not an email identity. + +send - A function to send the request to the Enclave. + +send.args - The arguments required to send the request. + +send.args.authentication - The authentication string. If who is +an email identity, this is the email verification code. If the who is not an email identity, this is the +signed payload. + +#### Defined in + +[lib/requests/create-account-store.request.ts:29](https://github.com/litentry/client-sdk/blob/develop/lib/requests/create-account-store.request.ts#L29) + +___ + ### createChallengeCode ▸ **createChallengeCode**(`api`, `args`, `options?`): `Promise`\<`string`\> @@ -106,7 +189,7 @@ ___ ### getLastRegisteredEnclave -▸ **getLastRegisteredEnclave**(`api`, `workerType?`): `Promise`\<\{ `account`: `AccountId32` ; `enclave`: `PalletTeebagEnclave` }\> +▸ **getLastRegisteredEnclave**(`api`, `workerType?`): `Promise`\<\{ `account`: `AccountId32` ; `enclave`: `CorePrimitivesTeebagTypesEnclave` }\> Return the Enclave registry information of the latest registered TEE worker. @@ -115,11 +198,11 @@ Return the Enclave registry information of the latest registered TEE worker. | Name | Type | Default value | | :------ | :------ | :------ | | `api` | `ApiPromise` | `undefined` | -| `workerType` | ``"Identity"`` \| ``"BitAcross"`` | `'Identity'` | +| `workerType` | ``"Identity"`` \| ``"BitAcross"`` \| ``"OmniExecutor"`` | `'Identity'` | #### Returns -`Promise`\<\{ `account`: `AccountId32` ; `enclave`: `PalletTeebagEnclave` }\> +`Promise`\<\{ `account`: `AccountId32` ; `enclave`: `CorePrimitivesTeebagTypesEnclave` }\> #### Defined in @@ -184,6 +267,45 @@ are used as the signer. ___ +### remark + +▸ **remark**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +Sends a remark to the Litentry Parachain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.message` | `string` | the message to be sent | +| `data.omniAccount` | `LitentryIdentity` | The user's omniAccount. Use `createLitentryIdentityType` helper to create this struct | +| `data.who` | `LitentryIdentity` | The user's account. Use `createLitentryIdentityType` helper to create this struct | + +#### Returns + +`Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +- A promise that resolves to an object containing the payload to sign +(if applicable) and a send function. + +[payloadToSign] - The payload to sign if who is not an email identity. + +send - A function to send the request to the Enclave. + +send.args - The arguments required to send the request. + +send.args.authentication - The authentication string. If who is +an email identity, this is the email verification code. If the who is not an email identity, +this is the signed payload. + +#### Defined in + +[lib/requests/remark.request.ts:30](https://github.com/litentry/client-sdk/blob/develop/lib/requests/remark.request.ts#L30) + +___ + ### requestBatchVC ▸ **requestBatchVC**(`api`, `data`): `Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }, `subscribeFn?`: (`error`: `Error` \| ``null``, `data`: \{ `index`: `number` ; `partialResult`: `WorkerRpcReturnValue`[] ; `vcPayload`: `Uint8Array` }) => `void`) => `Promise`\<\{ `response`: `WorkerRpcReturnValue`[] ; `txHash`: `string` ; `vcPayloads`: (`Uint8Array` \| `Error`)[] }\> ; `txHash`: `string` }\> @@ -219,6 +341,31 @@ The information about available assertions and their payload can be found in the ___ +### requestVerificationCode + +▸ **requestVerificationCode**(`api`, `«destructured»`): `Promise`\<\{ `success`: `boolean` }\> + +Request email verification code. + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `api` | `ApiPromise` | +| `«destructured»` | `Object` | +| › `email` | `string` | +| › `omniAccount` | \`0x$\{string}\` | + +#### Returns + +`Promise`\<\{ `success`: `boolean` }\> + +#### Defined in + +[lib/requests/request-verification-code.request.ts:9](https://github.com/litentry/client-sdk/blob/develop/lib/requests/request-verification-code.request.ts#L9) + +___ + ### setIdentityNetworks ▸ **setIdentityNetworks**(`api`, `data`): `Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> @@ -244,3 +391,83 @@ It allows to change the list of `networks` for an already linked web3 identity. #### Defined in [lib/requests/set-identity-networks.request.ts:26](https://github.com/litentry/client-sdk/blob/develop/lib/requests/set-identity-networks.request.ts#L26) + +___ + +### transferEthereum + +▸ **transferEthereum**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +Transfers Ethereum to another account on the Litentry Parachain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.amount` | `bigint` | Amount to send | +| `data.omniAccount` | `LitentryIdentity` | The user's omniAccount. Use `createLitentryIdentityType` helper to create this struct | +| `data.to` | `string` | Ethereum address destination | +| `data.who` | `LitentryIdentity` | The user's account. Use `createLitentryIdentityType` helper to create this struct | + +#### Returns + +`Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +- A promise that resolves to an object containing the payload to signature +(if applicable) and a send function. + +[payloadToSign] - The payload to sign if who is not an email identity. + +send - A function to send the request to the Enclave. + +send.args - The arguments required to send the request. + +send.args.authentication - The authentication string. If who is +an email identity, this is the email verification code. If the who is not an email identity, +this is the signed payload. + +#### Defined in + +[lib/requests/transfer-ethereum.request.ts:30](https://github.com/litentry/client-sdk/blob/develop/lib/requests/transfer-ethereum.request.ts#L30) + +___ + +### transferNative + +▸ **transferNative**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +Transfers native tokens to another account on the Litentry Parachain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.amount` | `bigint` | Amount to send | +| `data.omniAccount` | `LitentryIdentity` | The user's omniAccount. Use `createLitentryIdentityType` helper to create this struct | +| `data.to` | `string` | Account destination in hex or ss58 formatted address | +| `data.who` | `LitentryIdentity` | The user's account. Use `createLitentryIdentityType` helper to create this struct | + +#### Returns + +`Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +- A promise that resolves to an object containing the payload to sign +(if applicable) and a send function. + +[payloadToSign] - The payload to sign if who is not an email identity. + +send - A function to send the request to the Enclave. + +send.args - The arguments required to send the request. + +send.args.authentication - The authentication string. If who is +an email identity, this is the email verification code. If the who is not an email identity, +this is the signed payload. + +#### Defined in + +[lib/requests/transfer-native.request.ts:30](https://github.com/litentry/client-sdk/blob/develop/lib/requests/transfer-native.request.ts#L30) 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 7b05eb3aae..e23bc1e65e 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/package.json +++ b/tee-worker/identity/client-sdk/packages/client-sdk/package.json @@ -1,25 +1,25 @@ { - "name": "@litentry/client-sdk", - "description": "This package provides helpers for dApps to interact with the Litentry Protocol.", - "version": "1.0.0-next.4", - "license": "GPL-3.0-or-later", - "dependencies": {}, - "devDependencies": { - "@polkadot/rpc-provider": "^10.9.1" - }, - "peerDependencies": { - "@litentry/parachain-api": "0.9.20-next.8", - "@litentry/sidechain-api": "0.9.20-next.8", - "@litentry/chaindata": "*", - "@polkadot/api": "^10.9.1", - "@polkadot/types": "^10.9.1", - "@polkadot/types-codec": "^10.9.1", - "@polkadot/util": "^12.5.1", - "@polkadot/util-crypto": "^12.5.1", - "tslib": "^2.3.0" - }, - "type": "module", - "module": "./src/index.js", - "main": "./src/index.js", - "typings": "./src/index.d.ts" + "name": "@litentry/client-sdk", + "description": "This package provides helpers for dApps to interact with the Litentry Protocol.", + "version": "1.0.0-next.5", + "license": "GPL-3.0-or-later", + "dependencies": {}, + "devDependencies": { + "@polkadot/rpc-provider": "^10.9.1" + }, + "peerDependencies": { + "@litentry/parachain-api": "0.9.20-next.8", + "@litentry/sidechain-api": "0.9.20-next.8", + "@litentry/chaindata": "*", + "@polkadot/api": "^10.9.1", + "@polkadot/types": "^10.9.1", + "@polkadot/types-codec": "^10.9.1", + "@polkadot/util": "^12.5.1", + "@polkadot/util-crypto": "^12.5.1", + "tslib": "^2.3.0" + }, + "type": "module", + "module": "./src/index.js", + "main": "./src/index.js", + "typings": "./src/index.d.ts" } 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 index 686991bbb0..be37bdec6c 100644 --- 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 @@ -24,7 +24,7 @@ import type { U8aLike } from '@polkadot/util/types'; * @returns {string} [payloadToSign] - The payload to sign if who is not an email identity. * @returns {Function} send - A function to send the request to the Enclave. * @returns {Promise} send.args - The arguments required to send the request. - * @returns {string} send.args.authorization - The authentication string. If who is an + * @returns {string} send.args.authentication - The authentication string. If who is an * email identity, this is the email verification code. If the who is not an email identity, this * is the signed payload. */ @@ -43,7 +43,7 @@ export async function callEthereum( } ): Promise<{ payloadToSign?: string; - send: (args: { authorization: string }) => Promise<{ + send: (args: { authentication: string }) => Promise<{ response: WorkerRpcReturnValue; blockHash: string; extrinsicHash: string; @@ -72,7 +72,7 @@ export async function callEthereum( const nonce = await api.rpc.system.accountNextIndex(omniAccount.asSubstrate); const send = async (args: { - authorization: string; + authentication: string; }): Promise<{ response: WorkerRpcReturnValue; blockHash: string; @@ -81,8 +81,8 @@ export async function callEthereum( // prepare and encrypt request const request = await createRequestType(api, { - signer: who, - signature: args.authorization, + sender: who, + authentication: args.authentication, call, nonce, shard: shardU8, 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 index 8584888923..e0903d9633 100644 --- 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 @@ -69,8 +69,8 @@ export async function createAccountStore( // prepare and encrypt request const request = await createRequestType(api, { - signer: who, - signature: args.authentication, + sender: who, + authentication: args.authentication, call, nonce, shard: shardU8, diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/link-identity-callback.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/link-identity-callback.request.ts index ec21901981..9d2783580a 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/link-identity-callback.request.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/link-identity-callback.request.ts @@ -86,8 +86,8 @@ export async function linkIdentityCallback( }> => { // prepare and encrypt request const request = await createRequestType(api, { - signer, - signature: args.signedPayload, + sender: signer, + authentication: args.signedPayload, call, nonce, shard: shardU8, diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/link-identity.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/link-identity.request.ts index b91cd3601a..f342438263 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/link-identity.request.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/link-identity.request.ts @@ -131,8 +131,8 @@ export async function linkIdentity( }> => { // prepare and encrypt request const request = await createRequestType(api, { - signer: who, - signature: args.signedPayload, + sender: who, + authentication: args.signedPayload, call, nonce, shard: shardU8, 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 index f30b1b118e..0eccacebd9 100644 --- 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 @@ -77,8 +77,8 @@ export async function remark( // prepare and encrypt request const request = await createRequestType(api, { - signer: who, - signature: args.authentication, + sender: who, + authentication: args.authentication, call, nonce, shard: shardU8, diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/request-batch-vc.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/request-batch-vc.request.ts index 6988ee611e..58c8b073c2 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/request-batch-vc.request.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/request-batch-vc.request.ts @@ -112,8 +112,8 @@ export async function requestBatchVC( }> => { // prepare and encrypt request const requestPayload = await createRequestType(api, { - signer, - signature: args.signedPayload, + sender: signer, + authentication: args.signedPayload, call, nonce, shard: shardU8, diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/set-identity-networks.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/set-identity-networks.request.ts index 32a6213336..1fb00eb986 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/set-identity-networks.request.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/set-identity-networks.request.ts @@ -79,8 +79,8 @@ export async function setIdentityNetworks( }> => { // prepare and encrypt request const requestPayload = await createRequestType(api, { - signer: who, - signature: args.signedPayload, + sender: who, + authentication: args.signedPayload, call, nonce, shard: shardU8, 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 index 15218a1e73..d5b790fbb2 100644 --- 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 @@ -80,8 +80,8 @@ export async function transferEthereum( // prepare and encrypt request const request = await createRequestType(api, { - signer: who, - signature: args.authentication, + sender: who, + authentication: args.authentication, call, nonce, shard: shardU8, 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 index 02cfdbe5e4..4350ccbaaa 100644 --- 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 @@ -80,8 +80,8 @@ export async function transferNative( // prepare and encrypt request const request = await createRequestType(api, { - signer: who, - signature: args.authentication, + sender: who, + authentication: args.authentication, call, nonce, shard: shardU8, 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 c5685401e0..1b7a1db2f9 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 @@ -9,6 +9,7 @@ import type { LitentryIdentity, AesRequest, AesOutput, + TCAuthentication, } from '@litentry/parachain-api'; import { encrypt, @@ -18,6 +19,7 @@ import { } from '../util/shielding-key'; import { createKeyAesOutputType } from './key-aes-output'; import { createLitentryMultiSignature } from './litentry-multi-signature'; +import { createTCAuthenticationType } from './tc-authentication'; /** * Creates a Request struct type for the `TrustedCall` operation. @@ -30,33 +32,31 @@ import { createLitentryMultiSignature } from './litentry-multi-signature'; export async function createRequestType( api: ApiPromise, data: { - signer: LitentryIdentity; - signature: string; + sender: LitentryIdentity; + /** signature or verification code based on the identity type */ + authentication: string; call: TrustedCall; nonce: Index; shard: Uint8Array; } ): Promise { - const { signer, shard, signature: signedPayload, nonce, call } = data; + const { sender, shard, authentication, nonce, call } = data; // generate ephemeral shielding key to encrypt the operation const encryptionKey = await generate(); const encryptionKeyU8 = await exportKey(encryptionKey); - const signature = createLitentryMultiSignature(api.registry, { - who: signer, - signature: signedPayload, - }); - let operationU8a = new Uint8Array(); if (isNativeRequest(call)) { const callAuthenticated = api.createType('TrustedCallAuthenticated', { call, nonce, - authentication: api.createType('TCAuthentication', { - [signer.isEmail ? 'Email' : 'Web3']: signature, - }), + authentication: createAuthenticationForSender( + api, + sender, + authentication + ), }); const operation = api.createType('TrustedOperationAuthenticated', { @@ -68,7 +68,10 @@ export async function createRequestType( const signedCall = api.createType('TrustedCallSigned', { call, index: nonce, - signature: signature, + signature: createLitentryMultiSignature(api.registry, { + who: sender, + signature: authentication, + }), }); const operation = api.createType('TrustedOperation', { @@ -110,3 +113,21 @@ export async function createRequestType( function isNativeRequest(call: TrustedCall): boolean { return call.isRequestIntent || call.isCreateAccountStore; } + +function createAuthenticationForSender( + api: ApiPromise, + signer: LitentryIdentity, + authentication: string +): TCAuthentication { + if (signer.isEmail) { + return createTCAuthenticationType(api.registry, { + type: 'Email', + verificationCode: authentication, + }); + } + return createTCAuthenticationType(api.registry, { + type: 'Web3', + signer, + signature: authentication, + }); +} diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/tc-authentication.test.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/tc-authentication.test.ts index ef291030c4..f21c460cfa 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/tc-authentication.test.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/tc-authentication.test.ts @@ -3,7 +3,6 @@ import { TypeRegistry } from '@polkadot/types'; import { trusted_operations, identity } from '@litentry/parachain-api'; import { createTCAuthenticationType } from './tc-authentication'; import { createLitentryIdentityType } from './litentry-identity'; -import { createLitentryMultiSignature } from './litentry-multi-signature'; describe('createTCAuthenticationType', () => { const types = { @@ -31,25 +30,22 @@ describe('createTCAuthenticationType', () => { }); it('creates Web3 authentication', () => { - const who = createLitentryIdentityType(registry, { + const signer = createLitentryIdentityType(registry, { type: 'Substrate', addressOrHandle: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', }); - const signatureString = '0x' + '12'.repeat(64); - const signature = createLitentryMultiSignature(registry, { - who, - signature: signatureString, - }); + const signature = '0x' + '12'.repeat(64); const web3TCAuthentication = createTCAuthenticationType(registry, { type: 'Web3', - signature: signature.toHex(), + signer, + signature, }); expect(web3TCAuthentication).toBeDefined(); expect(web3TCAuthentication.isWeb3).toEqual(true); expect(web3TCAuthentication.asWeb3.toHuman()).toEqual({ - Sr25519: signatureString, + Sr25519: signature, }); }); }); diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/tc-authentication.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/tc-authentication.ts index 2fbfe9d646..ac47c98406 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/tc-authentication.ts +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/tc-authentication.ts @@ -1,5 +1,6 @@ -import { TCAuthentication } from '@litentry/parachain-api'; +import { LitentryIdentity, TCAuthentication } from '@litentry/parachain-api'; import { Registry } from '@polkadot/types-codec/types'; +import { createLitentryMultiSignature } from './litentry-multi-signature'; type AuthenticationData = | { @@ -8,6 +9,7 @@ type AuthenticationData = } | { type: 'Web3'; + signer: LitentryIdentity; signature: string; }; @@ -16,6 +18,12 @@ export function createTCAuthenticationType( data: AuthenticationData ): TCAuthentication { return registry.createType('TCAuthentication', { - [data.type]: data.type === 'Email' ? data.verificationCode : data.signature, + [data.type]: + data.type === 'Email' + ? data.verificationCode + : createLitentryMultiSignature(registry, { + who: data.signer, + signature: data.signature, + }), }); }