Skip to content
Closed
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
4 changes: 4 additions & 0 deletions local-tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import { testBatchGeneratePrivateKeys } from './tests/wrapped-keys/testBatchGene

import { setLitActionsCodeToLocal } from './tests/wrapped-keys/util';
import { testUseEoaSessionSigsToRequestSingleResponse } from './tests/testUseEoaSessionSigsToRequestSingleResponse';
import { testUseTriaAuthAndWrappedKeysSessionSigsGen } from './tests/testUseTriaAuthAndWrappedKeysSessionSigsGen';

// Use the current LIT action code to test against
setLitActionsCodeToLocal();
Expand Down Expand Up @@ -171,7 +172,10 @@ setLitActionsCodeToLocal();
testUseEoaSessionSigsToEncryptDecryptString,
testUseEoaSessionSigsToEncryptDecryptFile,
testUseEoaSessionSigsToEncryptDecryptZip,

// single node execution
testUseEoaSessionSigsToRequestSingleResponse,
testUseTriaAuthAndWrappedKeysSessionSigsGen,
};

const pkpSessionSigsTests = {
Expand Down
112 changes: 112 additions & 0 deletions local-tests/tests/testUseTriaAuthAndWrappedKeysSessionSigsGen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { LitActionResource, LitPKPResource } from '@lit-protocol/auth-helpers';
import { log } from '@lit-protocol/misc';
import { LitAbility } from '@lit-protocol/types';
import {
getLitActionSessionSigs,
getLitActionSessionSigsUsingIpfsId,
} from 'local-tests/setup/session-sigs/get-lit-action-session-sigs';
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
import { api, utils } from '@lit-protocol/wrapped-keys';

import Hash from "typestub-ipfs-only-hash";
import { AuthMethodScope } from '@lit-protocol/constants';

const { triaBatchGeneratePrivateKeys, exportPrivateKey } = api;
/**
* Test Commands:
* ✅ NETWORK=datil-dev yarn test:local --filter=testUseTriaAuthAndWrappedKeysSessionSigsGen
* ✅ NETWORK=datil-test yarn test:local --filter=testUseTriaAuthAndWrappedKeysSessionSigsGen
* ✅ NETWORK=datil yarn test:local --filter=testUseTriaAuthAndWrappedKeysSessionSigsGen
*/
export const testUseTriaAuthAndWrappedKeysSessionSigsGen = async (
devEnv: TinnyEnvironment
) => {
const alice = await devEnv.createRandomPerson();

// -- Start
const triaAuthMethod = {
// authMethodId: '', <-- Tria's managing this by permitting auth method to the user id
authMethodType: process.env.TRIA_AUTHMETHOD_TYPE,
accessToken: process.env.TRIA_ACCESS_TOKEN,
};

// -- mint a pkp
console.log(`🔄 Minting new PKP...`);
const pkpMintRes =
await devEnv.contractsClient.pkpNftContractUtils.write.mint();
const pkp = pkpMintRes.pkp;
console.log(` ✅ PKP minted:`);
console.log(` - Token ID: ${pkp.tokenId}`);
console.log(` - Public Key: ${pkp.publicKey}`);
console.log(` - ETH Address: ${pkp.ethAddress}`);

// -- mint capacity token
console.log(`🔄 Minting Capacity Credits NFT...`);
const capacityTokenId = (
await devEnv.contractsClient.mintCapacityCreditsNFT({
requestsPerKilosecond: 10,
daysUntilUTCMidnightExpiration: 1,
})
).capacityTokenIdStr;
console.log(` ✅ Capacity Credits NFT minted:`);

// -- create capacity delegation auth sig
console.log(`🔄 Creating Capacity Delegation AuthSig...`);
const authSigResponse =
await devEnv.litNodeClient.createCapacityDelegationAuthSig({
dAppOwnerWallet: alice.wallet,
capacityTokenId,
delegateeAddresses: [pkp.ethAddress],
uses: '1',
});
const capacityDelegationAuthSig = authSigResponse.capacityDelegationAuthSig;
console.log(` ✅ Capacity Delegation AuthSig created:`);
console.log(` - AuthSig: ${JSON.stringify(capacityDelegationAuthSig)}`);
console.log(` - Uses: 1`);
console.log(` - Delegatee Address: ${pkp.ethAddress}`);
console.log(` - Capacity Token ID: ${capacityTokenId}`);

// -- Get the lit action code..
const { litActionCode, litActionIpfsCid } = utils.getLitActionCodeOrCidCommon(
'tria_batchGenerateEncryptedKeys'
);

// -- detect which one we got
const hashOfLitActionCode = litActionCode
? await Hash.of(Buffer.from(litActionCode))
: litActionIpfsCid;
console.log(` ✅ Lit Action Code IPFS CID: ${hashOfLitActionCode}`);

console.log(`🔄 Adding permitted action...`);
const permitTx = await devEnv.contractsClient.addPermittedAction({
ipfsId: hashOfLitActionCode,
pkpTokenId: pkp.tokenId,
authMethodScopes: [AuthMethodScope.SignAnything]
});
console.log(` ✅ Permitted action added:`);
console.log(` - Transaction Hash: ${permitTx.transactionHash}`);

const solanaMessageToSign = 'This is a test solana message';
const evmMessageToSign = 'This is a test evm message';

const { results } = await triaBatchGeneratePrivateKeys({
pkpPublicKey: pkp.publicKey,
ipfsId: hashOfLitActionCode,
actions: [
{
network: 'evm',
signMessageParams: { messageToSign: evmMessageToSign },
generateKeyParams: { memo: 'Test evm key' },
},
{
network: 'solana',
signMessageParams: { messageToSign: solanaMessageToSign },
generateKeyParams: { memo: 'Test solana key' },
},
],
litNodeClient: devEnv.litNodeClient,
authMethod: triaAuthMethod,
});

console.log("results:", results);
};
2 changes: 2 additions & 0 deletions local-tests/tests/wrapped-keys/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import type {

const emptyLitActionRepositoryCommon: LitActionCodeRepositoryCommon = {
batchGenerateEncryptedKeys: '',

tria_batchGenerateEncryptedKeys: '',
};

const emptyLitActionRepository: LitActionCodeRepository = {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"tslib": "^2.3.0",
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1",
"typestub-ipfs-only-hash": "^4.0.0",
"uint8arrays": "^4.0.3"
},
"devDependencies": {
Expand Down
7 changes: 6 additions & 1 deletion packages/misc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ export * from './lib/misc';
export {
validateSessionSig,
validateSessionSigs,
parseSignedMessage,
} from './lib/helper/session-sigs-validator';
export { formatSessionSigs } from './lib/helper/session-sigs-reader';
export {
formatSessionSigs,
formatSessionSigsJSON,
getResourcesFromSessionSigs
} from './lib/helper/session-sigs-reader';
Loading
Loading