Skip to content

Commit 9e76a22

Browse files
committed
Merge branch 'wyatt/sdkv7-bug'
2 parents 83332d6 + 91bbd4e commit 9e76a22

File tree

8 files changed

+731
-62
lines changed

8 files changed

+731
-62
lines changed

session-signatures/generating-a-session/using-pkp/auth-with-google-oauth/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
"dependencies": {
1414
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
1515
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
16-
"@lit-protocol/auth-helpers": "^7.0.2",
17-
"@lit-protocol/constants": "^7.0.2",
18-
"@lit-protocol/contracts-sdk": "^7.0.2",
19-
"@lit-protocol/lit-auth-client": "^7.0.2",
20-
"@lit-protocol/lit-node-client": "^7.0.2",
21-
"@lit-protocol/types": "^7.0.2",
16+
"@lit-protocol/auth-helpers": "^6.0.0",
17+
"@lit-protocol/constants": "^6.0.0",
18+
"@lit-protocol/contracts-sdk": "^6.0.0",
19+
"@lit-protocol/lit-auth-client": "^6.0.0",
20+
"@lit-protocol/lit-node-client": "^6.0.0",
21+
"@lit-protocol/types": "^6.0.0",
2222
"@react-oauth/google": "^0.12.1",
2323
"@simplewebauthn/browser": "^10.0.0",
2424
"@vitejs/plugin-react-swc": "^3.7.0",

session-signatures/generating-a-session/using-pkp/auth-with-google-oauth/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '@react-oauth/google';
77
import * as jwt_decode from 'jwt-decode';
88
import type { SigResponse } from '@lit-protocol/types';
9+
import { ethers } from 'ethers';
910

1011
import './App.css';
1112
import { mintPkp } from './mintPkp';

session-signatures/generating-a-session/using-pkp/auth-with-google-oauth/src/getPkpSessionSigs.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { LitNodeClient } from '@lit-protocol/lit-node-client';
2-
import {
3-
LIT_NETWORK as _LIT_NETWORK,
4-
LIT_ABILITY,
5-
} from '@lit-protocol/constants';
1+
import { disconnectWeb3, LitNodeClient } from '@lit-protocol/lit-node-client';
2+
import { LIT_NETWORK as _LIT_NETWORK } from '@lit-protocol/constants';
63
import { LitPKPResource } from '@lit-protocol/auth-helpers';
74

85
import type { MintedPkp } from './types';
96
import { litActionCode } from './litAction';
107
import { getCapacityCredit, getEthersSigner, getLitNodeClient } from './utils';
8+
import { LitAbility } from '@lit-protocol/types';
119

1210
const LIT_NETWORK =
1311
_LIT_NETWORK[import.meta.env.VITE_LIT_NETWORK as keyof typeof _LIT_NETWORK];
@@ -57,7 +55,7 @@ export const getPkpSessionSigs = async (
5755
resourceAbilityRequests: [
5856
{
5957
resource: new LitPKPResource('*'),
60-
ability: LIT_ABILITY.PKPSigning,
58+
ability: LitAbility.PKPSigning,
6159
},
6260
],
6361
expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes
@@ -68,5 +66,8 @@ export const getPkpSessionSigs = async (
6866
return sessionSignatures;
6967
} catch (error) {
7068
console.error(error);
69+
} finally {
70+
disconnectWeb3();
71+
litNodeClient!.disconnect();
7172
}
7273
};

session-signatures/generating-a-session/using-pkp/auth-with-google-oauth/src/litAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ declare global {
88
const _litActionCode = async () => {
99
// const GOOGLE_JWT_AUTH_METHOD_TYPE = 6;
1010
const GOOGLE_JWT_AUTH_METHOD_TYPE = ethers.utils.keccak256(
11-
ethers.utils.toUtf8Bytes('Lit Developer Guide GitHub Auth Example')
11+
ethers.utils.toUtf8Bytes('Lit Developer Guide Google Auth Example')
1212
);
1313

1414
try {

session-signatures/generating-a-session/using-pkp/auth-with-google-oauth/src/mintPkp.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import {
22
LIT_NETWORK as _LIT_NETWORK,
3-
AUTH_METHOD_SCOPE,
4-
AUTH_METHOD_TYPE,
3+
AuthMethodScope,
4+
AuthMethodType,
55
} from '@lit-protocol/constants';
6-
import { ethers } from 'ethers';
76
import bs58 from 'bs58';
8-
7+
import { ethers } from 'ethers';
98
import {
109
getEthersSigner,
1110
getGoogleAuthMethodInfo,
@@ -27,24 +26,23 @@ export const mintPkp = async (googleUser: GoogleUser) => {
2726
const { authMethodType, authMethodId } =
2827
getGoogleAuthMethodInfo(googleUser);
2928

29+
const GOOGLE_JWT_AUTH_METHOD_TYPE = ethers.utils.keccak256(
30+
ethers.utils.toUtf8Bytes('Lit Developer Guide Google Auth Example')
31+
);
32+
3033
console.log('🔄 Minting new PKP...');
3134
const tx =
3235
await litContracts.pkpHelperContract.write.mintNextAndAddAuthMethods(
33-
AUTH_METHOD_TYPE.LitAction, // keyType
34-
[
35-
AUTH_METHOD_TYPE.LitAction,
36-
ethers.utils.keccak256(
37-
ethers.utils.toUtf8Bytes('Lit Developer Guide GitHub Auth Example')
38-
),
39-
], // permittedAuthMethodTypes
36+
AuthMethodType.LitAction, // keyType
37+
[AuthMethodType.LitAction, GOOGLE_JWT_AUTH_METHOD_TYPE], // permittedAuthMethodTypes
4038
[
4139
`0x${Buffer.from(
4240
bs58.decode(await getLitActionCodeIpfsCid())
4341
).toString('hex')}`,
4442
authMethodId,
4543
], // permittedAuthMethodIds
4644
['0x', '0x'], // permittedAuthMethodPubkeys
47-
[[AUTH_METHOD_SCOPE.SignAnything], [AUTH_METHOD_SCOPE.NoPermissions]], // permittedAuthMethodScopes
45+
[[AuthMethodScope.SignAnything], [AuthMethodScope.NoPermissions]], // permittedAuthMethodScopes
4846
true, // addPkpEthAddressAsPermittedAddress
4947
true, // sendPkpToItself
5048
{ value: pkpMintCost }

session-signatures/generating-a-session/using-pkp/auth-with-google-oauth/src/pkpSign.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ethers } from 'ethers';
2-
import { LitNodeClient } from '@lit-protocol/lit-node-client';
2+
import { disconnectWeb3, LitNodeClient } from '@lit-protocol/lit-node-client';
33
import { LIT_NETWORK as _LIT_NETWORK } from '@lit-protocol/constants';
44

55
import { getLitNodeClient } from './utils';
@@ -17,8 +17,6 @@ export const pkpSign = async (
1717
console.log('🔄 Signing data with PKP...');
1818
litNodeClient = await getLitNodeClient(LIT_NETWORK);
1919

20-
console.log(litSessionSigs, pkpPublicKey, dataToSign);
21-
2220
const res = await litNodeClient.pkpSign({
2321
pubKey: pkpPublicKey,
2422
sessionSigs: litSessionSigs,
@@ -30,5 +28,8 @@ export const pkpSign = async (
3028
return res;
3129
} catch (error) {
3230
console.error(error);
31+
} finally {
32+
disconnectWeb3();
33+
litNodeClient!.disconnect();
3334
}
3435
};

session-signatures/generating-a-session/using-pkp/auth-with-google-oauth/src/utils.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { ethers } from 'ethers';
22
import { LitContracts } from '@lit-protocol/contracts-sdk';
3-
import { AUTH_METHOD_TYPE, LIT_NETWORK } from '@lit-protocol/constants';
3+
import { AuthMethodType, LIT_NETWORK } from '@lit-protocol/constants';
44
import { LitNodeClient } from '@lit-protocol/lit-node-client';
5-
import * as IpfsHash from 'typestub-ipfs-only-hash';
5+
// import * as IpfsHash from 'typestub-ipfs-only-hash';
6+
// @ts-ignore
7+
import IpfsHash from 'ipfs-only-hash';
8+
import bs58 from 'bs58';
69

710
import type { GoogleUser } from './types';
811
import { litActionCode } from './litAction';
@@ -27,6 +30,7 @@ export const getLitNodeClient = async (
2730
if (litNodeClient === null) {
2831
console.log(`🔄 Connecting LitNode client to the ${litNetwork} network...`);
2932
litNodeClient = new LitNodeClient({
33+
// @ts-ignore
3034
litNetwork,
3135
debug: Boolean(import.meta.env.VITE_LIT_DEBUG),
3236
});
@@ -46,6 +50,7 @@ export const getLitContractsClient = async (
4650
console.log('🔄 Connecting LitContracts client to the network...');
4751
litContractClient = new LitContracts({
4852
signer: ethersSigner,
53+
// @ts-ignore
4954
network: litNetwork,
5055
});
5156
await litContractClient.connect();
@@ -58,7 +63,7 @@ export const getLitContractsClient = async (
5863
export const getGoogleAuthMethodInfo = (googleUser: GoogleUser) => {
5964
console.log('🔄 Generating Auth Method type and ID...');
6065
const authMethodInfo = {
61-
authMethodType: AUTH_METHOD_TYPE.GoogleJwt,
66+
authMethodType: AuthMethodType.GoogleJwt,
6267
// Taken from here:
6368
// https://github.com/LIT-Protocol/js-sdk/blob/806264ace642c4c3f4fe1dc4f4c1067cdf54ef27/packages/lit-auth-client/src/lib/providers/GoogleProvider.ts#L216C3-L224C4
6469
authMethodId: ethers.utils.keccak256(
@@ -78,10 +83,22 @@ export const getPkpMintCost = async (litContracts: LitContracts) => {
7883
return pkpMintCost;
7984
};
8085

86+
// export const getLitActionCodeIpfsCid = async () => {
87+
// console.log('🔄 Calculating the IPFS CID for Lit Action code string...');
88+
// const litActionIpfsCid = await IpfsHash.of(litActionCode);
89+
// console.log(`✅ Calculated IPFS CID: ${litActionIpfsCid}`);
90+
91+
// return litActionIpfsCid;
92+
// };
93+
8194
export const getLitActionCodeIpfsCid = async () => {
8295
console.log('🔄 Calculating the IPFS CID for Lit Action code string...');
8396
const litActionIpfsCid = await IpfsHash.of(litActionCode);
84-
console.log(`✅ Calculated IPFS CID: ${litActionIpfsCid}`);
97+
console.log(
98+
`✅ Calculated IPFS CID: ${litActionIpfsCid}. Hexlified version: 0x${Buffer.from(
99+
bs58.decode(litActionIpfsCid)
100+
).toString('hex')}`
101+
);
85102

86103
return litActionIpfsCid;
87104
};

0 commit comments

Comments
 (0)