From 9a39939d3cac607fc5e533f3ed078375f9ba0825 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 10:09:08 +0100 Subject: [PATCH 01/15] add placeholder for delegate to fix encoding --- .../types/src/interfaces/integriteeWorker/definitions.ts | 2 ++ packages/types/src/interfaces/integriteeWorker/types.ts | 2 ++ packages/worker-api/src/integriteeWorker.spec.ts | 3 ++- packages/worker-api/src/requests.ts | 2 ++ packages/worker-api/src/testUtils/networks.ts | 6 +++--- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index c6471b74..bc149fa9 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -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: { diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index 93cb1cc0..6dc3da6e 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -213,6 +213,7 @@ export interface IntegriteeTrustedCall extends Enum { export interface IntegriteeTrustedCallSigned extends Struct { readonly call: IntegriteeTrustedCall; readonly nonce: u32; + readonly delegate: Option, readonly signature: MultiSignature; } @@ -278,6 +279,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/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 5351c0c6..03ddb22b 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -42,7 +42,7 @@ describe('worker', () => { // skip it, as this requires a worker (and hence a node) to be running // To my knowledge jest does not have an option to run skipped tests specifically, does it? // Todo: add proper CI to test this too. - describe.skip('needs worker and node running', () => { + describe('needs worker and node running', () => { describe('getWorkerPubKey', () => { it('should return value', async () => { const result = await worker.getShieldingKey(); @@ -139,6 +139,7 @@ describe('worker', () => { describe('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, diff --git a/packages/worker-api/src/requests.ts b/packages/worker-api/src/requests.ts index cf32b1da..d2bef0bb 100644 --- a/packages/worker-api/src/requests.ts +++ b/packages/worker-api/src/requests.ts @@ -41,6 +41,7 @@ export async function signTrustedGetter(self: IWorkerBase, account: AddressOrPai const g = self.createType('IntegriteeGetter', { trusted: { getter, + delegate: null, signature: {Sr25519: signature}, } }); @@ -83,6 +84,7 @@ export const signTrustedCall = async ( return self.createType('IntegriteeTrustedCallSigned', { call: call, nonce: nonce, + 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: {} }; From ceb95a539bfab11f9d77a643eef377c5e7c14f7b Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 11:40:20 +0100 Subject: [PATCH 02/15] delegate getter and calls --- .../worker-api/src/integriteeWorker.spec.ts | 39 ++++++++++++++++++- packages/worker-api/src/integriteeWorker.ts | 3 +- packages/worker-api/src/interface.ts | 6 ++- packages/worker-api/src/requests.ts | 12 +++--- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 03ddb22b..2b039718 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -5,6 +5,7 @@ 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,6 +151,28 @@ describe('worker', () => { }); }); + describe.only('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('should return note of the executed trusted call', () => { it('should return balance transfer with note as note', async () => { const shard = network.shard; diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index efb11999..26b0277a 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -47,6 +47,7 @@ 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'); @@ -194,7 +195,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 d2bef0bb..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,11 +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: null, + delegate: options?.delegate ? asString(options.delegate) : null, signature: {Sr25519: signature}, } }); @@ -79,12 +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: null, + delegate: options?.delegate ? asString(options.delegate) : null, signature: {Sr25519: signature}, }); } From 0bcdbc4f7a6178ca5f28281f5ce49f83f2d83e89 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 13:25:40 +0100 Subject: [PATCH 03/15] add TrustedCalls --- .../integriteeWorker/definitions.ts | 20 ++++++++- .../src/interfaces/integriteeWorker/types.ts | 34 ++++++++++++-- .../worker-api/src/integriteeWorker.spec.ts | 44 +++++++++++++++++-- packages/worker-api/src/integriteeWorker.ts | 24 +++++++++- 4 files changed, 113 insertions(+), 9 deletions(-) diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index bc149fa9..27acfa91 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -157,7 +157,7 @@ export default { unused_index_17: null, unused_index_18: null, unused_index_19: null, - unused_index_20: null, + send_node: 'SendNoteArgs', unused_index_21: null, unused_index_22: null, unused_index_23: null, @@ -167,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, @@ -233,6 +233,22 @@ export default { AttemptsArg: { origin: 'AccountId' }, + SessionProxyRole: { + _enum: { + readBalance: null, + readAny: null, + nonTransfer: null, + any: null, + transferAllowance: 'Balance' + } + }, + SessionProxyCredentials: { + role: 'SessionProxyRole', + expiry: 'Moment', + seed: 'H256', + }, + AddSessionProxyArgs: '(AccountId, AccountId, SessionProxyCredentials)', + 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 6dc3da6e..9e878a0d 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -6,7 +6,7 @@ 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'; /** @name AttemptsArg */ export interface AttemptsArg extends Struct { @@ -22,6 +22,30 @@ 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 BalanceUnshieldArgs */ export interface BalanceUnshieldArgs extends ITuple<[AccountId, AccountId, BalanceType, ShardIdentifier]> {} @@ -174,7 +198,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 +209,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; @@ -221,6 +247,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; diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 2b039718..fa3ec2e9 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -1,5 +1,5 @@ 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"; @@ -151,7 +151,7 @@ describe('worker', () => { }); }); - describe.only('call signed by unauthorized delegate should fail', () => { + describe('call signed by unauthorized delegate should fail', () => { it('should fail', async () => { const shard = network.shard; //const testNote = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"; @@ -173,7 +173,7 @@ describe('worker', () => { }); }); - describe('should return note of the executed trusted call', () => { + 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"; @@ -210,6 +210,44 @@ describe('worker', () => { }); }); + // race condition so skipped + describe.only('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('call as delegate should work', async () => { + const shard = network.shard; + const result = await worker.trustedBalanceTransfer( + alice, + shard, + network.mrenclave, + alice.address, + charlie.address, + 1100000000000, + "My test note", + { delegate: charlie } + ); + console.log('delegated balance transfer result', JSON.stringify(result)); + expect(result).toBeDefined(); + }); + }); // 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 26b0277a..72b4f79d 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -8,7 +8,7 @@ import type { GuessTheNumberTrustedGetter, AttemptsArg, ParentchainsInfo, - NotesBucketInfo, TimestampedTrustedNote, + NotesBucketInfo, TimestampedTrustedNote, SessionProxyRole, } from '@encointer/types'; import { type ISubmittableGetter, @@ -141,6 +141,28 @@ 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 guessTheNumber( account: AddressOrPair, shard: string, From eaf3425ffec871a50967433231c6fa0004c339f8 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 15:35:43 +0100 Subject: [PATCH 04/15] fixed encoding --- packages/types/src/interfaces/integriteeWorker/definitions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index 27acfa91..308f34b0 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -244,7 +244,7 @@ export default { }, SessionProxyCredentials: { role: 'SessionProxyRole', - expiry: 'Moment', + expiry: 'Option', seed: 'H256', }, AddSessionProxyArgs: '(AccountId, AccountId, SessionProxyCredentials)', From 467c2a60848398e10c67da51b12c9bd5a61591f4 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 15:42:16 +0100 Subject: [PATCH 05/15] fix call as delegate --- packages/worker-api/src/integriteeWorker.spec.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index fa3ec2e9..1605f158 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -211,7 +211,7 @@ describe('worker', () => { }); // race condition so skipped - describe.only('session proxies (delegates) should work', () => { + describe.skip('session proxies (delegates) should work', () => { it('add delegate should work', async () => { const shard = network.shard; const now = new Date(); @@ -234,18 +234,24 @@ describe('worker', () => { 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, - charlie.address, + '5DwH48esFAmQWjaae7zvzzAbhRgS4enS7tfUPTbGr6ZFnW7R', 1100000000000, "My test note", - { delegate: charlie } + { 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 From 564bddd5b6000c8dc701b2bd978e5e3c1e520d98 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 15:50:42 +0100 Subject: [PATCH 06/15] sendNote works too --- .../integriteeWorker/definitions.ts | 2 +- .../worker-api/src/integriteeWorker.spec.ts | 20 +++++++++++++++++++ packages/worker-api/src/integriteeWorker.ts | 17 ++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index 308f34b0..4a5855a6 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -157,7 +157,7 @@ export default { unused_index_17: null, unused_index_18: null, unused_index_19: null, - send_node: 'SendNoteArgs', + send_note: 'SendNoteArgs', unused_index_21: null, unused_index_22: null, unused_index_23: null, diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 1605f158..2f8c620c 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -254,6 +254,26 @@ describe('worker', () => { expect(status.isInSidechainBlock).toBeTruthy(); }); }); + + // race condition so skipped + describe.only('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 72b4f79d..acd838b2 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -163,6 +163,23 @@ export class IntegriteeWorker extends Worker { 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, From 96f798ae450484620944a629a1a5b98040abbe85 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 15:54:11 +0100 Subject: [PATCH 07/15] cleanup --- packages/worker-api/src/integriteeWorker.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 2f8c620c..fb6657a9 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -43,7 +43,7 @@ describe('worker', () => { // skip it, as this requires a worker (and hence a node) to be running // To my knowledge jest does not have an option to run skipped tests specifically, does it? // Todo: add proper CI to test this too. - describe('needs worker and node running', () => { + describe.skip('needs worker and node running', () => { describe('getWorkerPubKey', () => { it('should return value', async () => { const result = await worker.getShieldingKey(); @@ -256,7 +256,7 @@ describe('worker', () => { }); // race condition so skipped - describe.only('send note should work', () => { + describe.skip('send note should work', () => { it('send note included', async () => { const shard = network.shard; const result = await worker.trustedSendNote( From afcb3d253cc97ac707d729052f44fbd979ffbc47 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 16:00:46 +0100 Subject: [PATCH 08/15] bump version 0.18.0-alpha.1 --- lerna.json | 2 +- packages/node-api/package.json | 4 ++-- packages/types/package.json | 2 +- packages/util/package.json | 2 +- packages/worker-api/package.json | 8 ++++---- yarn.lock | 14 +++++++------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lerna.json b/lerna.json index f6cff2d3..e2535ecd 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.1" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index 7d67c92b..7ab55b12 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -18,10 +18,10 @@ }, "sideEffects": false, "type": "module", - "version": "0.17.0-alpha.2", + "version": "0.18.0-alpha.1", "main": "index.js", "dependencies": { - "@encointer/types": "^0.17.0-alpha.2", + "@encointer/types": "^0.18.0-alpha.1", "@polkadot/api": "^11.2.1", "tslib": "^2.6.2" }, diff --git a/packages/types/package.json b/packages/types/package.json index 7ca0b36c..01882d1b 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -18,7 +18,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.17.0-alpha.2", + "version": "0.18.0-alpha.1", "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/util/package.json b/packages/util/package.json index 90782e8c..268db940 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -20,7 +20,7 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.17.0-alpha.2", + "version": "0.18.0-alpha.1", "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..5ea48fe7 100644 --- a/packages/worker-api/package.json +++ b/packages/worker-api/package.json @@ -19,12 +19,12 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.17.0-alpha.2", + "version": "0.18.0-alpha.1", "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.1", + "@encointer/types": "^0.18.0-alpha.1", + "@encointer/util": "^0.18.0-alpha.1", "@peculiar/webcrypto": "^1.4.6", "@polkadot/api": "^11.2.1", "@polkadot/keyring": "^12.6.2", diff --git a/yarn.lock b/yarn.lock index 530782e6..5ac23628 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.1, @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.1" "@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.1, @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.1, @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.1" + "@encointer/types": "npm:^0.18.0-alpha.1" + "@encointer/util": "npm:^0.18.0-alpha.1" "@peculiar/webcrypto": "npm:^1.4.6" "@polkadot/api": "npm:^11.2.1" "@polkadot/keyring": "npm:^12.6.2" From 1fa54c11ec73869718b9de521a143969c4cacc02 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 16:03:38 +0100 Subject: [PATCH 09/15] v0.18.0-alpha.0 --- lerna.json | 2 +- packages/node-api/package.json | 4 ++-- packages/types/package.json | 2 +- packages/util/package.json | 2 +- packages/worker-api/package.json | 8 ++++---- yarn.lock | 14 +++++++------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lerna.json b/lerna.json index e2535ecd..a27be52d 100644 --- a/lerna.json +++ b/lerna.json @@ -6,5 +6,5 @@ "publishConfig": { "directory": "build" }, - "version": "0.18.0-alpha.1" + "version": "0.18.0-alpha.0" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index 7ab55b12..5afd01c8 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -18,10 +18,10 @@ }, "sideEffects": false, "type": "module", - "version": "0.18.0-alpha.1", + "version": "0.18.0-alpha.0", "main": "index.js", "dependencies": { - "@encointer/types": "^0.18.0-alpha.1", + "@encointer/types": "^0.18.0-alpha.0", "@polkadot/api": "^11.2.1", "tslib": "^2.6.2" }, diff --git a/packages/types/package.json b/packages/types/package.json index 01882d1b..de2f7106 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -18,7 +18,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.18.0-alpha.1", + "version": "0.18.0-alpha.0", "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/util/package.json b/packages/util/package.json index 268db940..a3b4bb58 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -20,7 +20,7 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.18.0-alpha.1", + "version": "0.18.0-alpha.0", "main": "index.js", "dependencies": { "@babel/runtime": "^7.18.9", diff --git a/packages/worker-api/package.json b/packages/worker-api/package.json index 5ea48fe7..80a433b6 100644 --- a/packages/worker-api/package.json +++ b/packages/worker-api/package.json @@ -19,12 +19,12 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.18.0-alpha.1", + "version": "0.18.0-alpha.0", "main": "index.js", "dependencies": { - "@encointer/node-api": "^0.18.0-alpha.1", - "@encointer/types": "^0.18.0-alpha.1", - "@encointer/util": "^0.18.0-alpha.1", + "@encointer/node-api": "^0.18.0-alpha.0", + "@encointer/types": "^0.18.0-alpha.0", + "@encointer/util": "^0.18.0-alpha.0", "@peculiar/webcrypto": "^1.4.6", "@polkadot/api": "^11.2.1", "@polkadot/keyring": "^12.6.2", diff --git a/yarn.lock b/yarn.lock index 5ac23628..970cd2ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -755,18 +755,18 @@ __metadata: languageName: node linkType: hard -"@encointer/node-api@npm:^0.18.0-alpha.1, @encointer/node-api@workspace:packages/node-api": +"@encointer/node-api@npm:^0.18.0-alpha.0, @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.18.0-alpha.1" + "@encointer/types": "npm:^0.18.0-alpha.0" "@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.18.0-alpha.1, @encointer/types@workspace:packages/types": +"@encointer/types@npm:^0.18.0-alpha.0, @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.18.0-alpha.1, @encointer/util@workspace:packages/util": +"@encointer/util@npm:^0.18.0-alpha.0, @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.18.0-alpha.1" - "@encointer/types": "npm:^0.18.0-alpha.1" - "@encointer/util": "npm:^0.18.0-alpha.1" + "@encointer/node-api": "npm:^0.18.0-alpha.0" + "@encointer/types": "npm:^0.18.0-alpha.0" + "@encointer/util": "npm:^0.18.0-alpha.0" "@peculiar/webcrypto": "npm:^1.4.6" "@polkadot/api": "npm:^11.2.1" "@polkadot/keyring": "npm:^12.6.2" From b580214ccaaca72e692ec3445552f89ce3035fb9 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 16:07:56 +0100 Subject: [PATCH 10/15] v0.18.0-alpha.1 --- lerna.json | 2 +- packages/node-api/package.json | 5 +++-- packages/types/package.json | 3 ++- packages/util/package.json | 3 ++- packages/worker-api/package.json | 9 +++++---- yarn.lock | 14 +++++++------- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lerna.json b/lerna.json index a27be52d..e2535ecd 100644 --- a/lerna.json +++ b/lerna.json @@ -6,5 +6,5 @@ "publishConfig": { "directory": "build" }, - "version": "0.18.0-alpha.0" + "version": "0.18.0-alpha.1" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index 5afd01c8..772305ac 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.18.0-alpha.0", + "version": "0.18.0-alpha.1", "main": "index.js", "dependencies": { - "@encointer/types": "^0.18.0-alpha.0", + "@encointer/types": "^0.18.0-alpha.1", "@polkadot/api": "^11.2.1", "tslib": "^2.6.2" }, diff --git a/packages/types/package.json b/packages/types/package.json index de2f7106..d5f22454 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.18.0-alpha.0", + "version": "0.18.0-alpha.1", "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/util/package.json b/packages/util/package.json index a3b4bb58..20c7121d 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.18.0-alpha.0", + "version": "0.18.0-alpha.1", "main": "index.js", "dependencies": { "@babel/runtime": "^7.18.9", diff --git a/packages/worker-api/package.json b/packages/worker-api/package.json index 80a433b6..0ea2a06b 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.18.0-alpha.0", + "version": "0.18.0-alpha.1", "main": "index.js", "dependencies": { - "@encointer/node-api": "^0.18.0-alpha.0", - "@encointer/types": "^0.18.0-alpha.0", - "@encointer/util": "^0.18.0-alpha.0", + "@encointer/node-api": "^0.18.0-alpha.1", + "@encointer/types": "^0.18.0-alpha.1", + "@encointer/util": "^0.18.0-alpha.1", "@peculiar/webcrypto": "^1.4.6", "@polkadot/api": "^11.2.1", "@polkadot/keyring": "^12.6.2", diff --git a/yarn.lock b/yarn.lock index 970cd2ae..5ac23628 100644 --- a/yarn.lock +++ b/yarn.lock @@ -755,18 +755,18 @@ __metadata: languageName: node linkType: hard -"@encointer/node-api@npm:^0.18.0-alpha.0, @encointer/node-api@workspace:packages/node-api": +"@encointer/node-api@npm:^0.18.0-alpha.1, @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.18.0-alpha.0" + "@encointer/types": "npm:^0.18.0-alpha.1" "@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.18.0-alpha.0, @encointer/types@workspace:packages/types": +"@encointer/types@npm:^0.18.0-alpha.1, @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.18.0-alpha.0, @encointer/util@workspace:packages/util": +"@encointer/util@npm:^0.18.0-alpha.1, @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.18.0-alpha.0" - "@encointer/types": "npm:^0.18.0-alpha.0" - "@encointer/util": "npm:^0.18.0-alpha.0" + "@encointer/node-api": "npm:^0.18.0-alpha.1" + "@encointer/types": "npm:^0.18.0-alpha.1" + "@encointer/util": "npm:^0.18.0-alpha.1" "@peculiar/webcrypto": "npm:^1.4.6" "@polkadot/api": "npm:^11.2.1" "@polkadot/keyring": "npm:^12.6.2" From 59ba7b88ae4bb183201da9c23f9b57bbbf745689 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 17:13:04 +0100 Subject: [PATCH 11/15] add trusted getter AccountInfoAndSessionProxies --- .../src/interfaces/integriteeWorker/definitions.ts | 6 +++++- .../types/src/interfaces/integriteeWorker/types.ts | 7 +++++++ packages/worker-api/src/integriteeWorker.spec.ts | 12 +++++++++++- packages/worker-api/src/integriteeWorker.ts | 11 +++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index 4a5855a6..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, @@ -248,6 +248,10 @@ export default { seed: 'H256', }, AddSessionProxyArgs: '(AccountId, AccountId, SessionProxyCredentials)', + AccountInfoAndSessionProxies: { + account_info: 'AccountInfo', + session_proxies: 'Vec' + }, SendNoteArgs: '(AccountId, AccountId, String)', GuessTheNumberTrustedCall: { _enum: { diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index 9e878a0d..90bd2265 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -7,6 +7,7 @@ import type { Bytes, Enum, Option, Struct, Text, Vec, u16, u32, u64 } from '@pol 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 {AccountInfo} from "@polkadot/types/interfaces/system"; /** @name AttemptsArg */ export interface AttemptsArg extends Struct { @@ -46,6 +47,12 @@ export interface SessionProxyCredentials extends Struct { 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]> {} diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index fb6657a9..91c83be7 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -211,7 +211,7 @@ describe('worker', () => { }); // race condition so skipped - describe.skip('session proxies (delegates) should work', () => { + describe.only('session proxies (delegates) should work', () => { it('add delegate should work', async () => { const shard = network.shard; const now = new Date(); @@ -232,6 +232,16 @@ describe('worker', () => { 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 }); diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index acd838b2..a9ae0be3 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -6,6 +6,7 @@ import type { GuessTheNumberTrustedCall, GuessTheNumberPublicGetter, GuessTheNumberTrustedGetter, + AccountInfoAndSessionProxies, AttemptsArg, ParentchainsInfo, NotesBucketInfo, TimestampedTrustedNote, SessionProxyRole, @@ -53,6 +54,16 @@ export class IntegriteeWorker extends Worker { 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, From 1b1e6c95e0419b0b57fe4d19d7eb24e1c2feb672 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 17:20:11 +0100 Subject: [PATCH 12/15] disable e2e test --- packages/worker-api/src/integriteeWorker.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 91c83be7..ebdc5cfe 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -211,7 +211,7 @@ describe('worker', () => { }); // race condition so skipped - describe.only('session proxies (delegates) should work', () => { + describe.skip('session proxies (delegates) should work', () => { it('add delegate should work', async () => { const shard = network.shard; const now = new Date(); From 5b7bdf176cae339c2957a79bc6fcb44430af0a8d Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 17:22:54 +0100 Subject: [PATCH 13/15] v0.18.0-alpha.2 --- lerna.json | 2 +- packages/node-api/package.json | 4 ++-- packages/types/package.json | 2 +- packages/util/package.json | 2 +- packages/worker-api/package.json | 8 ++++---- yarn.lock | 14 +++++++------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lerna.json b/lerna.json index e2535ecd..f6a9edc3 100644 --- a/lerna.json +++ b/lerna.json @@ -6,5 +6,5 @@ "publishConfig": { "directory": "build" }, - "version": "0.18.0-alpha.1" + "version": "0.18.0-alpha.2" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index 772305ac..23ec183d 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -19,10 +19,10 @@ }, "sideEffects": false, "type": "module", - "version": "0.18.0-alpha.1", + "version": "0.18.0-alpha.2", "main": "index.js", "dependencies": { - "@encointer/types": "^0.18.0-alpha.1", + "@encointer/types": "^0.18.0-alpha.2", "@polkadot/api": "^11.2.1", "tslib": "^2.6.2" }, diff --git a/packages/types/package.json b/packages/types/package.json index d5f22454..f7f37f58 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -19,7 +19,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.18.0-alpha.1", + "version": "0.18.0-alpha.2", "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/util/package.json b/packages/util/package.json index 20c7121d..085180dd 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -21,7 +21,7 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.18.0-alpha.1", + "version": "0.18.0-alpha.2", "main": "index.js", "dependencies": { "@babel/runtime": "^7.18.9", diff --git a/packages/worker-api/package.json b/packages/worker-api/package.json index 0ea2a06b..99d950b9 100644 --- a/packages/worker-api/package.json +++ b/packages/worker-api/package.json @@ -20,12 +20,12 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.18.0-alpha.1", + "version": "0.18.0-alpha.2", "main": "index.js", "dependencies": { - "@encointer/node-api": "^0.18.0-alpha.1", - "@encointer/types": "^0.18.0-alpha.1", - "@encointer/util": "^0.18.0-alpha.1", + "@encointer/node-api": "^0.18.0-alpha.2", + "@encointer/types": "^0.18.0-alpha.2", + "@encointer/util": "^0.18.0-alpha.2", "@peculiar/webcrypto": "^1.4.6", "@polkadot/api": "^11.2.1", "@polkadot/keyring": "^12.6.2", diff --git a/yarn.lock b/yarn.lock index 5ac23628..c8e16d6f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -755,18 +755,18 @@ __metadata: languageName: node linkType: hard -"@encointer/node-api@npm:^0.18.0-alpha.1, @encointer/node-api@workspace:packages/node-api": +"@encointer/node-api@npm:^0.18.0-alpha.2, @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.18.0-alpha.1" + "@encointer/types": "npm:^0.18.0-alpha.2" "@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.18.0-alpha.1, @encointer/types@workspace:packages/types": +"@encointer/types@npm:^0.18.0-alpha.2, @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.18.0-alpha.1, @encointer/util@workspace:packages/util": +"@encointer/util@npm:^0.18.0-alpha.2, @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.18.0-alpha.1" - "@encointer/types": "npm:^0.18.0-alpha.1" - "@encointer/util": "npm:^0.18.0-alpha.1" + "@encointer/node-api": "npm:^0.18.0-alpha.2" + "@encointer/types": "npm:^0.18.0-alpha.2" + "@encointer/util": "npm:^0.18.0-alpha.2" "@peculiar/webcrypto": "npm:^1.4.6" "@polkadot/api": "npm:^11.2.1" "@polkadot/keyring": "npm:^12.6.2" From 6c587337850d72900c2fe2acdec70283f2c1269b Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Tue, 10 Dec 2024 17:24:34 +0100 Subject: [PATCH 14/15] fix missing delegate forwards --- packages/worker-api/src/integriteeWorker.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index a9ae0be3..33cf932f 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -83,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]); @@ -101,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)}); From a32ae2fd0ae50bf58c54c14db90358e712720b7c Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Tue, 10 Dec 2024 17:25:06 +0100 Subject: [PATCH 15/15] v0.18.0-alpha.3 --- lerna.json | 2 +- packages/node-api/package.json | 4 ++-- packages/types/package.json | 2 +- packages/util/package.json | 2 +- packages/worker-api/package.json | 8 ++++---- yarn.lock | 14 +++++++------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lerna.json b/lerna.json index f6a9edc3..b9194a18 100644 --- a/lerna.json +++ b/lerna.json @@ -6,5 +6,5 @@ "publishConfig": { "directory": "build" }, - "version": "0.18.0-alpha.2" + "version": "0.18.0-alpha.3" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index 23ec183d..e73fa54f 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -19,10 +19,10 @@ }, "sideEffects": false, "type": "module", - "version": "0.18.0-alpha.2", + "version": "0.18.0-alpha.3", "main": "index.js", "dependencies": { - "@encointer/types": "^0.18.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 f7f37f58..8e10fc74 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -19,7 +19,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.18.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/util/package.json b/packages/util/package.json index 085180dd..6e4f0541 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -21,7 +21,7 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.18.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 99d950b9..cdd133df 100644 --- a/packages/worker-api/package.json +++ b/packages/worker-api/package.json @@ -20,12 +20,12 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.18.0-alpha.2", + "version": "0.18.0-alpha.3", "main": "index.js", "dependencies": { - "@encointer/node-api": "^0.18.0-alpha.2", - "@encointer/types": "^0.18.0-alpha.2", - "@encointer/util": "^0.18.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/yarn.lock b/yarn.lock index c8e16d6f..745746e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -755,18 +755,18 @@ __metadata: languageName: node linkType: hard -"@encointer/node-api@npm:^0.18.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.18.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.18.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.18.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.18.0-alpha.2" - "@encointer/types": "npm:^0.18.0-alpha.2" - "@encointer/util": "npm:^0.18.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"