11import { LitActionResource , LitPKPResource } from '@lit-protocol/auth-helpers' ;
22import { log } from '@lit-protocol/misc' ;
33import { LitAbility } from '@lit-protocol/types' ;
4- import { getLitActionSessionSigs , getLitActionSessionSigsUsingIpfsId } from 'local-tests/setup/session-sigs/get-lit-action-session-sigs' ;
4+ import {
5+ getLitActionSessionSigs ,
6+ getLitActionSessionSigsUsingIpfsId ,
7+ } from 'local-tests/setup/session-sigs/get-lit-action-session-sigs' ;
58import { TinnyEnvironment } from 'local-tests/setup/tinny-environment' ;
69
710/**
@@ -10,113 +13,116 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
1013 * ✅ NETWORK=datil-test yarn test:local --filter=testUseTriaAuthAndWrappedKeysSessionSigsGen
1114 * ✅ NETWORK=datil yarn test:local --filter=testUseTriaAuthAndWrappedKeysSessionSigsGen
1215 */
13- export const testUseTriaAuthAndWrappedKeysSessionSigsGen =
14- async ( devEnv : TinnyEnvironment ) => {
16+ export const testUseTriaAuthAndWrappedKeysSessionSigsGen = async (
17+ devEnv : TinnyEnvironment
18+ ) => {
19+ const alice = await devEnv . createRandomPerson ( ) ;
1520
16- const alice = await devEnv . createRandomPerson ( ) ;
21+ // -- Start
1722
18- // -- Start
23+ // -- mint a pkp
24+ console . log ( `🔄 Minting new PKP...` ) ;
25+ const pkpMintRes =
26+ await devEnv . contractsClient . pkpNftContractUtils . write . mint ( ) ;
27+ const pkp = pkpMintRes . pkp ;
28+ console . log ( ` ✅ PKP minted:` ) ;
29+ console . log ( ` - Token ID: ${ pkp . tokenId } ` ) ;
30+ console . log ( ` - Public Key: ${ pkp . publicKey } ` ) ;
31+ console . log ( ` - ETH Address: ${ pkp . ethAddress } ` ) ;
1932
20- // -- mint a pkp
21- console . log ( `🔄 Minting new PKP...` ) ;
22- const pkpMintRes = await devEnv . contractsClient . pkpNftContractUtils . write . mint ( ) ;
23- const pkp = pkpMintRes . pkp ;
24- console . log ( ` ✅ PKP minted:` ) ;
25- console . log ( ` - Token ID: ${ pkp . tokenId } ` ) ;
26- console . log ( ` - Public Key: ${ pkp . publicKey } ` ) ;
27- console . log ( ` - ETH Address: ${ pkp . ethAddress } ` ) ;
33+ // -- mint capacity token
34+ console . log ( `🔄 Minting Capacity Credits NFT...` ) ;
35+ const capacityTokenId = (
36+ await devEnv . contractsClient . mintCapacityCreditsNFT ( {
37+ requestsPerKilosecond : 10 ,
38+ daysUntilUTCMidnightExpiration : 1 ,
39+ } )
40+ ) . capacityTokenIdStr ;
41+ console . log ( ` ✅ Capacity Credits NFT minted:` ) ;
2842
29- // -- mint capacity token
30- console . log ( `🔄 Minting Capacity Credits NFT...` ) ;
31- const capacityTokenId = (
32- await devEnv . contractsClient . mintCapacityCreditsNFT ( {
33- requestsPerKilosecond : 10 ,
34- daysUntilUTCMidnightExpiration : 1 ,
35- } )
36- ) . capacityTokenIdStr ;
37- console . log ( ` ✅ Capacity Credits NFT minted:` ) ;
38-
39- // -- create capacity delegation auth sig
40- console . log ( `🔄 Creating Capacity Delegation AuthSig...` ) ;
41- const authSigResponse = await devEnv . litNodeClient . createCapacityDelegationAuthSig ( {
43+ // -- create capacity delegation auth sig
44+ console . log ( `🔄 Creating Capacity Delegation AuthSig...` ) ;
45+ const authSigResponse =
46+ await devEnv . litNodeClient . createCapacityDelegationAuthSig ( {
4247 dAppOwnerWallet : alice . wallet ,
4348 capacityTokenId,
4449 delegateeAddresses : [ pkp . ethAddress ] ,
45- uses : "1" ,
50+ uses : '1' ,
4651 } ) ;
47- const capacityDelegationAuthSig = authSigResponse . capacityDelegationAuthSig ;
48- console . log ( ` ✅ Capacity Delegation AuthSig created:` ) ;
49- console . log ( ` - AuthSig: ${ JSON . stringify ( capacityDelegationAuthSig ) } ` ) ;
50- console . log ( ` - Uses: 1` ) ;
51- console . log ( ` - Delegatee Address: ${ pkp . ethAddress } ` ) ;
52- console . log ( ` - Capacity Token ID: ${ capacityTokenId } ` ) ;
53-
54- // -- Get the lit action code..
52+ const capacityDelegationAuthSig = authSigResponse . capacityDelegationAuthSig ;
53+ console . log ( ` ✅ Capacity Delegation AuthSig created:` ) ;
54+ console . log ( ` - AuthSig: ${ JSON . stringify ( capacityDelegationAuthSig ) } ` ) ;
55+ console . log ( ` - Uses: 1` ) ;
56+ console . log ( ` - Delegatee Address: ${ pkp . ethAddress } ` ) ;
57+ console . log ( ` - Capacity Token ID: ${ capacityTokenId } ` ) ;
5558
59+ // -- Get the lit action code..
5660
57- process . exit ( ) ;
61+ process . exit ( ) ;
5862
59- const litActionSessionSigs = await devEnv . litNodeClient . getLitActionSessionSigs ( {
63+ const litActionSessionSigs =
64+ await devEnv . litNodeClient . getLitActionSessionSigs ( {
6065 pkpPublicKey : alice . authMethodOwnedPkp . publicKey ,
6166 expiration : new Date ( Date . now ( ) + 1000 * 60 * 10 ) . toISOString ( ) , // 10 mins expiry
6267 resourceAbilityRequests : [
6368 {
64- resource : new LitPKPResource ( "*" ) ,
69+ resource : new LitPKPResource ( '*' ) ,
6570 ability : LitAbility . PKPSigning ,
6671 } ,
6772 {
68- resource : new LitActionResource ( "*" ) ,
73+ resource : new LitActionResource ( '*' ) ,
6974 ability : LitAbility . LitActionExecution ,
7075 } ,
7176 ] ,
72- litActionCode : Buffer . from ( `
77+ litActionCode : Buffer . from (
78+ `
7379 // Works with an AuthSig AuthMethod
7480 if (Lit.Auth.authMethodContexts.some(e => e.authMethodType === 1)) {
7581 LitActions.setResponse({ response: "true" });
7682 } else {
7783 LitActions.setResponse({ response: "false" });
7884 }
79- ` ) . toString ( "base64" ) ,
85+ `
86+ ) . toString ( 'base64' ) ,
8087 jsParams : {
8188 magicNumber : 42 ,
8289 } ,
8390 capabilityAuthSigs : [ capacityDelegationAuthSig ] ,
8491 } ) ;
8592
86- // const litActionSessionSigs = await getLitActionSessionSigs(devEnv, alice)
87-
88- console . log ( "litActionSessionSigs:" , litActionSessionSigs ) ;
89- process . exit ( ) ;
93+ // const litActionSessionSigs = await getLitActionSessionSigs(devEnv, alice)
9094
91- // -- Remove below
92- // const litActionSessionSigs = await getLitActionSessionSigsUsingIpfsId(
93- // devEnv,
94- // alice,
95- // [
96- // {
97- // resource: new LitPKPResource('*'),
98- // ability: LitAbility.PKPSigning,
99- // },
100- // {
101- // resource: new LitActionResource('*'),
102- // ability: LitAbility.LitActionExecution,
103- // },
104- // ]
105- // );
95+ console . log ( 'litActionSessionSigs:' , litActionSessionSigs ) ;
96+ process . exit ( ) ;
10697
107- // const res = await devEnv.litNodeClient.executeJs({
108- // sessionSigs: litActionSessionSigs,
109- // code: `(async () => {
110- // const sigShare = await LitActions.signEcdsa({
111- // toSign: dataToSign,
112- // publicKey,
113- // sigName: "sig",
114- // });
115- // })();`,
116- // jsParams: {
117- // dataToSign: alice.loveLetter,
118- // publicKey: alice.authMethodOwnedPkp.publicKey,
119- // },
120- // });
98+ // -- Remove below
99+ // const litActionSessionSigs = await getLitActionSessionSigsUsingIpfsId(
100+ // devEnv,
101+ // alice,
102+ // [
103+ // {
104+ // resource: new LitPKPResource('*'),
105+ // ability: LitAbility.PKPSigning,
106+ // },
107+ // {
108+ // resource: new LitActionResource('*'),
109+ // ability: LitAbility.LitActionExecution,
110+ // },
111+ // ]
112+ // );
121113
122- } ;
114+ // const res = await devEnv.litNodeClient.executeJs({
115+ // sessionSigs: litActionSessionSigs,
116+ // code: `(async () => {
117+ // const sigShare = await LitActions.signEcdsa({
118+ // toSign: dataToSign,
119+ // publicKey,
120+ // sigName: "sig",
121+ // });
122+ // })();`,
123+ // jsParams: {
124+ // dataToSign: alice.loveLetter,
125+ // publicKey: alice.authMethodOwnedPkp.publicKey,
126+ // },
127+ // });
128+ } ;
0 commit comments