Skip to content
Merged
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
8 changes: 4 additions & 4 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"homepage": "https://github.com/ava-labs/avalanche-sdk-typescript/tree/main/client#readme",
"browser": "./dist/avalanche-sdk-client.js",
"dependencies": {
"@avalabs/avalanchejs": "^5.0.0",
"@avalabs/avalanchejs": "^5.1.0-alpha.1",
"@noble/hashes": "1.3.3",
"@noble/secp256k1": "2.0.0",
"util": "^0.12.5",
Expand Down
6 changes: 3 additions & 3 deletions client/src/clients/createAvalancheWalletClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { CChainRpcSchema } from "src/methods/cChain/cChainRpcSchema.js";
import { PChainRpcSchema } from "src/methods/pChain/pChainRpcSchema.js";
import { XChainRpcSchema } from "src/methods/xChain/xChainRpcSchema.js";
import {
Account,
Chain,
Expand All @@ -18,8 +15,11 @@ import {
WalletRpcSchema,
} from "viem";
import { XPAccount } from "../accounts/avalancheAccount.js";
import { CChainRpcSchema } from "../methods/cChain/cChainRpcSchema.js";
import { PChainRpcSchema } from "../methods/pChain/pChainRpcSchema.js";
import { AvalanchePublicRpcSchema } from "../methods/public/avalanchePublicRpcSchema.js";
import { AvalancheWalletRpcSchema } from "../methods/wallet/avalancheWalletRPCSchema.js";
import { XChainRpcSchema } from "../methods/xChain/xChainRpcSchema.js";
import { AvalancheCoreClient } from "./createAvalancheCoreClient.js";
import {
AvalancheWalletCoreClient,
Expand Down
1 change: 1 addition & 0 deletions client/src/clients/decorators/avalanche.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ test("default", async () => {
"getGasPrice": [Function],
"getLogs": [Function],
"getProof": [Function],
"getRegistrationJustification": [Function],
"getStorageAt": [Function],
"getTransaction": [Function],
"getTransactionConfirmations": [Function],
Expand Down
45 changes: 45 additions & 0 deletions client/src/clients/decorators/avalanchePublic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,37 @@ const mockTransport = () =>
},
},
};
case "eth_blockNumber":
return "0x1000";
case "eth_getLogs":
return [
{
eventName: "SendWarpMessage",
args: {
sourceAddress: "0xfAcadE0000000000000000000000000000000000",
unsignedMessageID:
"0x9e883c90bee7398d20cf3dd1e96b53a1b8b929833888532e2a2e37f2f6067c39",
message:
"0x00000000000595d7bbe6942f60afd7be8091b89d4e4ed6183862605809c5395dca8dde94b3a3000000d800000000000100000014facade0000010000000000000000000000000000000000b60000000000019fc4f2405328995ed8bf88798e9ff7e310a5bd1918874000000147c9968cefdb8445b2426dd020f12d246defcb11294ab445df7ca4158cf63b66b6c463e9995b380441863f89231d3cd468ecdf7a96b080d3e96e20d74d9f2cd4f96d9dc40000000006931432e0000000100000001fc29235b2bdabea93b3546331fc8dc3a941391b80000000100000001fc29235b2bdabea93b3546331fc8dc3a941391b8000000000000000a",
},
address: "0x0200000000000000000000000000000000000005",
topics: [
"0x56600c567728a800c0aa927500f831cb451df66a7af570eb4df4dfbf4674887d",
"0x000000000000000000000000facade0000000000000000000000000000000000",
"0x9e883c90bee7398d20cf3dd1e96b53a1b8b929833888532e2a2e37f2f6067c39",
],
data: "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000010200000000000595d7bbe6942f60afd7be8091b89d4e4ed6183862605809c5395dca8dde94b3a3000000d800000000000100000014facade0000000000000000000000000000000000000000b60000000000019fc4f2405328995ed8bf8879cf83459efe1402691368e9ff7e310a5bd1918874000000147c9968cefdb8445b2426dd020f12d246defcb11294ab445df7ca4158cf63b66b6c463e9995b380441863f89231d3cd468ecdf7a96b080d3e96e20d74d9f2cd4f96d9dc40000000006931432e0000000100000001fc29235b2bdabea93b3546331fc8dc3a941391b80000000100000001fc29235b2bdabea93b3546331fc8dc3a941391b8000000000000000a000000000000000000000000000000000000000000000000000000000000",
blockNumber: 6n,
transactionHash:
"0xa8935a010bb7bdea63580b8fc366641f801d2e7a86d98b6b5ade3b33bf5ecdce",
transactionIndex: 0,
blockHash:
"0xba44797cac7ba95176f4fc5e1395cea55f8e766782bc9625031117e067641fe6",
logIndex: 0,
removed: false,
},
];

// TODO: add proper responses for the rest of the methods
// The default case is just a placeholder to satisfy the test
default:
Expand All @@ -98,6 +129,7 @@ test("default", async () => {
"feeConfig": [Function],
"getActiveRulesAt": [Function],
"getChainConfig": [Function],
"getRegistrationJustification": [Function],
"maxPriorityFeePerGas": [Function],
}`);
});
Expand Down Expand Up @@ -183,4 +215,17 @@ describe("smoke test", () => {
},
});
});

test("getRegistrationJustification", async () => {
const res = await avalanchePublicClient.getRegistrationJustification({
validationID:
"0x5ecf5d9c6fe20c4e43afda8f5cc97e7baef800ed485a60f7370fe26fdea75e3a",
subnetIDStr: "2DN6PTi2uXNCzzNz1p2ckGcW2eqTfpt2kv2a1h7EV36hYV3XRJ",
maxBootstrapValidators: 100,
chunkSize: 200,
maxChunks: 100,
});
expect(res.error).toBeUndefined();
expect(res.justification).not.toBeNull();
});
});
67 changes: 67 additions & 0 deletions client/src/clients/decorators/avalanchePublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { baseFee } from "../../methods/public/baseFee.js";
import { feeConfig } from "../../methods/public/feeConfig.js";
import { getActiveRulesAt } from "../../methods/public/getActiveRulesAt.js";
import { getChainConfig } from "../../methods/public/getChainConfig.js";
import { getRegistrationJustification } from "../../methods/public/getRegistrationJustification.js";
import { maxPriorityFeePerGas } from "../../methods/public/maxPriorityFeePerGas.js";
import { BaseFeeReturnType } from "../../methods/public/types/baseFee.js";
import {
Expand All @@ -14,6 +15,10 @@ import {
GetActiveRulesAtReturnType,
} from "../../methods/public/types/getActiveRulesAt.js";
import { GetChainConfigReturnType } from "../../methods/public/types/getChainConfig.js";
import {
GetRegistrationJustificationParams,
GetRegistrationJustificationReturnType,
} from "../../methods/public/types/getRegistrationJustification.js";
import { MaxPriorityFeePerGasReturnType } from "../../methods/public/types/maxPriorityFeePerGas.js";
export type AvalanchePublicActions = {
/**
Expand Down Expand Up @@ -134,6 +139,66 @@ export type AvalanchePublicActions = {
getActiveRulesAt: (
args: GetActiveRulesAtParameters
) => Promise<GetActiveRulesAtReturnType>;

/**
* Retrieves the registration justification for the given validation ID Hex and subnet ID.
*
* If the validation ID corresponds to a bootstrap validator, the justification bytes
* produced by `ConvertSubnetToL1Tx` are returned.
*
* Otherwise, the function searches the Warp logs on the chain where the validator
* manager is deployed to locate the RegisterL1ValidatorMessage for the specified validation ID.
*
* @param client - The AvalancheCoreClient instance.
* @param params - The GetRegistrationJustificationParams instance.
* @returns The GetRegistrationJustificationReturnType instance.
*
* @example
* ```ts
* import { createAvalancheClient } from "@avalanche-sdk/client";
* import { getRegistrationJustification } from "@avalanche-sdk/client/methods/public";
* import { defineChain } from "@avalanche-sdk/client/chains";
* import { utils } from "@avalanche-sdk/client/utils";
*
* const chainConfig = defineChain({
* id: 28098,
* name: "Rough Complexity Chain",
* rpcUrls: {
* default: {
* http: [
* "https://base-url-to-your-rpc/ext/bc/28zXo5erueBemgxPjLom6Vhsm6oVyftLtfQSt61fd62SghoXrz/rpc",
* ],
* },
* },
* });
*
* const publicClient = createAvalancheClient({
* chain: chainConfig,
* transport: {
* type: "http",
* },
* });
*
* const validationIDHex = utils.bufferToHex(
* utils.base58check.decode(
* "TEwxg8JzAUsqFibtYkaiiYH9G1h5ZfX56zYURXpyaPRCSppC4"
* )
* );
*
* const justification = await publicClient.getRegistrationJustification({
* validationIDHex,
* subnetIDStr: "2DN6PTi2uXNCzzNz1p2ckGcW2eqTfpt2kv2a1h7EV36hYV3XRJ",
* maxBootstrapValidators: 200,
* chunkSize: 200,
* maxChunks: 100,
* });
*
* console.log("justification", JSON.stringify(justification, null, 2));
* ```
*/
getRegistrationJustification: (
args: GetRegistrationJustificationParams
) => Promise<GetRegistrationJustificationReturnType>;
};

export function avalanchePublicActions<
Expand All @@ -145,5 +210,7 @@ export function avalanchePublicActions<
maxPriorityFeePerGas: () => maxPriorityFeePerGas(client),
feeConfig: (args) => feeConfig(client, args),
getActiveRulesAt: (args) => getActiveRulesAt(client, args),
getRegistrationJustification: (args) =>
getRegistrationJustification(client, args),
};
}
Loading