From 11da01efc6ae29bcf990d8904dca85d12ba60a18 Mon Sep 17 00:00:00 2001 From: higherordertech Date: Tue, 17 Dec 2024 18:05:46 +1100 Subject: [PATCH 1/2] feat: P-1221 supported new omni account api in client-sdk: add_account, remove_accounts, publicize_account --- .../packages/client-sdk/docs/README.md | 71 +++++++++- .../src/lib/requests/add-account.request.ts | 124 ++++++++++++++++++ .../lib/requests/publicize-account.request.ts | 122 +++++++++++++++++ .../lib/requests/remove-accounts.request.ts | 123 +++++++++++++++++ .../lib/type-creators/member-account.test.ts | 54 ++++++++ .../src/lib/type-creators/member-account.ts | 45 +++++++ .../src/lib/type-creators/trusted-call.ts | 99 ++++++++++++++ 7 files changed, 631 insertions(+), 7 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 create mode 100644 tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.test.ts create mode 100644 tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.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..a164620ff4 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 @@ -578,7 +578,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:109](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L109) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -597,7 +597,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:116](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L116) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -616,7 +616,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:123](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L123) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -635,7 +635,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:130](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L130) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -654,7 +654,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:137](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L137) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -673,7 +673,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:144](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L144) + +▸ **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:151](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L151) + +▸ **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:158](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L158) + +▸ **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:165](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L165) ▸ **createTrustedCallType**(`registry`, `data`): `Promise`\<\{ `call`: `TrustedCall` ; `key`: `CryptoKey` }\> @@ -692,7 +749,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:172](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L172) ___ 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..f491994512 --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/add-account.request.ts @@ -0,0 +1,124 @@ +import { hexToU8a } from '@polkadot/util'; + +import type { ApiPromise } from '@polkadot/api'; +import type { + LitentryIdentity, + MemberAccount, + 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 member account for adding. Use `createMemberAccountType` helper to create this struct */ + memberAccount: MemberAccount; + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + } +): Promise<{ + payloadToSign?: string; + send: (args: { authentication: string }) => Promise<{ + response: WorkerRpcReturnValue; + blockHash: string; + extrinsicHash: string; + }>; +}> { + const { who, memberAccount } = 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, + memberAccount + }, + }); + + 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/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..78839b34dd --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/requests/publicize-account.request.ts @@ -0,0 +1,122 @@ +import { hexToU8a } from '@polkadot/util'; + +import type { ApiPromise } from '@polkadot/api'; +import type { + LitentryIdentity, + MemberAccount, + 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 member account for publicizing. Use `createLitentryIdentityType` helper to create this struct */ + memberAccount: LitentryIdentity; + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + } +): Promise<{ + payloadToSign?: string; + send: (args: { authentication: string }) => Promise<{ + response: WorkerRpcReturnValue; + blockHash: string; + extrinsicHash: string; + }>; +}> { + const { who, memberAccount } = 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, + memberAccount + }, + }); + + 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..32de5eb5dd --- /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 remove_accounts( + /** Litentry Parachain API instance from Polkadot.js */ + api: ApiPromise, + data: { + /** Member accounts for removing */ + memberAccounts: Array<`0x${string}`>; + /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ + who: LitentryIdentity; + } +): Promise<{ + payloadToSign?: string; + send: (args: { authentication: string }) => Promise<{ + response: WorkerRpcReturnValue; + blockHash: string; + extrinsicHash: string; + }>; +}> { + const { who, memberAccounts } = 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, + memberAccounts + }, + }); + + 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/member-account.test.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.test.ts new file mode 100644 index 0000000000..8420b3e86a --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.test.ts @@ -0,0 +1,54 @@ +import { TypeRegistry } from '@polkadot/types'; +import { cryptoWaitReady } from '@polkadot/util-crypto'; + +import { identity, omniAccount } from '@litentry/parachain-api'; + +import { createMemberAccountType } from './member-account'; +import { createLitentryIdentityType } from './litentry-identity'; + +const types = { + ...identity.types, // LitentryIdentity is defined here + ...omniAccount.types, // MemberAccount is defined here +}; + +let registry: TypeRegistry; + + +beforeAll(async () => { + await cryptoWaitReady(); + + registry = new TypeRegistry(); + registry.register(types); +}); + +it('creates a public MemberAccount', () => { + const litentryIdentity = createLitentryIdentityType(registry, { + type: 'Substrate', + addressOrHandle: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', + }); + + const publicAccount = createMemberAccountType(registry, { + type: 'Public', + identity: litentryIdentity, + }); + + expect(publicAccount.isPublic).toBe(true); + expect(publicAccount.asPublic.toHuman()).toEqual(litentryIdentity.toHuman()); +}); + +it('creates a private MemberAccount with correct length', () => { + const encryptedPayload = new Uint8Array(66).fill(1); + const hash = '0x' + '2'.repeat(64) as `0x${string}`; + + const privateAccount = createMemberAccountType(registry, { + type: 'Private', + encryptedPayload, + hash, + }); + + expect(privateAccount.isPrivate).toBe(true); + const [privateData, privateHash] = privateAccount.asPrivate; + expect(privateData.toU8a()).toEqual(encryptedPayload); + expect(privateHash.toHex()).toEqual(hash); +}); + diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.ts new file mode 100644 index 0000000000..1ebbdc347d --- /dev/null +++ b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.ts @@ -0,0 +1,45 @@ +import type { Registry } from '@polkadot/types-codec/types'; +import type { LitentryIdentity, MemberAccount } from '@litentry/parachain-api'; + +/** + * Creates a MemberAccount chain type. + * + * @param registry - The type registry + * @param data - Either a LitentryIdentity for public accounts, or an encrypted payload with hash for private accounts + * @returns A MemberAccount instance + * + * @example + * ```ts + * // Public account + * const publicAccount = createMemberAccountType(registry, { + * type: 'Public', + * identity: litentryIdentity + * }); + * + * // Private account + * const privateAccount = createMemberAccountType(registry, { + * type: 'Private', + * encryptedPayload: new Uint8Array([...]), + * hash: '0x...' + * }); + * ``` + */ +export function createMemberAccountType( + registry: Registry, + data: { + type: 'Public'; + identity: LitentryIdentity; + } | { + type: 'Private'; + encryptedPayload: Uint8Array; + hash: `0x${string}`; + } +): MemberAccount { + if (data.type === 'Public') { + return registry.createType('MemberAccount', { Public: data.identity }); + } else { + return registry.createType('MemberAccount', { + Private: [data.encryptedPayload, data.hash] + }); + } +} 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..2627eb8a17 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 @@ -9,6 +9,7 @@ import type { LitentryValidationData, Web3Network, Assertion, + MemberAccount, } from '@litentry/parachain-api'; import * as shieldingKeyUtils from '../util/shielding-key'; @@ -77,6 +78,24 @@ type RequestCreateAccountStoreParams = { who: LitentryIdentity; }; +// LitentryIdentity, MemberAccount +type RequestAddAccountParams = { + who: LitentryIdentity; + memberAccount: MemberAccount; +}; + +// LitentryIdentity, Array +type RequestRemoveAccountsParams = { + who: LitentryIdentity; + memberAccounts: Array<`0x${string}`>; +}; + +// LitentryIdentity, LitentryIdentity +type RequestPublicizeAccountParams = { + who: LitentryIdentity; + memberAccount: LitentryIdentity; +}; + /** * Creates the TrustedCall for the given method and provide the `param's` types expected for them. * @@ -129,6 +148,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 +310,45 @@ export async function createTrustedCallType( return { call, key }; } + if (isRequestAddAccountParams(method, params)) { + const { who, memberAccount } = params; + + const call = registry.createType('TrustedCall', { + [trustedCallMethodsMap.add_account]: registry.createType( + trusted_operations.types.TrustedCall._enum.add_account, + [who, memberAccount] + ), + }) as TrustedCall; + + return { call, key }; + } + + if (isRequestRemoveAccountsParams(method, params)) { + const { who, memberAccounts } = params; + + const call = registry.createType('TrustedCall', { + [trustedCallMethodsMap.remove_accounts]: registry.createType( + trusted_operations.types.TrustedCall._enum.remove_accounts, + [who, memberAccounts] + ), + }) as TrustedCall; + + return { call, key }; + } + + if (isRequestPublicizeAccountParams(method, params)) { + const { who, memberAccount } = params; + + const call = registry.createType('TrustedCall', { + [trustedCallMethodsMap.publicize_account]: registry.createType( + trusted_operations.types.TrustedCall._enum.publicize_account, + [who, memberAccount] + ), + }) as TrustedCall; + + return { call, key }; + } + throw new Error(`trusted call method: ${data.method} is not supported`); } @@ -316,3 +395,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'; +} From dd8606b0e938b1bde9d106f301a93216fa3d9b4f Mon Sep 17 00:00:00 2001 From: higherordertech Date: Wed, 18 Dec 2024 23:34:05 +1100 Subject: [PATCH 2/2] feat: P-1221 update client-sdk api to fit the trusted call definition --- .../packages/client-sdk/docs/README.md | 28 +- .../client-sdk/docs/classes/Enclave.md | 6 +- .../client-sdk/docs/modules/request.md | 442 +++++++++++------- .../src/lib/requests/add-account.request.ts | 16 +- .../client-sdk/src/lib/requests/index.ts | 3 + .../lib/requests/publicize-account.request.ts | 9 +- .../lib/requests/remove-accounts.request.ts | 10 +- .../lib/type-creators/member-account.test.ts | 54 --- .../src/lib/type-creators/member-account.ts | 45 -- .../src/lib/type-creators/trusted-call.ts | 27 +- 10 files changed, 332 insertions(+), 308 deletions(-) delete mode 100644 tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.test.ts delete mode 100644 tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.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 a164620ff4..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:109](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L109) +[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:116](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L116) +[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:123](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L123) +[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:130](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L130) +[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:137](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L137) +[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,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:144](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L144) +[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` }\> @@ -692,7 +690,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:151](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L151) +[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` }\> @@ -711,7 +709,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:158](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L158) +[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` }\> @@ -730,7 +728,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:165](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L165) +[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` }\> @@ -749,7 +747,7 @@ Similarly, our types definitions must match also. #### Defined in -[lib/type-creators/trusted-call.ts:172](https://github.com/litentry/client-sdk/blob/develop/lib/type-creators/trusted-call.ts#L172) +[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 index f491994512..ebc1b167f8 100644 --- 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 @@ -3,7 +3,7 @@ import { hexToU8a } from '@polkadot/util'; import type { ApiPromise } from '@polkadot/api'; import type { LitentryIdentity, - MemberAccount, + LitentryValidationData, TrustedCallResult, WorkerRpcReturnValue, } from '@litentry/parachain-api'; @@ -32,10 +32,14 @@ export async function addAccount( /** Litentry Parachain API instance from Polkadot.js */ api: ApiPromise, data: { - /** The member account for adding. Use `createMemberAccountType` helper to create this struct */ - memberAccount: MemberAccount; /** 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; @@ -45,7 +49,7 @@ export async function addAccount( extrinsicHash: string; }>; }> { - const { who, memberAccount } = data; + const { who, identity, validation, isPublic } = data; const shard = await enclave.getShard(api); const shardU8 = hexToU8a(shard); @@ -55,7 +59,9 @@ export async function addAccount( method: 'add_account', params: { who, - memberAccount + identity, + validation, + isPublic, }, }); 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 index 78839b34dd..6c7c826a32 100644 --- 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 @@ -3,7 +3,6 @@ import { hexToU8a } from '@polkadot/util'; import type { ApiPromise } from '@polkadot/api'; import type { LitentryIdentity, - MemberAccount, TrustedCallResult, WorkerRpcReturnValue, } from '@litentry/parachain-api'; @@ -30,10 +29,10 @@ export async function publicizeAccount( /** Litentry Parachain API instance from Polkadot.js */ api: ApiPromise, data: { - /** The member account for publicizing. Use `createLitentryIdentityType` helper to create this struct */ - memberAccount: LitentryIdentity; /** 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; @@ -43,7 +42,7 @@ export async function publicizeAccount( extrinsicHash: string; }>; }> { - const { who, memberAccount } = data; + const { who, identity } = data; const shard = await enclave.getShard(api); const shardU8 = hexToU8a(shard); @@ -53,7 +52,7 @@ export async function publicizeAccount( method: 'publicize_account', params: { who, - memberAccount + identity, }, }); 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 index 32de5eb5dd..9eb783287a 100644 --- 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 @@ -27,14 +27,14 @@ import { getEnclaveNonce } from './get-enclave-nonce'; * an email identity, this is the email verification code. If who is not an email identity, this is the * signed payload. */ -export async function remove_accounts( +export async function removeAccounts( /** Litentry Parachain API instance from Polkadot.js */ api: ApiPromise, data: { - /** Member accounts for removing */ - memberAccounts: Array<`0x${string}`>; /** The user's account. Use `createLitentryIdentityType` helper to create this struct */ who: LitentryIdentity; + /** Accounts for removing */ + identities: Array; } ): Promise<{ payloadToSign?: string; @@ -44,7 +44,7 @@ export async function remove_accounts( extrinsicHash: string; }>; }> { - const { who, memberAccounts } = data; + const { who, identities } = data; const shard = await enclave.getShard(api); const shardU8 = hexToU8a(shard); @@ -54,7 +54,7 @@ export async function remove_accounts( method: 'remove_accounts', params: { who, - memberAccounts + identities, }, }); diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.test.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.test.ts deleted file mode 100644 index 8420b3e86a..0000000000 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.test.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { TypeRegistry } from '@polkadot/types'; -import { cryptoWaitReady } from '@polkadot/util-crypto'; - -import { identity, omniAccount } from '@litentry/parachain-api'; - -import { createMemberAccountType } from './member-account'; -import { createLitentryIdentityType } from './litentry-identity'; - -const types = { - ...identity.types, // LitentryIdentity is defined here - ...omniAccount.types, // MemberAccount is defined here -}; - -let registry: TypeRegistry; - - -beforeAll(async () => { - await cryptoWaitReady(); - - registry = new TypeRegistry(); - registry.register(types); -}); - -it('creates a public MemberAccount', () => { - const litentryIdentity = createLitentryIdentityType(registry, { - type: 'Substrate', - addressOrHandle: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', - }); - - const publicAccount = createMemberAccountType(registry, { - type: 'Public', - identity: litentryIdentity, - }); - - expect(publicAccount.isPublic).toBe(true); - expect(publicAccount.asPublic.toHuman()).toEqual(litentryIdentity.toHuman()); -}); - -it('creates a private MemberAccount with correct length', () => { - const encryptedPayload = new Uint8Array(66).fill(1); - const hash = '0x' + '2'.repeat(64) as `0x${string}`; - - const privateAccount = createMemberAccountType(registry, { - type: 'Private', - encryptedPayload, - hash, - }); - - expect(privateAccount.isPrivate).toBe(true); - const [privateData, privateHash] = privateAccount.asPrivate; - expect(privateData.toU8a()).toEqual(encryptedPayload); - expect(privateHash.toHex()).toEqual(hash); -}); - diff --git a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.ts b/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.ts deleted file mode 100644 index 1ebbdc347d..0000000000 --- a/tee-worker/identity/client-sdk/packages/client-sdk/src/lib/type-creators/member-account.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { Registry } from '@polkadot/types-codec/types'; -import type { LitentryIdentity, MemberAccount } from '@litentry/parachain-api'; - -/** - * Creates a MemberAccount chain type. - * - * @param registry - The type registry - * @param data - Either a LitentryIdentity for public accounts, or an encrypted payload with hash for private accounts - * @returns A MemberAccount instance - * - * @example - * ```ts - * // Public account - * const publicAccount = createMemberAccountType(registry, { - * type: 'Public', - * identity: litentryIdentity - * }); - * - * // Private account - * const privateAccount = createMemberAccountType(registry, { - * type: 'Private', - * encryptedPayload: new Uint8Array([...]), - * hash: '0x...' - * }); - * ``` - */ -export function createMemberAccountType( - registry: Registry, - data: { - type: 'Public'; - identity: LitentryIdentity; - } | { - type: 'Private'; - encryptedPayload: Uint8Array; - hash: `0x${string}`; - } -): MemberAccount { - if (data.type === 'Public') { - return registry.createType('MemberAccount', { Public: data.identity }); - } else { - return registry.createType('MemberAccount', { - Private: [data.encryptedPayload, data.hash] - }); - } -} 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 2627eb8a17..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 @@ -9,7 +9,6 @@ import type { LitentryValidationData, Web3Network, Assertion, - MemberAccount, } from '@litentry/parachain-api'; import * as shieldingKeyUtils from '../util/shielding-key'; @@ -78,22 +77,24 @@ type RequestCreateAccountStoreParams = { who: LitentryIdentity; }; -// LitentryIdentity, MemberAccount +// LitentryIdentity, LitentryIdentity, LitentryValidationData, boolean type RequestAddAccountParams = { who: LitentryIdentity; - memberAccount: MemberAccount; + identity: LitentryIdentity; + validation: LitentryValidationData; + isPublic: boolean; }; -// LitentryIdentity, Array +// LitentryIdentity, Array type RequestRemoveAccountsParams = { who: LitentryIdentity; - memberAccounts: Array<`0x${string}`>; + identities: Array; }; // LitentryIdentity, LitentryIdentity type RequestPublicizeAccountParams = { who: LitentryIdentity; - memberAccount: LitentryIdentity; + identity: LitentryIdentity; }; /** @@ -311,12 +312,13 @@ export async function createTrustedCallType( } if (isRequestAddAccountParams(method, params)) { - const { who, memberAccount } = 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, memberAccount] + [who, identity, validation, isPublic] ), }) as TrustedCall; @@ -324,12 +326,13 @@ export async function createTrustedCallType( } if (isRequestRemoveAccountsParams(method, params)) { - const { who, memberAccounts } = 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, memberAccounts] + [who, identitiesVec] ), }) as TrustedCall; @@ -337,12 +340,12 @@ export async function createTrustedCallType( } if (isRequestPublicizeAccountParams(method, params)) { - const { who, memberAccount } = params; + const { who, identity } = params; const call = registry.createType('TrustedCall', { [trustedCallMethodsMap.publicize_account]: registry.createType( trusted_operations.types.TrustedCall._enum.publicize_account, - [who, memberAccount] + [who, identity] ), }) as TrustedCall;