Package Exports
- @axiom-crypto/codec
- @axiom-crypto/codec/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@axiom-crypto/codec) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Axiom Query Codec
This Typescript package handles encoding and decoding of Axiom Queries.
Usage
For usage examples, please see the /tests folder
Encoding a v2 Query
const sourceChainId = 1;
const dataQueryHash = "0x4c8f18581c0167eb90a761b4a304e009b924f03b619a0c0e8ea3adfce20aee64";
const k = 8;
const omega = 256;
const vkey = "0xdf54012db55e6801dd86d4d19a758eb963f6873a2565d123eb86411d8ea224e07f3f57b5eb5ecc068677b57f1c28b395f1e6011ce55bbec0369d33b95d9dda00";
const resultLen = 100;
const computeProof = "0xe9b88dad55adda4d5c2e83dbd97db7860e46fb23b021218140de9251b092046672b277791612344114916ebfe9df1243d4d3f4871874d4d8ff514b6ced74b8869cc8dea8ce032fd4485110a55b16ce13d0b2f537288d0d1baa0bb7824cfb1777e79c992a5d2adfc799190c548fee47b9b94931883dbe0078b5fba4b9835cdd48286e7b30bbd8f7945bbe793be6b77ee8a8d15c4ae052c9ad68b43344356bd1cb34f4eb49028a46823a4cd2a2df447ccb80a891f6cfb116e23bbae9e86a6eef5f";
const callbackAddr = "0xB392448932F6ef430555631f765Df0dfaE34efF3";
const callbackFunctionSelector = "0xe3d670d7";
const encodedQuery = encodeQueryV2(
sourceChainId,
dataQueryHash,
k,
omega,
vkey,
resultLen,
computeProof,
callbackAddr,
callbackFunctionSelector
);Decoding a v2 Query
// `queryString` is an encoded v2 Query (automatic detection)
const queryData = decodeQuery(queryString) as QueryV2;Encoding a v1 Query
const query = [
{
blockNumber: 15537394,
address: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
slot: 0,
value: 0,
},
{
blockNumber: 15822595,
address: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
slot: 0,
value: 0,
},
{
blockNumber: 17000000,
address: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
},
]
let queryRows: string[] = [];
for (const queryRow of query) {
const length = Object.keys(queryRow).length;
const rowHash = encodeQueryRow(length, queryRow.blockNumber, queryRow.address, queryRow.slot ?? 0, queryRow.value ?? 0);
queryRows.push(rowHash);
}
const encodedQuery = encodeQueryV1(query.length, queryRows);Decoding a v1 Query
// `queryString` is an encoded v2 Query (automatic detection)
const queryData = decodeQuery(queryString) as QueryV1;