From bc3537ef79b3fd3d131a7a9f537c753b689718de Mon Sep 17 00:00:00 2001 From: "will.li" <120463031+higherordertech@users.noreply.github.com> Date: Sun, 22 Dec 2024 20:20:17 +1100 Subject: [PATCH] feat: P-1221 supported new omni account api in client-sdk (#3208) * feat: P-1221 supported new omni account api in client-sdk: add_account, remove_accounts, publicize_account * feat: P-1221 update client-sdk api to fit the trusted call definition --------- Co-authored-by: higherordertech --- .../packages/client-sdk/docs/README.md | 79 +++- .../client-sdk/docs/classes/Enclave.md | 6 +- .../client-sdk/docs/modules/request.md | 442 +++++++++++------- .../src/lib/requests/add-account.request.ts | 130 ++++++ .../client-sdk/src/lib/requests/index.ts | 3 + .../lib/requests/publicize-account.request.ts | 121 +++++ .../lib/requests/remove-accounts.request.ts | 123 +++++ .../src/lib/type-creators/trusted-call.ts | 102 ++++ 8 files changed, 827 insertions(+), 179 deletions(-) create mode 100644 tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/add-account.request.ts create mode 100644 tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/publicize-account.request.ts create mode 100644 tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/remove-accounts.request.ts 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 a1c8e4c65d..f147bdf3f3 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 @@ -335,7 +335,7 @@ Heads-up: ensure data.ciphertext is in hex format. Using Uint may cause a bytes | Name | Type | | :------ | :------ | | `registry` | `Registry` | -| `data` | \`0x$\{string}\` \| \{ `aad`: \`0x$\{string}\` \| `Uint8Array` ; `ciphertext`: \`0x$\{string}\` ; `nonce`: \`0x$\{string}\` \| `Uint8Array` } | +| `data` | \`0x$\{string}\` \| \{ `aad`: \`0x$\{string}\` \| `Uint8Array`\<`ArrayBufferLike`\> ; `ciphertext`: \`0x$\{string}\` ; `nonce`: \`0x$\{string}\` \| `Uint8Array`\<`ArrayBufferLike`\> } | #### Returns @@ -382,7 +382,7 @@ For Substrate, the address is expected to be a SS58-encoded or hex-encoded addre | Name | Type | | :------ | :------ | | `registry` | `Registry` | -| `data` | \`0x$\{string}\` \| `Uint8Array` \| \{ `addressOrHandle`: `string` ; `type`: ``"Solana"`` \| ``"Twitter"`` \| ``"Discord"`` \| ``"Github"`` \| ``"Substrate"`` \| ``"Evm"`` \| ``"Bitcoin"`` \| ``"Email"`` } | +| `data` | \`0x$\{string}\` \| `Uint8Array`\<`ArrayBufferLike`\> \| \{ `addressOrHandle`: `string` ; `type`: ``"Solana"`` \| ``"Twitter"`` \| ``"Discord"`` \| ``"Github"`` \| ``"Substrate"`` \| ``"Evm"`` \| ``"Bitcoin"`` \| ``"Email"`` } | #### Returns @@ -441,7 +441,6 @@ The proof to pass depends on the identity network (IIdentityType): **`Example`** -Web3 ```ts import { createLitentryValidationDataType } from '@litentry/client-sdk'; import type { Web3Proof } from '@litentry/client-sdk'; @@ -465,7 +464,6 @@ const validationData = createLitentryValidationDataType( **`Example`** -Twitter ```ts import { createLitentryValidationDataType } from '@litentry/client-sdk'; import type { TwitterProof } from '@litentry/client-sdk'; @@ -514,7 +512,7 @@ The shielding key is encrypted using the Enclave's shielding key and attached in | `data.call` | `TrustedCall` | - | | `data.nonce` | `Index` | - | | `data.sender` | `LitentryIdentity` | - | -| `data.shard` | `Uint8Array` | - | +| `data.shard` | `Uint8Array`\<`ArrayBufferLike`\> | - | #### Returns @@ -578,7 +576,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:90](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L90) +[lib/type-creators/trusted-call.ts:110](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L110) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -597,7 +595,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:97](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L97) +[lib/type-creators/trusted-call.ts:117](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L117) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -616,7 +614,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:104](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L104) +[lib/type-creators/trusted-call.ts:124](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L124) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -635,7 +633,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:111](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L111) +[lib/type-creators/trusted-call.ts:131](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L131) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -654,7 +652,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:118](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L118) +[lib/type-creators/trusted-call.ts:138](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L138) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -673,7 +671,64 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:125](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L125) +[lib/type-creators/trusted-call.ts:145](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L145) + +▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `registry` | `Registry` | +| `data` | `Object` | +| `data.method` | ``"add_account"`` | +| `data.params` | `RequestAddAccountParams` | + +#### Returns + +`Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> + +#### Defined in + +[lib/type-creators/trusted-call.ts:152](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L152) + +▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `registry` | `Registry` | +| `data` | `Object` | +| `data.method` | ``"remove_accounts"`` | +| `data.params` | `RequestRemoveAccountsParams` | + +#### Returns + +`Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> + +#### Defined in + +[lib/type-creators/trusted-call.ts:159](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L159) + +▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `registry` | `Registry` | +| `data` | `Object` | +| `data.method` | ``"publicize_account"`` | +| `data.params` | `RequestPublicizeAccountParams` | + +#### Returns + +`Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> + +#### Defined in + +[lib/type-creators/trusted-call.ts:166](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L166) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -692,7 +747,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:132](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L132) +[lib/type-creators/trusted-call.ts:173](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L173) ___ diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/docs/classes/Enclave.md b/tee-worker/identity/client-sdk/packages/client-sdk/docs/classes/Enclave.md index cc7dca4e74..49aa9abbe6 100644 --- a/tee-worker/identity/client-sdk/packages/client-sdk/docs/classes/Enclave.md +++ b/tee-worker/identity/client-sdk/packages/client-sdk/docs/classes/Enclave.md @@ -102,7 +102,7 @@ ___ ### encrypt -▸ **encrypt**(`api`, `args`): `Promise`\<\{ `ciphertext`: `Uint8Array` }\> +▸ **encrypt**(`api`, `args`): `Promise`\<\{ `ciphertext`: `Uint8Array`\<`ArrayBufferLike`\> }\> #### Parameters @@ -110,11 +110,11 @@ ___ | :------ | :------ | | `api` | `ApiPromise` | | `args` | `Object` | -| `args.cleartext` | `Uint8Array` | +| `args.cleartext` | `Uint8Array`\<`ArrayBufferLike`\> | #### Returns -`Promise`\<\{ `ciphertext`: `Uint8Array` }\> +`Promise`\<\{ `ciphertext`: `Uint8Array`\<`ArrayBufferLike`\> }\> #### Defined in 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 d12b08f6c5..ccb49ea0e0 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,47 +8,89 @@ 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) -- [transferSolana](request.md#transfersolana) +- [addAccount](request.md#addaccount) +- [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) +- [publicizeAccount](request.md#publicizeaccount) +- [remark](request.md#remark) +- [removeAccounts](request.md#removeaccounts) +- [requestBatchVC](request.md#requestbatchvc) +- [requestVerificationCode](request.md#requestverificationcode) +- [setIdentityNetworks](request.md#setidentitynetworks) +- [transferEthereum](request.md#transferethereum) +- [transferNative](request.md#transfernative) +- [transferSolana](request.md#transfersolana) ## Functions +### addAccount + +▸ **addAccount**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +Adds an account to the Litentry Parachain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.identity` | `LitentryIdentity` | Account to be added. Use `createCorePrimitivesIdentityType` helper to create this struct | +| `data.isPublic` | `boolean` | Whether the account is public | +| `data.validation` | `LitentryValidationData` | The ownership proof. Use `createLitentryValidationDataType` 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 who is not an email identity, this is the +signed payload. + +#### Defined in + +[lib/requests/add-account.request.ts:31](https://github.com/litentry/client-sdk/blob/develop/lib/requests/add-account.request.ts#L31) + +___ + ### callEthereum -▸ **callEthereum**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> +▸ **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 | +| 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 | +| `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` }\> }\> +`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. +- 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. @@ -64,28 +106,28 @@ is the signed payload. [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` }\> }\> +▸ **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` | - | +| 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 | +| `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` }\> }\> +`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. +- 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. @@ -101,7 +143,7 @@ signed payload. [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 @@ -123,14 +165,14 @@ Otherwise, it will be returned as a hex string. #### Parameters -| Name | Type | Description | -| :------------------ | :----------------- | :----------------------------------------------------------------------------------------- | -| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | -| `args` | `Object` | - | -| `args.identity` | `LitentryIdentity` | Identity to be linked. Use `createCorePrimitivesIdentityType` helper to create this struct | -| `args.who` | `LitentryIdentity` | The user's account. Use `createCorePrimitivesIdentityType` helper to create this struct | -| `options` | `Object` | - | -| `options.prettify?` | `boolean` | - | +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `args` | `Object` | - | +| `args.identity` | `LitentryIdentity` | Identity to be linked. Use `createCorePrimitivesIdentityType` helper to create this struct | +| `args.who` | `LitentryIdentity` | The user's account. Use `createCorePrimitivesIdentityType` helper to create this struct | +| `options` | `Object` | - | +| `options.prettify?` | `boolean` | - | #### Returns @@ -140,107 +182,107 @@ Otherwise, it will be returned as a hex string. [lib/requests/link-identity.request.ts:39](https://github.com/litentry/client-sdk/blob/develop/lib/requests/link-identity.request.ts#L39) ---- +___ ### getIdGraph -▸ **getIdGraph**(`api`, `data`): `Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraph`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` }\> }\> +▸ **getIdGraph**(`api`, `data`): `Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraph`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` }\> }\> #### Parameters -| Name | Type | Description | -| :--------- | :----------------- | :-------------------------------------------------------------------------------- | -| `api` | `ApiPromise` | - | -| `data` | `Object` | - | +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | - | +| `data` | `Object` | - | | `data.who` | `LitentryIdentity` | The user's account. Use `createLitentryIdentityType` helper to create this struct | #### Returns -`Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraph`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` }\> }\> +`Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraph`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` }\> }\> #### Defined in [lib/requests/get-id-graph.request.ts:14](https://github.com/litentry/client-sdk/blob/develop/lib/requests/get-id-graph.request.ts#L14) ---- +___ ### getIdGraphHash -▸ **getIdGraphHash**(`api`, `«destructured»`): `Promise`\<`H256` \| `null`\> +▸ **getIdGraphHash**(`api`, `«destructured»`): `Promise`\<`H256` \| ``null``\> Retrieve the idGraphHash for a given identity. #### Parameters -| Name | Type | -| :--------------- | :----------------- | -| `api` | `ApiPromise` | -| `«destructured»` | `Object` | -| › `who` | `LitentryIdentity` | +| Name | Type | +| :------ | :------ | +| `api` | `ApiPromise` | +| `«destructured»` | `Object` | +| › `who` | `LitentryIdentity` | #### Returns -`Promise`\<`H256` \| `null`\> +`Promise`\<`H256` \| ``null``\> #### Defined in [lib/requests/get-id-graph-hash.ts:13](https://github.com/litentry/client-sdk/blob/develop/lib/requests/get-id-graph-hash.ts#L13) ---- +___ ### getLastRegisteredEnclave -▸ **getLastRegisteredEnclave**(`api`, `workerType?`): `Promise`\<\{ `account`: `AccountId32` ; `enclave`: `CorePrimitivesTeebagTypesEnclave` }\> +▸ **getLastRegisteredEnclave**(`api`, `workerType?`): `Promise`\<\{ `account`: `AccountId32` ; `enclave`: `CorePrimitivesTeebagTypesEnclave` }\> Return the Enclave registry information of the latest registered TEE worker. #### Parameters -| Name | Type | Default value | -| :----------- | :------------------------------------------------ | :------------ | -| `api` | `ApiPromise` | `undefined` | -| `workerType` | `"Identity"` \| `"BitAcross"` \| `"OmniExecutor"` | `'Identity'` | +| Name | Type | Default value | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | `undefined` | +| `workerType` | ``"Identity"`` \| ``"BitAcross"`` \| ``"OmniExecutor"`` | `'Identity'` | #### Returns -`Promise`\<\{ `account`: `AccountId32` ; `enclave`: `CorePrimitivesTeebagTypesEnclave` }\> +`Promise`\<\{ `account`: `AccountId32` ; `enclave`: `CorePrimitivesTeebagTypesEnclave` }\> #### Defined in [lib/requests/get-last-registered-enclave.ts:11](https://github.com/litentry/client-sdk/blob/develop/lib/requests/get-last-registered-enclave.ts#L11) ---- +___ ### linkIdentity -▸ **linkIdentity**(`api`, `data`): `Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> +▸ **linkIdentity**(`api`, `data`): `Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> Link an identity to the user's account. #### Parameters -| Name | Type | Description | -| :---------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------- | -| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | -| `data` | `Object` | - | -| `data.identity` | `LitentryIdentity` | Identity to be linked. Use `createCorePrimitivesIdentityType` helper to create this struct | -| `data.networks` | (`"Polkadot"` \| `"Kusama"` \| `"Litentry"` \| `"Litmus"` \| `"LitentryRococo"` \| `"Khala"` \| `"SubstrateTestnet"` \| `"Ethereum"` \| `"Bsc"` \| `"BitcoinP2tr"` \| `"BitcoinP2pkh"` \| `"BitcoinP2sh"` \| `"BitcoinP2wpkh"` \| `"BitcoinP2wsh"` \| `"Polygon"` \| `"Arbitrum"` \| `"Solana"` \| `"Combo"`)[] | The networks to link the identity to, for web3 accounts | -| `data.validation` | `LitentryValidationData` | The ownership proof. Use `createLitentryValidationDataType` helper to create this struct | -| `data.who` | `LitentryIdentity` | The prime identity. Use `createCorePrimitivesIdentityType` helper to create this struct | +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.identity` | `LitentryIdentity` | Identity to be linked. Use `createCorePrimitivesIdentityType` helper to create this struct | +| `data.networks` | (``"Polkadot"`` \| ``"Kusama"`` \| ``"Litentry"`` \| ``"Litmus"`` \| ``"LitentryRococo"`` \| ``"Khala"`` \| ``"SubstrateTestnet"`` \| ``"Ethereum"`` \| ``"Bsc"`` \| ``"BitcoinP2tr"`` \| ``"BitcoinP2pkh"`` \| ``"BitcoinP2sh"`` \| ``"BitcoinP2wpkh"`` \| ``"BitcoinP2wsh"`` \| ``"Polygon"`` \| ``"Arbitrum"`` \| ``"Solana"`` \| ``"Combo"``)[] | The networks to link the identity to, for web3 accounts | +| `data.validation` | `LitentryValidationData` | The ownership proof. Use `createLitentryValidationDataType` helper to create this struct | +| `data.who` | `LitentryIdentity` | The prime identity. Use `createCorePrimitivesIdentityType` helper to create this struct | #### Returns -`Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> +`Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> #### Defined in [lib/requests/link-identity.request.ts:75](https://github.com/litentry/client-sdk/blob/develop/lib/requests/link-identity.request.ts#L75) ---- +___ ### linkIdentityCallback -▸ **linkIdentityCallback**(`api`, `data`): `Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> +▸ **linkIdentityCallback**(`api`, `data`): `Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> (internal) Link an identity to the user's account. @@ -249,47 +291,82 @@ are used as the signer. #### Parameters -| Name | Type | Description | -| :--------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------- | -| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | -| `data` | `Object` | - | -| `data.identity` | `LitentryIdentity` | Identity to be linked. Use `createCorePrimitivesIdentityType` helper to create this struct | -| `data.networks?` | (`"Polkadot"` \| `"Kusama"` \| `"Litentry"` \| `"Litmus"` \| `"LitentryRococo"` \| `"Khala"` \| `"SubstrateTestnet"` \| `"Ethereum"` \| `"Bsc"` \| `"BitcoinP2tr"` \| `"BitcoinP2pkh"` \| `"BitcoinP2sh"` \| `"BitcoinP2wpkh"` \| `"BitcoinP2wsh"` \| `"Polygon"` \| `"Arbitrum"` \| `"Solana"` \| `"Combo"`)[] | The networks to link the identity to, for web3 accounts | -| `data.signer` | `LitentryIdentity` | The signer. Use `createCorePrimitivesIdentityType` helper to create this struct | -| `data.who` | `LitentryIdentity` | The prime identity. Use `createCorePrimitivesIdentityType` helper to create this struct | +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.identity` | `LitentryIdentity` | Identity to be linked. Use `createCorePrimitivesIdentityType` helper to create this struct | +| `data.networks?` | (``"Polkadot"`` \| ``"Kusama"`` \| ``"Litentry"`` \| ``"Litmus"`` \| ``"LitentryRococo"`` \| ``"Khala"`` \| ``"SubstrateTestnet"`` \| ``"Ethereum"`` \| ``"Bsc"`` \| ``"BitcoinP2tr"`` \| ``"BitcoinP2pkh"`` \| ``"BitcoinP2sh"`` \| ``"BitcoinP2wpkh"`` \| ``"BitcoinP2wsh"`` \| ``"Polygon"`` \| ``"Arbitrum"`` \| ``"Solana"`` \| ``"Combo"``)[] | The networks to link the identity to, for web3 accounts | +| `data.signer` | `LitentryIdentity` | The signer. Use `createCorePrimitivesIdentityType` helper to create this struct | +| `data.who` | `LitentryIdentity` | The prime identity. Use `createCorePrimitivesIdentityType` helper to create this struct | #### Returns -`Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> +`Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> #### Defined in [lib/requests/link-identity-callback.request.ts:28](https://github.com/litentry/client-sdk/blob/develop/lib/requests/link-identity-callback.request.ts#L28) ---- +___ + +### publicizeAccount + +▸ **publicizeAccount**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +Publicizes a member account in the AccountStore on the Litentry Parachain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.identity` | `LitentryIdentity` | The member account for publicizing. 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 the identity is not an email. + +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. For email identities, this is the verification code. For non-email identities, this is the signed payload. + +#### Defined in + +[lib/requests/publicize-account.request.ts:28](https://github.com/litentry/client-sdk/blob/develop/lib/requests/publicize-account.request.ts#L28) + +___ ### remark -▸ **remark**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> +▸ **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 | +| 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 | +| `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` }\> }\> +`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. +- 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. @@ -305,11 +382,48 @@ this is the signed payload. [lib/requests/remark.request.ts:30](https://github.com/litentry/client-sdk/blob/develop/lib/requests/remark.request.ts#L30) ---- +___ + +### removeAccounts + +▸ **removeAccounts**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> + +Removes accounts from the Litentry Parachain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.identities` | `LitentryIdentity`[] | Accounts for removing | +| `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 who is not an email identity, this is the +signed payload. + +#### Defined in + +[lib/requests/remove-accounts.request.ts:30](https://github.com/litentry/client-sdk/blob/develop/lib/requests/remove-accounts.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` }\> +▸ **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` }\> Request a Batch of Verifiable Credential (VC) from the Litentry Protocol. @@ -324,52 +438,52 @@ The information about available assertions and their payload can be found in the #### Parameters -| Name | Type | Description | -| :---------------- | :----------------- | :---------------------------------------------------------------------------------- | -| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | -| `data` | `Object` | - | -| `data.assertions` | `Assertion`[] | the assertions to be claimed. See `Assertion` type | -| `data.signer?` | `LitentryIdentity` | The signer's account. Use `createLitentryIdentityType` helper to create this struct | -| `data.who` | `LitentryIdentity` | The user's account. Use `createLitentryIdentityType` helper to create this struct | +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.assertions` | `Assertion`[] | the assertions to be claimed. See `Assertion` type | +| `data.signer?` | `LitentryIdentity` | The signer's account. 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`: \{ `signedPayload`: `string` }, `subscribeFn?`: (`error`: `Error` \| `null`, `data`: \{ `index`: `number` ; `partialResult`: `WorkerRpcReturnValue`[] ; `vcPayload`: `Uint8Array` }) => `void`) => `Promise`\<\{ `response`: `WorkerRpcReturnValue`[] ; `txHash`: `string` ; `vcPayloads`: (`Uint8Array` \| `Error`)[] }\> ; `txHash`: `string` }\> +`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` }\> #### Defined in [lib/requests/request-batch-vc.request.ts:35](https://github.com/litentry/client-sdk/blob/develop/lib/requests/request-batch-vc.request.ts#L35) ---- +___ ### requestVerificationCode -▸ **requestVerificationCode**(`api`, `«destructured»`): `Promise`\<\{ `success`: `boolean` }\> +▸ **requestVerificationCode**(`api`, `«destructured»`): `Promise`\<\{ `success`: `boolean` }\> Request email verification code. #### Parameters -| Name | Type | -| :--------------- | :--------------- | -| `api` | `ApiPromise` | -| `«destructured»` | `Object` | -| › `email` | `string` | -| › `omniAccount` | \`0x$\{string}\` | +| Name | Type | +| :------ | :------ | +| `api` | `ApiPromise` | +| `«destructured»` | `Object` | +| › `email` | `string` | +| › `omniAccount` | \`0x$\{string}\` | #### Returns -`Promise`\<\{ `success`: `boolean` }\> +`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` }\> +▸ **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` }\> Set the networks for a Web3 Identity. @@ -377,47 +491,47 @@ It allows to change the list of `networks` for an already linked web3 identity. #### Parameters -| Name | Type | Description | -| :-------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------- | -| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | -| `data` | `Object` | - | -| `data.identity` | `LitentryIdentity` | Identity to be modified. Use `createLitentryIdentityType` helper to create this struct | -| `data.networks` | (`"Polkadot"` \| `"Kusama"` \| `"Litentry"` \| `"Litmus"` \| `"LitentryRococo"` \| `"Khala"` \| `"SubstrateTestnet"` \| `"Ethereum"` \| `"Bsc"` \| `"BitcoinP2tr"` \| `"BitcoinP2pkh"` \| `"BitcoinP2sh"` \| `"BitcoinP2wpkh"` \| `"BitcoinP2wsh"` \| `"Polygon"` \| `"Arbitrum"` \| `"Solana"` \| `"Combo"`)[] | Networks to be set | -| `data.who` | `LitentryIdentity` | The user's account. Use `createLitentryIdentityType` helper to create this struct | +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.identity` | `LitentryIdentity` | Identity to be modified. Use `createLitentryIdentityType` helper to create this struct | +| `data.networks` | (``"Polkadot"`` \| ``"Kusama"`` \| ``"Litentry"`` \| ``"Litmus"`` \| ``"LitentryRococo"`` \| ``"Khala"`` \| ``"SubstrateTestnet"`` \| ``"Ethereum"`` \| ``"Bsc"`` \| ``"BitcoinP2tr"`` \| ``"BitcoinP2pkh"`` \| ``"BitcoinP2sh"`` \| ``"BitcoinP2wpkh"`` \| ``"BitcoinP2wsh"`` \| ``"Polygon"`` \| ``"Arbitrum"`` \| ``"Solana"`` \| ``"Combo"``)[] | Networks to be set | +| `data.who` | `LitentryIdentity` | The user's account. Use `createLitentryIdentityType` helper to create this struct | #### Returns -`Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> +`Promise`\<\{ `payloadToSign`: `string` ; `send`: (`args`: \{ `signedPayload`: `string` }) => `Promise`\<\{ `idGraphHash`: \`0x$\{string}\` ; `mutatedIdentities`: [`IdGraph`](../README.md#idgraph) ; `response`: `WorkerRpcReturnValue` ; `txHash`: `string` }\> ; `txHash`: `string` }\> #### 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` }\> }\> +▸ **transferEthereum**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> Transfers ETH to another account on Ethereum. #### Parameters -| Name | Type | Description | -| :----------------- | :----------------- | :------------------------------------------------------------------------------------ | -| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | -| `data` | `Object` | - | -| `data.amount` | `bigint` | Amount to send | +| 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 | +| `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` }\> }\> +`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. +- 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. @@ -433,31 +547,31 @@ this is the signed payload. [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` }\> }\> +▸ **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 | +| 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 | +| `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` }\> }\> +`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. +- 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. @@ -473,31 +587,31 @@ this is the signed payload. [lib/requests/transfer-native.request.ts:30](https://github.com/litentry/client-sdk/blob/develop/lib/requests/transfer-native.request.ts#L30) ---- +___ ### transferSolana -▸ **transferSolana**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> +▸ **transferSolana**(`api`, `data`): `Promise`\<\{ `payloadToSign?`: `string` ; `send`: (`args`: \{ `authentication`: `string` }) => `Promise`\<\{ `blockHash`: `string` ; `extrinsicHash`: `string` ; `response`: `WorkerRpcReturnValue` }\> }\> Transfers SOL to another account on Solana. #### Parameters -| Name | Type | Description | -| :----------------- | :----------------- | :------------------------------------------------------------------------------------ | -| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | -| `data` | `Object` | - | -| `data.amount` | `bigint` | Amount to send in lamports | +| Name | Type | Description | +| :------ | :------ | :------ | +| `api` | `ApiPromise` | Litentry Parachain API instance from Polkadot.js | +| `data` | `Object` | - | +| `data.amount` | `bigint` | Amount to send in lamports | | `data.omniAccount` | `LitentryIdentity` | The user's omniAccount. Use `createLitentryIdentityType` helper to create this struct | -| `data.to` | `string` | Solana address destination | -| `data.who` | `LitentryIdentity` | The user's account. Use `createLitentryIdentityType` helper to create this struct | +| `data.to` | `string` | Solana 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` }\> }\> +`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. +- 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. diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/add-account.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/add-account.request.ts new file mode 100644 index 0000000000..ebc1b167f8 --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/add-account.request.ts @@ -0,0 +1,130 @@ +import { hexToU8a } from '@polkadot/util'; + +import type { ApiPromise } from '@polkadot/api'; +import type { + LitentryIdentity, + LitentryValidationData, + TrustedCallResult, + WorkerRpcReturnValue, +} from '@litentry/parachain-api'; + +import { enclave } from '../enclave'; +import { codecToString } from '../util/codec-to-string'; +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 { getEnclaveNonce } from './get-enclave-nonce'; + +/** + * Adds an account to the Litentry Parachain. + * + * @returns {Promise} - A promise that resolves to an object containing the payload to sign (if applicable) and a send function. + * @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.authentication - The authentication string. If who is + * an email identity, this is the email verification code. If who is not an email identity, this is the + * signed payload. + */ +export async function addAccount( + /** Litentry Parachain API instance from Polkadot.js */ + api: ApiPromise, + data: { + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + /** Account to be added. Use `createCorePrimitivesIdentityType` helper to create this struct */ + identity: LitentryIdentity; + /** The ownership proof. Use `createLitentryValidationDataType` helper to create this struct */ + validation: LitentryValidationData; + /** Whether the account is public */ + isPublic: boolean; + } +): Promise<{ + payloadToSign?: string; + send: (args: { authentication: string }) => Promise<{ + response: WorkerRpcReturnValue; + blockHash: string; + extrinsicHash: string; + }>; +}> { + const { who, identity, validation, isPublic } = data; + + const shard = await enclave.getShard(api); + const shardU8 = hexToU8a(shard); + const nonce = await getEnclaveNonce(api, { who }); + + const { call } = await createTrustedCallType(api.registry, { + method: 'add_account', + params: { + who, + identity, + validation, + isPublic, + }, + }); + + const send = async (args: { + authentication: string; + }): Promise<{ + response: WorkerRpcReturnValue; + blockHash: string; + extrinsicHash: string; + }> => { + // prepare and encrypt request + const request = await createRequestType(api, { + sender: who, + authentication: args.authentication, + call, + nonce, + shard: shardU8, + }); + + // send the request to the Enclave + const rpcRequest: JsonRpcRequest = { + jsonrpc: '2.0', + method: 'author_submitNativeRequest', + params: [request.toHex()], + }; + + const [response] = await enclave.send(api, rpcRequest); // we expect 1 response only + + const result: TrustedCallResult = api.createType( + 'TrustedCallResult', + response.value + ); + + if (result.isErr) { + throw new Error(codecToString(result.asErr)); + } + + if (!result.asOk.isExtrinsicReport) { + throw new Error('Unexpected response type'); + } + + const { extrinsic_hash, block_hash } = result.asOk.asExtrinsicReport; + + return { + response, + extrinsicHash: extrinsic_hash.toString(), + blockHash: block_hash.toString(), + }; + }; + + if (who.isEmail) { + return { send }; + } + + const payloadToSign = createPayloadToSign({ + who, + call, + nonce, + shard: shardU8, + }); + + return { + payloadToSign, + send, + }; +} 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 c0cf84c6ba..201f4e422a 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 @@ -9,6 +9,9 @@ export { callEthereum } from './call-ethereum.request'; export { transferSolana } from './transfer-solana.request'; export { createAccountStore } from './create-account-store.request'; +export { addAccount } from './add-account.request'; +export { publicizeAccount } from './publicize-account.request'; +export { removeAccounts } from './remove-accounts.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/publicize-account.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/publicize-account.request.ts new file mode 100644 index 0000000000..6c7c826a32 --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/publicize-account.request.ts @@ -0,0 +1,121 @@ +import { hexToU8a } from '@polkadot/util'; + +import type { ApiPromise } from '@polkadot/api'; +import type { + LitentryIdentity, + TrustedCallResult, + WorkerRpcReturnValue, +} from '@litentry/parachain-api'; + +import { enclave } from '../enclave'; +import { codecToString } from '../util/codec-to-string'; +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 { getEnclaveNonce } from './get-enclave-nonce'; + +/** + * Publicizes a member account in the AccountStore on the Litentry Parachain. + * + * @returns {Promise} A promise that resolves to an object containing the payload to sign (if applicable) and a send function. + * @returns {string} [payloadToSign] The payload to sign if the identity is not an email. + * @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.authentication The authentication string. For email identities, this is the verification code. For non-email identities, this is the signed payload. + */ +export async function publicizeAccount( + /** Litentry Parachain API instance from Polkadot.js */ + api: ApiPromise, + data: { + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + /** The member account for publicizing. Use `createLitentryIdentityType` helper to create this struct */ + identity: LitentryIdentity; + } +): Promise<{ + payloadToSign?: string; + send: (args: { authentication: string }) => Promise<{ + response: WorkerRpcReturnValue; + blockHash: string; + extrinsicHash: string; + }>; +}> { + const { who, identity } = data; + + const shard = await enclave.getShard(api); + const shardU8 = hexToU8a(shard); + const nonce = await getEnclaveNonce(api, { who }); + + const { call } = await createTrustedCallType(api.registry, { + method: 'publicize_account', + params: { + who, + identity, + }, + }); + + const send = async (args: { + authentication: string; + }): Promise<{ + response: WorkerRpcReturnValue; + blockHash: string; + extrinsicHash: string; + }> => { + // prepare and encrypt request + const request = await createRequestType(api, { + sender: who, + authentication: args.authentication, + call, + nonce, + shard: shardU8, + }); + + // send the request to the Enclave + const rpcRequest: JsonRpcRequest = { + jsonrpc: '2.0', + method: 'author_submitNativeRequest', + params: [request.toHex()], + }; + + const [response] = await enclave.send(api, rpcRequest); // we expect 1 response only + + const result: TrustedCallResult = api.createType( + 'TrustedCallResult', + response.value + ); + + if (result.isErr) { + throw new Error(codecToString(result.asErr)); + } + + if (!result.asOk.isExtrinsicReport) { + throw new Error('Unexpected response type'); + } + + const { extrinsic_hash, block_hash } = result.asOk.asExtrinsicReport; + + return { + response, + extrinsicHash: extrinsic_hash.toString(), + blockHash: block_hash.toString(), + }; + }; + + if (who.isEmail) { + return { send }; + } + + const payloadToSign = createPayloadToSign({ + who, + call, + nonce, + shard: shardU8, + }); + + return { + payloadToSign, + send, + }; +} diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/remove-accounts.request.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/remove-accounts.request.ts new file mode 100644 index 0000000000..9eb783287a --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/remove-accounts.request.ts @@ -0,0 +1,123 @@ +import { hexToU8a } from '@polkadot/util'; + +import type { ApiPromise } from '@polkadot/api'; +import type { + LitentryIdentity, + TrustedCallResult, + WorkerRpcReturnValue, +} from '@litentry/parachain-api'; + +import { enclave } from '../enclave'; +import { codecToString } from '../util/codec-to-string'; +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 { getEnclaveNonce } from './get-enclave-nonce'; + +/** + * Removes accounts from the Litentry Parachain. + * + * @returns {Promise} - A promise that resolves to an object containing the payload to sign (if applicable) and a send function. + * @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.authentication - The authentication string. If who is + * an email identity, this is the email verification code. If who is not an email identity, this is the + * signed payload. + */ +export async function removeAccounts( + /** Litentry Parachain API instance from Polkadot.js */ + api: ApiPromise, + data: { + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + /** Accounts for removing */ + identities: Array; + } +): Promise<{ + payloadToSign?: string; + send: (args: { authentication: string }) => Promise<{ + response: WorkerRpcReturnValue; + blockHash: string; + extrinsicHash: string; + }>; +}> { + const { who, identities } = data; + + const shard = await enclave.getShard(api); + const shardU8 = hexToU8a(shard); + const nonce = await getEnclaveNonce(api, { who }); + + const { call } = await createTrustedCallType(api.registry, { + method: 'remove_accounts', + params: { + who, + identities, + }, + }); + + const send = async (args: { + authentication: string; + }): Promise<{ + response: WorkerRpcReturnValue; + blockHash: string; + extrinsicHash: string; + }> => { + // prepare and encrypt request + const request = await createRequestType(api, { + sender: who, + authentication: args.authentication, + call, + nonce, + shard: shardU8, + }); + + // send the request to the Enclave + const rpcRequest: JsonRpcRequest = { + jsonrpc: '2.0', + method: 'author_submitNativeRequest', + params: [request.toHex()], + }; + + const [response] = await enclave.send(api, rpcRequest); // we expect 1 response only + + const result: TrustedCallResult = api.createType( + 'TrustedCallResult', + response.value + ); + + if (result.isErr) { + throw new Error(codecToString(result.asErr)); + } + + if (!result.asOk.isExtrinsicReport) { + throw new Error('Unexpected response type'); + } + + const { extrinsic_hash, block_hash } = result.asOk.asExtrinsicReport; + + return { + response, + extrinsicHash: extrinsic_hash.toString(), + blockHash: block_hash.toString(), + }; + }; + + if (who.isEmail) { + return { send }; + } + + const payloadToSign = createPayloadToSign({ + who, + call, + nonce, + shard: shardU8, + }); + + return { + payloadToSign, + send, + }; +} 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 661ea380bb..510b1e1fa1 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 @@ -77,6 +77,26 @@ type RequestCreateAccountStoreParams = { who: LitentryIdentity; }; +// LitentryIdentity, LitentryIdentity, LitentryValidationData, boolean +type RequestAddAccountParams = { + who: LitentryIdentity; + identity: LitentryIdentity; + validation: LitentryValidationData; + isPublic: boolean; +}; + +// LitentryIdentity, Array +type RequestRemoveAccountsParams = { + who: LitentryIdentity; + identities: Array; +}; + +// LitentryIdentity, LitentryIdentity +type RequestPublicizeAccountParams = { + who: LitentryIdentity; + identity: LitentryIdentity; +}; + /** * Creates the TrustedCall for the given method and provide the `param's` types expected for them. * @@ -129,6 +149,27 @@ export async function createTrustedCallType( params: RequestCreateAccountStoreParams; } ): Promise<{ call: TrustedCall; key: CryptoKey }>; +export async function createTrustedCallType( + registry: Registry, + data: { + method: 'add_account'; + params: RequestAddAccountParams; + } +): Promise<{ call: TrustedCall; key: CryptoKey }>; +export async function createTrustedCallType( + registry: Registry, + data: { + method: 'remove_accounts'; + params: RequestRemoveAccountsParams; + } +): Promise<{ call: TrustedCall; key: CryptoKey }>; +export async function createTrustedCallType( + registry: Registry, + data: { + method: 'publicize_account'; + params: RequestPublicizeAccountParams; + } +): Promise<{ call: TrustedCall; key: CryptoKey }>; export async function createTrustedCallType( registry: Registry, data: { @@ -270,6 +311,47 @@ export async function createTrustedCallType( return { call, key }; } + if (isRequestAddAccountParams(method, params)) { + const { who, identity, validation, isPublic } = params; + + + const call = registry.createType('TrustedCall', { + [trustedCallMethodsMap.add_account]: registry.createType( + trusted_operations.types.TrustedCall._enum.add_account, + [who, identity, validation, isPublic] + ), + }) as TrustedCall; + + return { call, key }; + } + + if (isRequestRemoveAccountsParams(method, params)) { + const { who, identities } = params; + + const identitiesVec = registry.createType('Vec', identities); + const call = registry.createType('TrustedCall', { + [trustedCallMethodsMap.remove_accounts]: registry.createType( + trusted_operations.types.TrustedCall._enum.remove_accounts, + [who, identitiesVec] + ), + }) as TrustedCall; + + return { call, key }; + } + + if (isRequestPublicizeAccountParams(method, params)) { + const { who, identity } = params; + + const call = registry.createType('TrustedCall', { + [trustedCallMethodsMap.publicize_account]: registry.createType( + trusted_operations.types.TrustedCall._enum.publicize_account, + [who, identity] + ), + }) as TrustedCall; + + return { call, key }; + } + throw new Error(`trusted call method: ${data.method} is not supported`); } @@ -316,3 +398,23 @@ function isRequestCreateAccountStoreParams( ): params is RequestCreateAccountStoreParams { return method === 'create_account_store'; } +function isRequestAddAccountParams( + method: TrustedCallMethod, + params: Record +): params is RequestAddAccountParams { + return method === 'add_account'; +} + +function isRequestRemoveAccountsParams( + method: TrustedCallMethod, + params: Record +): params is RequestRemoveAccountsParams { + return method === 'remove_accounts'; +} + +function isRequestPublicizeAccountParams( + method: TrustedCallMethod, + params: Record +): params is RequestPublicizeAccountParams { + return method === 'publicize_account'; +}