Files
ImmortalClanVue/src/helper/blockchain.js
T
2023-08-14 18:37:11 +02:00

73 lines
1.6 KiB
JavaScript

import { useTokenStore } from "@/stores/tokens";
export function createPermitObject(fromAddress, spender, nonce, deadline, value) {
const tokenStore = useTokenStore();
const message = {
owner: fromAddress,
spender: spender,
nonce: nonce,
deadline: deadline,
value: value,
};
const domainType = [
{ name: "name", type: "string" },
{ name: "version", type: "string" },
{ name: "chainId", type: "uint256" },
{ name: "verifyingContract", type: "address" },
];
const primaryType = "Permit";
const types = {
EIP712Domain: domainType,
Permit: [
{
name: "owner",
type: "address",
},
{
name: "spender",
type: "address",
},
{
name: "value",
type: "uint256",
},
{
name: "nonce",
type: "uint256",
},
{
name: "deadline",
type: "uint256",
},
],
}
const domain = {
name: "Bloodline",
version: "1",
chainId: 5,
verifyingContract: tokenStore.memeToken.contractAddress,
};
return {
types,
message,
domain,
primaryType,
};
}
export function getSignatureRSV(sig) {
// splits the signature to r, s, and v values.
// const pureSig = sig.replace("0x", "");
const r = sig.slice(0, 66);
const s = "0x" + sig.slice(66, 130);
const v = Number("0x" + sig.slice(130, 132));
return { v, r, s };
};