Skip to content

Feat/datil clonenet test #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions local-tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import { testFailBatchGeneratePrivateKeysAtomic } from './tests/wrapped-keys/tes

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

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

const pkpSessionSigsTests = {
Expand Down
69 changes: 69 additions & 0 deletions local-tests/tests/testUseEoaSessionSigsClaimAndMint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { log } from '@lit-protocol/misc';
import { getEoaSessionSigs } from 'local-tests/setup/session-sigs/get-eoa-session-sigs';
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';

/**
* Test Commands:
* NETWORK=datil-dev yarn test:local --filter=testUseEoaSessionSigsClaimAndMint
* NETWORK=datil-test yarn test:local --filter=testUseEoaSessionSigsClaimAndMint
* NETWORK=custom yarn test:local --filter=testUseEoaSessionSigsClaimAndMint
*/
export const testUseEoaSessionSigsClaimAndMint = async (
devEnv: TinnyEnvironment
) => {
const alice = await devEnv.createRandomPerson();

const eoaSessionSigs = await getEoaSessionSigs(devEnv, alice);

const { claims } = await devEnv.litNodeClient.executeJs({
sessionSigs: eoaSessionSigs,
code: `(async () => {
Lit.Actions.claimKey({ keyId: "keyId" });
})();`,
});

const { signatures, derivedKeyId } = claims.keyId;

console.log('signatures:', signatures);
console.log('derivedKeyId:', derivedKeyId);

const keyType = 2;

const claimMaterial = {
keyType: keyType,
derivedKeyId: `0x${derivedKeyId}`,
signatures: signatures,
};

const authMethodData = {
keyType: keyType,
permittedIpfsCIDs: [],
permittedIpfsCIDScopes: [],
permittedAddresses: [],
permittedAddressScopes: [],
permittedAuthMethodTypes: [alice.authMethod.authMethodType],
permittedAuthMethodIds: [await alice.getAuthMethodId()],
permittedAuthMethodPubkeys: [`0x${alice.pkp.publicKey}`],
permittedAuthMethodScopes: [],
addPkpEthAddressAsPermittedAddress: true,
addPkpPubkeyAsPermittedAuthMethod: true,
sendPkpToItself: true,
};

const tx =
await devEnv.contractsClient.pkpHelperContract.write.claimAndMintNextAndAddAuthMethodsWithTypes(
claimMaterial,
authMethodData,
{
gasLimit: 500000,
}
);

console.log('tx:', tx);

devEnv.releasePrivateKeyFromUser(alice);

// Expected output:

log('✅ testUseEoaSessionSigsClaimAndMint');
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@cosmjs/stargate": "0.30.1",
"@dotenvx/dotenvx": "^1.6.4",
"@lit-protocol/accs-schemas": "^0.0.15",
"@lit-protocol/contracts": "^0.0.63",
"@lit-protocol/contracts": "^0.0.71",
"@metamask/eth-sig-util": "5.0.2",
"@mysten/sui.js": "^0.37.1",
"@openagenda/verror": "^3.1.4",
Expand Down
68 changes: 68 additions & 0 deletions packages/contracts-sdk/src/lib/contracts-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,74 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
}
};

/**
* Claims and mints a PKP with auth methods
* @param {Object} params - The parameters object
* @param {Object} params.claimMaterial - The claim material containing keyType, derivedKeyId and signatures
* @param {number} params.claimMaterial.keyType - The type of key to mint
* @param {string} params.claimMaterial.derivedKeyId - The derived key ID
* @param {Array<{signature: string, derivedKeyId: string, signedData: string}>} params.claimMaterial.signatures - Array of signature objects
* @param {Object} params.authMethodData - The auth method data for permissions
* @param {number} params.authMethodData.keyType - The type of key
* @param {string[]} params.authMethodData.permittedIpfsCIDs - Permitted IPFS CIDs
* @param {string[][]} params.authMethodData.permittedIpfsCIDScopes - Scopes for permitted IPFS CIDs
* @param {string[]} params.authMethodData.permittedAddresses - Permitted addresses
* @param {string[][]} params.authMethodData.permittedAddressScopes - Scopes for permitted addresses
* @param {number[]} params.authMethodData.permittedAuthMethodTypes - Types of permitted auth methods
* @param {string[]} params.authMethodData.permittedAuthMethodIds - IDs of permitted auth methods
* @param {string[]} params.authMethodData.permittedAuthMethodPubkeys - Public keys of permitted auth methods
* @param {string[][]} params.authMethodData.permittedAuthMethodScopes - Scopes for permitted auth methods
* @param {boolean} params.authMethodData.addPkpEthAddressAsPermittedAddress - Whether to add PKP ETH address
* @param {boolean} params.authMethodData.addPkpPubkeyAsPermittedAuthMethod - Whether to add PKP pubkey
* @param {boolean} params.authMethodData.sendPkpToItself - Whether to send PKP to itself
* @returns {Promise<ethers.ContractTransaction>} The transaction result
*/
claimAndMintPKPWithAuth = async ({
claimMaterial,
authMethodData,
}: {
claimMaterial: {
keyType: number;
derivedKeyId: string;
signatures: Array<{
r: `0x${string}` | string;
s: `0x${string}` | string;
v: number;
}>;
};
authMethodData: {
keyType: number;
permittedIpfsCIDs: string[];
permittedIpfsCIDScopes: string[][];
permittedAddresses: string[];
permittedAddressScopes: string[][];
permittedAuthMethodTypes: number[];
permittedAuthMethodIds: string[];
permittedAuthMethodPubkeys: string[];
permittedAuthMethodScopes: string[][];
addPkpEthAddressAsPermittedAddress: boolean;
addPkpPubkeyAsPermittedAuthMethod: boolean;
sendPkpToItself: boolean;
};
}): Promise<ethers.ContractTransaction> => {
// Ensure derivedKeyId has 0x prefix
const derivedKeyId = claimMaterial.derivedKeyId.startsWith('0x')
? claimMaterial.derivedKeyId
: `0x${claimMaterial.derivedKeyId}`;

claimMaterial.derivedKeyId = derivedKeyId;

const tx = await this._callWithAdjustedOverrides(
this.pkpHelperContract.write,
'claimAndMintNextAndAddAuthMethodsWithTypes',
[claimMaterial, authMethodData]
);

this.log('Claim and mint PKP with auth method tx:', tx);

return tx;
};

// getRandomPrivateKeySignerProvider = () => {
// const privateKey = ethers.utils.hexlify(ethers.utils.randomBytes(32));

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3042,10 +3042,10 @@
dependencies:
ajv "^8.12.0"

"@lit-protocol/contracts@^0.0.63":
version "0.0.63"
resolved "https://registry.yarnpkg.com/@lit-protocol/contracts/-/contracts-0.0.63.tgz#8700c37df9d2422e9c97aa27871fb64de6186f6c"
integrity sha512-CAorNt72ybIY/g//dDeR837izNGuYQR99XwPSK2X2AJ6c+aZX1kdXCrOnxsbY40BzFrOk/dIFo+ymJ9E3qh48w==
"@lit-protocol/contracts@^0.0.71":
version "0.0.71"
resolved "https://registry.yarnpkg.com/@lit-protocol/contracts/-/contracts-0.0.71.tgz#f436b35a4cfe5b49e7ceaf3ea1dc4d73ad953c53"
integrity sha512-T5cPgo7tZG3+qLmNk2KDbB5t8f0yBThJEVs5lxsagkhZaabx0AOte0kJpGioWICvlaiGYKtACWh6ukBEo3bKzw==

"@ljharb/resumer@~0.0.1":
version "0.0.1"
Expand Down
Loading