From 1aa77f330b34c706817b4f7c6d6917efe12b0e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Mon, 4 Nov 2024 17:35:06 +0100 Subject: [PATCH] [TEMP COMMIT] Show how self-delegation works in an example This currently works with tapir ritual 6, but only because it uses OpenAccessAuthorizer. In reality, this will fail with GlobalAllowList since this needs proper validation of evidence authorization. This commit should be deleted before merging the PR, it's just illustrative --- examples/taco/nodejs/src/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/taco/nodejs/src/index.ts b/examples/taco/nodejs/src/index.ts index ef4550ab..4309cb0b 100644 --- a/examples/taco/nodejs/src/index.ts +++ b/examples/taco/nodejs/src/index.ts @@ -13,10 +13,11 @@ import { } from '@nucypher/taco'; import { EIP4361AuthProvider, + SelfDelegateProvider, USER_ADDRESS_PARAM_DEFAULT, } from '@nucypher/taco-auth'; import * as dotenv from 'dotenv'; -import { ethers } from 'ethers'; +import { Wallet, ethers } from 'ethers'; dotenv.config(); @@ -73,13 +74,17 @@ const encryptToBytes = async (messageString: string) => { 'Condition requires authentication', ); + const selfDelegateProvider = new SelfDelegateProvider(encryptorSigner); + const ephemeralPrivateKey = Wallet.createRandom().privateKey; + const [appSideSigner, authSignature] = await selfDelegateProvider.createSelfDelegatedAppSideSigner(ephemeralPrivateKey); + const messageKit = await encrypt( provider, domain, message, hasPositiveBalance, ritualId, - encryptorSigner, + appSideSigner, ); return messageKit.toBytes();