Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client-sdk: decode the result of native trusted operations #3169

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tee-worker/identity/client-api/parachain-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/src/index.js",
"module": "dist/src/index.js",
"sideEffects": false,
"version": "0.9.20-next.5",
"version": "0.9.20-next.7",
"scripts": {
"clean": "rm -rf dist build node_modules",
"update-metadata": "curl -s -H \"Content-Type: application/json\" -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9944 > prepare-build/litentry-parachain-metadata.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,29 @@ export default {
},
},
NativeTaskError: {
UnexpectedCall: "String",
ShieldingKeyRetrievalFailed: "String", // Stringified itp_sgx_crypto::Error
RequestPayloadDecodingFailed: "Null",
ParentchainDataRetrievalFailed: "String", // Stringified itp_stf_state_handler::Error
InvalidSignerAccount: "Null",
UnauthorizedSigner: "Null",
InvalidMemberIdentity: "Null",
MissingAesKey: "Null",
MrEnclaveRetrievalFailed: "Null",
EnclaveSignerRetrievalFailed: "Null",
AuthenticationVerificationFailed: "Null",
ValidationDataVerificationFailed: "Null",
ConnectionHashNotFound: "String",
MetadataRetrievalFailed: "String", // Stringified itp_node_api_metadata_provider::Error
InvalidMetadata: "String", // Stringified itp_node_api_metadata::Error
TrustedCallSendingFailed: "String", // Stringified mpsc::SendError<(H256, TrustedCall)>
CallSendingFailed: "String",
ExtrinsicConstructionFailed: "String", // Stringified itp_extrinsics_factory::Error
ExtrinsicSendingFailed: "String", // Stringified sgx_status_t
InvalidRequest: "Null",
NativeRequestSendFailed: "Null",
_enum: {
UnexpectedCall: "Text",
ShieldingKeyRetrievalFailed: "Text", // Stringified itp_sgx_crypto::Error
RequestPayloadDecodingFailed: "Null",
ParentchainDataRetrievalFailed: "Text", // Stringified itp_stf_state_handler::Error
InvalidSignerAccount: "Null",
UnauthorizedSigner: "Null",
InvalidMemberIdentity: "Null",
MissingAesKey: "Null",
MrEnclaveRetrievalFailed: "Null",
EnclaveSignerRetrievalFailed: "Null",
AuthenticationVerificationFailed: "Null",
ValidationDataVerificationFailed: "Null",
ConnectionHashNotFound: "Text",
MetadataRetrievalFailed: "Text", // Stringified itp_node_api_metadata_provider::Error
InvalidMetadata: "Text", // Stringified itp_node_api_metadata::Error
TrustedCallSendingFailed: "Text", // Stringified mpsc::SendError<(H256, TrustedCall)>
CallSendingFailed: "Text",
ExtrinsicConstructionFailed: "Text", // Stringified itp_extrinsics_factory::Error
ExtrinsicSendingFailed: "Text", // Stringified sgx_status_t
InvalidRequest: "Null",
NativeRequestSendFailed: "Null",
},
},
},
};
2 changes: 1 addition & 1 deletion tee-worker/identity/client-api/sidechain-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/src/index.js",
"module": "dist/src/index.js",
"sideEffects": false,
"version": "0.9.20-next.5",
"version": "0.9.20-next.7",
"scripts": {
"clean": "rm -rf dist build node_modules",
"update-metadata": "../../bin/litentry-cli print-sgx-metadata-raw > prepare-build/litentry-sidechain-metadata.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@litentry/client-sdk",
"description": "This package provides helpers for dApps to interact with the Litentry Protocol.",
"version": "1.0.0-next.0",
"version": "1.0.0-next.1",
"license": "GPL-3.0-or-later",
"dependencies": {},
"devDependencies": {
"@polkadot/rpc-provider": "^10.9.1"
},
"peerDependencies": {
"@litentry/parachain-api": "0.9.20-next.5",
"@litentry/sidechain-api": "0.9.20-next.5",
"@litentry/parachain-api": "0.9.20-next.7",
"@litentry/sidechain-api": "0.9.20-next.7",
"@litentry/chaindata": "*",
"@polkadot/api": "^10.9.1",
"@polkadot/types": "^10.9.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { assert, hexToU8a } from '@polkadot/util';
import { randomAsHex } from '@polkadot/util-crypto';

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';
Expand All @@ -33,10 +34,10 @@ export async function callEthereum(
}
): Promise<{
payloadToSign: string;
txHash: string;
send: (args: { signedPayload: string }) => Promise<{
response: Array<WorkerRpcReturnValue>;
txHash: string;
response: WorkerRpcReturnValue;
blockHash: string;
extrinsicHash: string;
}>;
}> {
const { who, omniAccount } = data;
Expand All @@ -45,7 +46,6 @@ export async function callEthereum(

const shard = await enclave.getShard(api);
const shardU8 = hexToU8a(shard);
const txHash = randomAsHex();

const { call } = await createTrustedCallType(api.registry, {
method: 'request_intent',
Expand All @@ -72,8 +72,9 @@ export async function callEthereum(
const send = async (args: {
signedPayload: string;
}): Promise<{
response: Array<WorkerRpcReturnValue>;
txHash: string;
response: WorkerRpcReturnValue;
blockHash: string;
extrinsicHash: string;
}> => {
// prepare and encrypt request

Expand All @@ -92,16 +93,27 @@ export async function callEthereum(
params: [request.toHex()],
};

const enclaveResult = await enclave.send(api, rpcRequest);
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));
}

const { extrinsic_hash, block_hash } = result.asOk;

return {
txHash,
response: enclaveResult,
response,
extrinsicHash: extrinsic_hash.toString(),
blockHash: block_hash.toString(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block_hash is an Option, would this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't throw, if that's what you mean.

It'd either be: the hex value, empty strings, or 0x0000...

but for these methods, blockHash should always be there, right? since we are watching until InBlock?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are waiting until the is Finalized

};
};

return {
txHash,
payloadToSign,
send,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { hexToU8a } from '@polkadot/util';
import { randomAsHex } from '@polkadot/util-crypto';

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';
Expand All @@ -28,17 +29,16 @@ export async function createAccountStore(
}
): Promise<{
payloadToSign: string;
txHash: string;
send: (args: { signedPayload: string }) => Promise<{
response: Array<WorkerRpcReturnValue>;
txHash: string;
response: WorkerRpcReturnValue;
blockHash: string;
extrinsicHash: string;
}>;
}> {
const { who, omniAccount } = data;

const shard = await enclave.getShard(api);
const shardU8 = hexToU8a(shard);
const txHash = randomAsHex();

const { call } = await createTrustedCallType(api.registry, {
method: 'create_account_store',
Expand All @@ -61,8 +61,9 @@ export async function createAccountStore(
const send = async (args: {
signedPayload: string;
}): Promise<{
response: Array<WorkerRpcReturnValue>;
txHash: string;
response: WorkerRpcReturnValue;
blockHash: string;
extrinsicHash: string;
}> => {
// prepare and encrypt request

Expand All @@ -81,16 +82,27 @@ export async function createAccountStore(
params: [request.toHex()],
};

const enclaveResult = await enclave.send(api, rpcRequest);
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));
}

const { extrinsic_hash, block_hash } = result.asOk;

return {
txHash,
response: enclaveResult,
response,
extrinsicHash: extrinsic_hash.toString(),
blockHash: block_hash.toString(),
};
};

return {
txHash,
payloadToSign,
send,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { assert, hexToU8a, stringToHex } from '@polkadot/util';
import { randomAsHex } from '@polkadot/util-crypto';

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';
Expand All @@ -30,17 +31,16 @@ export async function remark(
}
): Promise<{
payloadToSign: string;
txHash: string;
send: (args: { signedPayload: string }) => Promise<{
response: Array<WorkerRpcReturnValue>;
txHash: string;
response: WorkerRpcReturnValue;
blockHash: string;
extrinsicHash: string;
}>;
}> {
const { who, message, omniAccount } = data;

const shard = await enclave.getShard(api);
const shardU8 = hexToU8a(shard);
const txHash = randomAsHex();

const { call } = await createTrustedCallType(api.registry, {
method: 'request_intent',
Expand Down Expand Up @@ -68,8 +68,9 @@ export async function remark(
const send = async (args: {
signedPayload: string;
}): Promise<{
response: Array<WorkerRpcReturnValue>;
txHash: string;
response: WorkerRpcReturnValue;
blockHash: string;
extrinsicHash: string;
}> => {
// prepare and encrypt request

Expand All @@ -88,16 +89,27 @@ export async function remark(
params: [request.toHex()],
};

const enclaveResult = await enclave.send(api, rpcRequest);
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));
}

const { extrinsic_hash, block_hash } = result.asOk;

return {
txHash,
response: enclaveResult,
response,
extrinsicHash: extrinsic_hash.toString(),
blockHash: block_hash.toString(),
};
};

return {
txHash,
payloadToSign,
send,
};
Expand Down
Loading