From 0c9a088f5d4b266dfb6cdfd59c5f4b3b1dc8e778 Mon Sep 17 00:00:00 2001 From: brenzi Date: Thu, 12 Dec 2024 13:46:20 +0100 Subject: [PATCH] add session proxy calls and getters to worker-api (#125) * add placeholder for delegate to fix encoding * delegate getter and calls * add TrustedCalls * fixed encoding * fix call as delegate * sendNote works too * cleanup * bump version 0.18.0-alpha.1 * v0.18.0-alpha.0 * v0.18.0-alpha.1 * add trusted getter AccountInfoAndSessionProxies * disable e2e test * v0.18.0-alpha.2 * fix missing delegate forwards * v0.18.0-alpha.3 --- lerna.json | 2 +- packages/node-api/package.json | 5 +- packages/types/package.json | 3 +- .../integriteeWorker/definitions.ts | 28 ++++- .../src/interfaces/integriteeWorker/types.ts | 43 ++++++- packages/util/package.json | 3 +- packages/worker-api/package.json | 9 +- .../worker-api/src/integriteeWorker.spec.ts | 118 +++++++++++++++++- packages/worker-api/src/integriteeWorker.ts | 57 ++++++++- packages/worker-api/src/interface.ts | 6 +- packages/worker-api/src/requests.ts | 10 +- packages/worker-api/src/testUtils/networks.ts | 6 +- yarn.lock | 14 +-- 13 files changed, 270 insertions(+), 34 deletions(-) diff --git a/lerna.json b/lerna.json index f6cff2d3..b9194a18 100644 --- a/lerna.json +++ b/lerna.json @@ -6,5 +6,5 @@ "publishConfig": { "directory": "build" }, - "version": "0.17.0-alpha.2" + "version": "0.18.0-alpha.3" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index 7d67c92b..e73fa54f 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -5,6 +5,7 @@ "engines": { "node": ">=18.14" }, + "gitHead": "1fa54c11ec73869718b9de521a143969c4cacc02", "homepage": "https://github.com/encointer/encointer-js/tree/master/packages/node-api#readme", "license": "GPL-3.0-or-later", "name": "@encointer/node-api", @@ -18,10 +19,10 @@ }, "sideEffects": false, "type": "module", - "version": "0.17.0-alpha.2", + "version": "0.18.0-alpha.3", "main": "index.js", "dependencies": { - "@encointer/types": "^0.17.0-alpha.2", + "@encointer/types": "^0.18.0-alpha.3", "@polkadot/api": "^11.2.1", "tslib": "^2.6.2" }, diff --git a/packages/types/package.json b/packages/types/package.json index 7ca0b36c..8e10fc74 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -5,6 +5,7 @@ "engines": { "node": ">=18.14" }, + "gitHead": "1fa54c11ec73869718b9de521a143969c4cacc02", "homepage": "https://github.com/encointer/encointer-js/tree/master/packages/types#readme", "license": "GPL-3.0-or-later", "name": "@encointer/types", @@ -18,7 +19,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.17.0-alpha.2", + "version": "0.18.0-alpha.3", "main": "index.js", "scripts": { "generate:defs": "node --experimental-specifier-resolution=node --loader ts-node/esm ../../node_modules/.bin/polkadot-types-from-defs --package @encointer/types/interfaces --input ./src/interfaces", diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index c6471b74..9b267188 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -59,7 +59,7 @@ export default { IntegriteeTrustedGetter: { _enum: { account_info: 'AccountId', - unused_index_1: null, + account_info_and_session_proxies: 'AccountId', unused_index_2: null, unused_index_3: null, unused_index_4: null, @@ -113,6 +113,7 @@ export default { }, IntegriteeTrustedGetterSigned: { getter: 'IntegriteeTrustedGetter', + delegate: 'Option', signature: 'MultiSignature' }, IntegriteeGetter: { @@ -131,6 +132,7 @@ export default { IntegriteeTrustedCallSigned: { call: 'IntegriteeTrustedCall', nonce: 'u32', + delegate: 'Option', signature: 'MultiSignature' }, IntegriteeTrustedCall: { @@ -155,7 +157,7 @@ export default { unused_index_17: null, unused_index_18: null, unused_index_19: null, - unused_index_20: null, + send_note: 'SendNoteArgs', unused_index_21: null, unused_index_22: null, unused_index_23: null, @@ -165,7 +167,7 @@ export default { unused_index_27: null, unused_index_28: null, unused_index_29: null, - unused_index_30: null, + add_session_proxy: 'AddSessionProxyArgs', unused_index_31: null, unused_index_32: null, unused_index_33: null, @@ -231,6 +233,26 @@ export default { AttemptsArg: { origin: 'AccountId' }, + SessionProxyRole: { + _enum: { + readBalance: null, + readAny: null, + nonTransfer: null, + any: null, + transferAllowance: 'Balance' + } + }, + SessionProxyCredentials: { + role: 'SessionProxyRole', + expiry: 'Option', + seed: 'H256', + }, + AddSessionProxyArgs: '(AccountId, AccountId, SessionProxyCredentials)', + AccountInfoAndSessionProxies: { + account_info: 'AccountInfo', + session_proxies: 'Vec' + }, + SendNoteArgs: '(AccountId, AccountId, String)', GuessTheNumberTrustedCall: { _enum: { set_winnings: 'GuessTheNumberSetWinningsArgs', diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index 93cb1cc0..90bd2265 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -6,7 +6,8 @@ import type { ParentchainId, ShardIdentifier } from '@encointer/types/interfaces import type { Bytes, Enum, Option, Struct, Text, Vec, u16, u32, u64 } from '@polkadot/types-codec'; import type { ITuple } from '@polkadot/types-codec/types'; import type { MultiSignature } from '@polkadot/types/interfaces/extrinsics'; -import type { AccountId, Balance, H160, Moment } from '@polkadot/types/interfaces/runtime'; +import type {AccountId, Balance, H160, Moment} from '@polkadot/types/interfaces/runtime'; +import type {AccountInfo} from "@polkadot/types/interfaces/system"; /** @name AttemptsArg */ export interface AttemptsArg extends Struct { @@ -22,6 +23,36 @@ export interface BalanceTransferArgs extends ITuple<[AccountId, AccountId, Balan /** @name BalanceTransferWithNoteArgs */ export interface BalanceTransferWithNoteArgs extends ITuple<[AccountId, AccountId, BalanceType, Text]> {} +/** @name SendNoteArgs */ +export interface SendNoteArgs extends ITuple<[AccountId, AccountId, Text]> {} + +/** @name AddSessionProxyArgs */ +export interface AddSessionProxyArgs extends ITuple<[AccountId, AccountId, SessionProxyCredentials]> {} + +/** @name SessionProxyRole */ +export interface SessionProxyRole extends Enum { + readonly isReadBalance: boolean; + readonly isReadAny: boolean; + readonly isNonTransfer: boolean; + readonly isAny: boolean; + readonly isTransferAllowance: boolean; + readonly asTransferAllowance: Balance; + readonly type: 'ReadBalance' | 'ReadAny' | 'NonTransfer' | 'Any' | 'TransferAllowance'; +} + +/** @name SessionProxyCredentials */ +export interface SessionProxyCredentials extends Struct { + readonly role: SessionProxyRole; + readonly expiry: Option; + readonly seed: Uint8Array; +} + +/** @name AccountInfoAndSessionProxies */ +export interface AccountInfoAndSessionProxies extends Struct { + readonly account_info: AccountInfo; + readonly session_proxies: Vec; +} + /** @name BalanceUnshieldArgs */ export interface BalanceUnshieldArgs extends ITuple<[AccountId, AccountId, BalanceType, ShardIdentifier]> {} @@ -174,7 +205,8 @@ export interface IntegriteeTrustedCall extends Enum { readonly isUnusedIndex17: boolean; readonly isUnusedIndex18: boolean; readonly isUnusedIndex19: boolean; - readonly isUnusedIndex20: boolean; + readonly isSendNote: boolean; + readonly asSendNote: SendNoteArgs; readonly isUnusedIndex21: boolean; readonly isUnusedIndex22: boolean; readonly isUnusedIndex23: boolean; @@ -184,7 +216,8 @@ export interface IntegriteeTrustedCall extends Enum { readonly isUnusedIndex27: boolean; readonly isUnusedIndex28: boolean; readonly isUnusedIndex29: boolean; - readonly isUnusedIndex30: boolean; + readonly isAddSessionProxy: boolean; + readonly asAddSessionProxy: AddSessionProxyArgs; readonly isUnusedIndex31: boolean; readonly isUnusedIndex32: boolean; readonly isUnusedIndex33: boolean; @@ -213,6 +246,7 @@ export interface IntegriteeTrustedCall extends Enum { export interface IntegriteeTrustedCallSigned extends Struct { readonly call: IntegriteeTrustedCall; readonly nonce: u32; + readonly delegate: Option, readonly signature: MultiSignature; } @@ -220,6 +254,8 @@ export interface IntegriteeTrustedCallSigned extends Struct { export interface IntegriteeTrustedGetter extends Enum { readonly isAccountInfo: boolean; readonly asAccountInfo: AccountId; + readonly isAccountInfoAndSessionProxies: boolean; + readonly asAccountInfoAndSessionProxies: AccountId; readonly isUnusedIndex1: boolean; readonly isUnusedIndex2: boolean; readonly isUnusedIndex3: boolean; @@ -278,6 +314,7 @@ export interface IntegriteeTrustedGetter extends Enum { /** @name IntegriteeTrustedGetterSigned */ export interface IntegriteeTrustedGetterSigned extends Struct { readonly getter: IntegriteeTrustedGetter; + readonly delegate: Option readonly signature: MultiSignature; } diff --git a/packages/util/package.json b/packages/util/package.json index 90782e8c..6e4f0541 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -5,6 +5,7 @@ "engines": { "node": ">=18.14" }, + "gitHead": "1fa54c11ec73869718b9de521a143969c4cacc02", "homepage": "https://github.com/encointer/encointer-js/tree/master/packages/util#readme", "license": "MIT", "name": "@encointer/util", @@ -20,7 +21,7 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.17.0-alpha.2", + "version": "0.18.0-alpha.3", "main": "index.js", "dependencies": { "@babel/runtime": "^7.18.9", diff --git a/packages/worker-api/package.json b/packages/worker-api/package.json index 20af5bc5..cdd133df 100644 --- a/packages/worker-api/package.json +++ b/packages/worker-api/package.json @@ -5,6 +5,7 @@ "engines": { "node": ">=18.14" }, + "gitHead": "1fa54c11ec73869718b9de521a143969c4cacc02", "homepage": "https://github.com/encointer/encointer-js/tree/master/packages/worker-api#readme", "license": "GPL-3.0-or-later", "name": "@encointer/worker-api", @@ -19,12 +20,12 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.17.0-alpha.2", + "version": "0.18.0-alpha.3", "main": "index.js", "dependencies": { - "@encointer/node-api": "^0.17.0-alpha.2", - "@encointer/types": "^0.17.0-alpha.2", - "@encointer/util": "^0.17.0-alpha.2", + "@encointer/node-api": "^0.18.0-alpha.3", + "@encointer/types": "^0.18.0-alpha.3", + "@encointer/util": "^0.18.0-alpha.3", "@peculiar/webcrypto": "^1.4.6", "@polkadot/api": "^11.2.1", "@polkadot/keyring": "^12.6.2", diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 5351c0c6..ebdc5cfe 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -1,10 +1,11 @@ import { Keyring } from '@polkadot/api'; -import { cryptoWaitReady } from '@polkadot/util-crypto'; +import {cryptoWaitReady, mnemonicToMiniSecret} from '@polkadot/util-crypto'; import {localDockerNetwork} from './testUtils/networks.js'; import { IntegriteeWorker } from './integriteeWorker.js'; import {type KeyringPair} from "@polkadot/keyring/types"; import WS from 'websocket'; +import type {AccountInfo} from "@polkadot/types/interfaces/system"; const {w3cwebsocket: WebSocket} = WS; @@ -78,11 +79,25 @@ describe('worker', () => { describe('accountInfoGetter', () => { it('should return value', async () => { - const getter = await worker.accountInfoGetter(charlie, network.shard); + const getter = await worker.accountInfoGetter(alice, network.shard); console.log(`AccountInfoGetter: ${JSON.stringify(getter)}`); const result = await getter.send(); console.log('getAccountInfo:', result.toHuman()); expect(result).toBeDefined(); + const info = result as AccountInfo; + expect(info.data.free.toBigInt()).toBeGreaterThan(0); + }); + + it('should fall back to default if signed by unauthorized delegate', async () => { + const getter = await worker.accountInfoGetter(alice, network.shard, { delegate: charlie }); + console.log(`AccountInfoGetter with unauthorized signature: ${JSON.stringify(getter)}`); + const result = await getter.send(); + console.log('getAccountInfo:', result.toHuman()); + expect(result).toBeDefined(); + const info = result as AccountInfo; + console.log("parsed: ", info.data.free); + // we don't forward errors here. instead, failures are mapped to default, which is zero + expect(info.data.free.toBigInt()).toEqual(BigInt(0)); }); }); @@ -136,9 +151,32 @@ describe('worker', () => { }); }); - describe('should return note of the executed trusted call', () => { + describe('call signed by unauthorized delegate should fail', () => { + it('should fail', async () => { + const shard = network.shard; + //const testNote = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"; + const testNote = "My test note"; + const result = await worker.trustedBalanceTransfer( + alice, + shard, + network.mrenclave, + alice.address, + charlie.address, + 1100000000000, + testNote, + { delegate: charlie} + ); + console.log('balance transfer result', JSON.stringify(result)); + expect(result).toBeDefined(); + const status = worker.createType('TrustedOperationStatus', result.status); + expect(status.isInvalid).toBeTruthy(); + }); + }); + + describe.skip('should return note of the executed trusted call', () => { it('should return balance transfer with note as note', async () => { const shard = network.shard; + //const testNote = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"; const testNote = "My test note"; const result = await worker.trustedBalanceTransfer( alice, @@ -172,6 +210,80 @@ describe('worker', () => { }); }); + // race condition so skipped + describe.skip('session proxies (delegates) should work', () => { + it('add delegate should work', async () => { + const shard = network.shard; + const now = new Date(); + const expiryDate = new Date(now.getTime() + 40 * 24 * 60 * 60 * 1000); + const expiry = Math.floor(expiryDate.getTime()); + const miniSecret = mnemonicToMiniSecret("secret forest ticket smooth wide mass parent reveal embark impose fiscal company"); + const role = worker.createType('SessionProxyRole', 'Any'); + const result = await worker.trustedAddSessionProxy( + alice, + shard, + network.mrenclave, + role, + '5DwH48esFAmQWjaae7zvzzAbhRgS4enS7tfUPTbGr6ZFnW7R', + expiry, + miniSecret, + ); + console.log('add session proxy', JSON.stringify(result)); + expect(result).toBeDefined(); + }); + + it('AccountInfoAndProxiesGetter should return new proxy', async () => { + const getter = await worker.accountInfoAndSessionProxiesGetter(alice, network.shard); + console.log(`accountInfoAndSessionProxies: ${JSON.stringify(getter)}`); + const result = await getter.send(); + console.log('accountInfoAndSessionProxies:', result.toHuman()); + const data = worker.createType('AccountInfoAndSessionProxies', result); + const expected_role = worker.createType('SessionProxyRole', 'Any'); + expect(data.session_proxies[0].role).toEqual(expected_role); + }); + + it('call as delegate should work', async () => { + const shard = network.shard; + const localKeyring = new Keyring({ type: "sr25519", ss58Format: 42 }); + const delegate = localKeyring.addFromMnemonic("secret forest ticket smooth wide mass parent reveal embark impose fiscal company", { + name: "fresh", + }); + const result = await worker.trustedBalanceTransfer( + alice, + shard, + network.mrenclave, + alice.address, + '5DwH48esFAmQWjaae7zvzzAbhRgS4enS7tfUPTbGr6ZFnW7R', + 1100000000000, + "My test note", + { delegate: delegate } + ); + console.log('delegated balance transfer result', JSON.stringify(result)); + expect(result).toBeDefined(); + const status = worker.createType('TrustedOperationStatus', result.status); + expect(status.isInSidechainBlock).toBeTruthy(); + }); + }); + + // race condition so skipped + describe.skip('send note should work', () => { + it('send note included', async () => { + const shard = network.shard; + const result = await worker.trustedSendNote( + alice, + shard, + network.mrenclave, + alice.address, + charlie.address, + "Hoi" + ); + console.log('send note', JSON.stringify(result)); + expect(result).toBeDefined(); + const status = worker.createType('TrustedOperationStatus', result.status); + expect(status.isInSidechainBlock).toBeTruthy(); + }); + }); + // race condition so skipped describe.skip('balance transfer should work', () => { it('should return value', async () => { diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index efb11999..33cf932f 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -6,9 +6,10 @@ import type { GuessTheNumberTrustedCall, GuessTheNumberPublicGetter, GuessTheNumberTrustedGetter, + AccountInfoAndSessionProxies, AttemptsArg, ParentchainsInfo, - NotesBucketInfo, TimestampedTrustedNote, + NotesBucketInfo, TimestampedTrustedNote, SessionProxyRole, } from '@encointer/types'; import { type ISubmittableGetter, @@ -47,11 +48,22 @@ export class IntegriteeWorker extends Worker { const trustedGetterArgs = { shard: shard, account: accountOrPubKey, + delegate: signerOptions?.delegate, signer: signerOptions?.signer, } return await submittableTrustedGetter(this, 'account_info', accountOrPubKey, trustedGetterArgs, asString(accountOrPubKey), 'AccountInfo'); } + public async accountInfoAndSessionProxiesGetter(accountOrPubKey: AddressOrPair, shard: string, signerOptions?: TrustedSignerOptions): Promise> { + const trustedGetterArgs = { + shard: shard, + account: accountOrPubKey, + delegate: signerOptions?.delegate, + signer: signerOptions?.signer, + } + return await submittableTrustedGetter(this, 'account_info_and_session_proxies', accountOrPubKey, trustedGetterArgs, asString(accountOrPubKey), 'AccountInfoAndSessionProxies'); + } + public parentchainsInfoGetter(shard: string): SubmittableGetter { const publicGetterArgs = { shard: shard, @@ -71,6 +83,7 @@ export class IntegriteeWorker extends Worker { const trustedGetterArgs = { shard: shard, account: accountOrPubKey, + delegate: signerOptions?.delegate, signer: signerOptions?.signer, } const notesForArgs = this.createType('NotesForArgs', [asString(accountOrPubKey), bucketIndex]); @@ -89,6 +102,7 @@ export class IntegriteeWorker extends Worker { const trustedGetterArgs = { shard: shard, account: accountOrPubKey, + delegate: signerOptions?.delegate, signer: signerOptions?.signer, } const args = this.createType('AttemptsArg', {origin: asString(accountOrPubKey)}); @@ -140,6 +154,45 @@ export class IntegriteeWorker extends Worker { return this.sendTrustedCall(signed, shardT); } + public async trustedAddSessionProxy( + account: AddressOrPair, + shard: string, + mrenclave: string, + role: SessionProxyRole, + delegate: AddressOrPair, + expiry: number, + seed: Uint8Array, + signerOptions?: TrustedSignerOptions, + ): Promise { + const nonce = signerOptions?.nonce ?? await this.getNonce(account, shard, signerOptions) + + const shardT = this.createType('ShardIdentifier', bs58.decode(shard)); + const credentials = this.createType('SessionProxyCredentials', [role, expiry, seed]) + const params = this.createType('AddSessionProxyArgs', [asString(account), asString(delegate), credentials]) + const call = createTrustedCall(this, ['add_session_proxy', 'AddSessionProxyArgs'], params); + const signed = await signTrustedCall(this, call, account, shardT, mrenclave, nonce, signerOptions); + + console.debug(`AddSessionProxy ${JSON.stringify(signed)}`); + return this.sendTrustedCall(signed, shardT); + } + + public async trustedSendNote( + account: AddressOrPair, + shard: string, + mrenclave: string, + from: String, + to: String, + note: string, + signerOptions?: TrustedSignerOptions, + ): Promise { + const nonce = signerOptions?.nonce ?? await this.getNonce(account, shard, signerOptions) + const shardT = this.createType('ShardIdentifier', bs58.decode(shard)); + const params = this.createType('SendNoteArgs', [from, to, note]) + const call = createTrustedCall(this, ['send_note', 'SendNoteArgs'], params); + const signed = await signTrustedCall(this, call, account, shardT, mrenclave, nonce, signerOptions); + return this.sendTrustedCall(signed, shardT); + } + public async guessTheNumber( account: AddressOrPair, shard: string, @@ -194,7 +247,7 @@ export class SubmittableGetter implements ISubmittableGe async function submittableTrustedGetter(self: W, request: string, account: AddressOrPair, args: TrustedGetterArgs, trustedGetterParams: TrustedGetterParams, returnType: string): Promise> { const {shard} = args; const shardT = self.createType('ShardIdentifier', bs58.decode(shard)); - const signedGetter = await createSignedGetter(self, request, account, trustedGetterParams, { signer: args?.signer }) + const signedGetter = await createSignedGetter(self, request, account, trustedGetterParams, { signer: args?.signer, delegate: args?.delegate }); return new SubmittableGetter(self, shardT, signedGetter, returnType); } diff --git a/packages/worker-api/src/interface.ts b/packages/worker-api/src/interface.ts index e7cb3606..c0217bbc 100644 --- a/packages/worker-api/src/interface.ts +++ b/packages/worker-api/src/interface.ts @@ -54,6 +54,7 @@ export interface WorkerOptions { export interface TrustedGetterArgs { shard: string; account: AddressOrPair; + delegate?: AddressOrPair; signer?: Signer } @@ -65,9 +66,12 @@ export type TrustedGetterParams = string | GuessTheNumberTrustedGetter | null * In the future, this might include other things. */ export interface TrustedSignerOptions { - // If this is null, we assume that the account is a Pair. + // use signer extension? If this is null, we assume that the account is a Pair. signer?: Signer; + // use session proxy pair? + delegate?: AddressOrPair + // If the nonce is null, it will be fetched. nonce?: u32; } diff --git a/packages/worker-api/src/requests.ts b/packages/worker-api/src/requests.ts index cf32b1da..bb9c1430 100644 --- a/packages/worker-api/src/requests.ts +++ b/packages/worker-api/src/requests.ts @@ -11,7 +11,7 @@ import type { IntegriteeTrustedGetter, ShardIdentifier } from "@encointer/types"; -import {signPayload} from "@encointer/util"; +import {asString, signPayload} from "@encointer/util"; import type {u32} from "@polkadot/types"; import bs58 from "bs58"; import type {AddressOrPair} from "@polkadot/api-base/types/submittable"; @@ -37,10 +37,12 @@ export const createTrustedGetter = (self: IWorkerBase, request: string, params: } export async function signTrustedGetter(self: IWorkerBase, account: AddressOrPair, getter: IntegriteeTrustedGetter, options?: TrustedSignerOptions): Promise { - const signature = await signPayload(account, getter.toU8a(), options?.signer); + // delegate overrides signer extension option + const signature = await signPayload(options?.delegate ? options.delegate : account, getter.toU8a(), options?.delegate ? undefined : options?.signer); const g = self.createType('IntegriteeGetter', { trusted: { getter, + delegate: options?.delegate ? asString(options.delegate) : null, signature: {Sr25519: signature}, } }); @@ -78,11 +80,13 @@ export const signTrustedCall = async ( const payload = Uint8Array.from([...call.toU8a(), ...nonce.toU8a(), ...hash.toU8a(), ...shard.toU8a()]); - const signature = await signPayload(account, payload, options?.signer); + // delegate overrides signer extension option + const signature = await signPayload(options?.delegate ? options.delegate : account, payload, options?.delegate ? undefined : options?.signer); return self.createType('IntegriteeTrustedCallSigned', { call: call, nonce: nonce, + delegate: options?.delegate ? asString(options.delegate) : null, signature: {Sr25519: signature}, }); } diff --git a/packages/worker-api/src/testUtils/networks.ts b/packages/worker-api/src/testUtils/networks.ts index 2a5b885f..e2f5851a 100644 --- a/packages/worker-api/src/testUtils/networks.ts +++ b/packages/worker-api/src/testUtils/networks.ts @@ -39,9 +39,9 @@ export const localDockerNetwork = () => { chain: 'ws://127.0.0.1:9944', worker: 'wss://127.0.0.1:2000', genesisHash: '0x388c446a804e24e77ae89f5bb099edb60cacc2ac7c898ce175bdaa08629c1439', - mrenclave: 'GNKMuR4rnW54mcYqeAmNnH9Vibd6XsHdV2u62DgaG1bS', - shard: 'GNKMuR4rnW54mcYqeAmNnH9Vibd6XsHdV2u62DgaG1bS', - chosenCid: 'GNKMuR4rnW54mcYqeAmNnH9Vibd6XsHdV2u62DgaG1bS', + mrenclave: 'J8rq84Li1LzW8LxVEsvB1u55F8vUqiKiB3wHxh4YF8DJ', + shard: 'J8rq84Li1LzW8LxVEsvB1u55F8vUqiKiB3wHxh4YF8DJ', + chosenCid: 'J8rq84Li1LzW8LxVEsvB1u55F8vUqiKiB3wHxh4YF8DJ', customTypes: {}, palletOverrides: {} }; diff --git a/yarn.lock b/yarn.lock index 530782e6..745746e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -755,18 +755,18 @@ __metadata: languageName: node linkType: hard -"@encointer/node-api@npm:^0.17.0-alpha.2, @encointer/node-api@workspace:packages/node-api": +"@encointer/node-api@npm:^0.18.0-alpha.3, @encointer/node-api@workspace:packages/node-api": version: 0.0.0-use.local resolution: "@encointer/node-api@workspace:packages/node-api" dependencies: - "@encointer/types": "npm:^0.17.0-alpha.2" + "@encointer/types": "npm:^0.18.0-alpha.3" "@polkadot/api": "npm:^11.2.1" "@polkadot/util-crypto": "npm:^12.6.2" tslib: "npm:^2.6.2" languageName: unknown linkType: soft -"@encointer/types@npm:^0.17.0-alpha.2, @encointer/types@workspace:packages/types": +"@encointer/types@npm:^0.18.0-alpha.3, @encointer/types@workspace:packages/types": version: 0.0.0-use.local resolution: "@encointer/types@workspace:packages/types" dependencies: @@ -781,7 +781,7 @@ __metadata: languageName: unknown linkType: soft -"@encointer/util@npm:^0.17.0-alpha.2, @encointer/util@workspace:packages/util": +"@encointer/util@npm:^0.18.0-alpha.3, @encointer/util@workspace:packages/util": version: 0.0.0-use.local resolution: "@encointer/util@workspace:packages/util" dependencies: @@ -798,9 +798,9 @@ __metadata: version: 0.0.0-use.local resolution: "@encointer/worker-api@workspace:packages/worker-api" dependencies: - "@encointer/node-api": "npm:^0.17.0-alpha.2" - "@encointer/types": "npm:^0.17.0-alpha.2" - "@encointer/util": "npm:^0.17.0-alpha.2" + "@encointer/node-api": "npm:^0.18.0-alpha.3" + "@encointer/types": "npm:^0.18.0-alpha.3" + "@encointer/util": "npm:^0.18.0-alpha.3" "@peculiar/webcrypto": "npm:^1.4.6" "@polkadot/api": "npm:^11.2.1" "@polkadot/keyring": "npm:^12.6.2"