@eigen-secret/sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

sdk

Create proofs of user account operation (i.e., create, migrate, or update) and transaction operation (i.e., deposit, send, or withdraw).

Usage

const sdk = require('sdk');

1. Initialize

let secretSDK = new sdk(
    user_alias,
    user_secretAccount, // contain user's accountKey and signingKey
    addr, // local test: "http://127.0.0.1:3000"
    circuitPath,
    eddsa,
    user_EthAddress,
    contractAddress_spongePoseidon,
    contractAddress_tokenRegistry,
    contractAddress_poseidon2,
    contractAddress_poseidon3,
    contractAddress_poseidon6,
    contractAddress_rollup,
    contractAddress_smtVerifier,
);

// user signature information for verifying the user's ETH address
const ctx = {
    alias: user_alias,
    ethAddress: user_EthAddress.address,
    rawMessage: rawMessage,
    timestamp: timestamp,
    signature: signature 
    // signMessage("\x19Ethereum Signed Message:\n" + lengthOf(m) + m)
    // m = rawMessage + user_EthAddress.address + alias + timestamp
};

await secretSDK.initialize(
    defaultContractABI // the contracts ABI directory
);

2. Generate create-account proof

let proofAndPublicSignals = await secretSDK.createAccount(
    ctx,
    user_secretAccount.newSigningKey1,
    user_secretAccount.newSigningKey2
);

3. Generate migrate-account proof

let proofAndPublicSignals = await secretSDK.createAccount(
    ctx,
    newAccountKey // the accountKey that which user renews
);

4. Generate update-account proof

let proofAndPublicSignals = await secretSDK.createAccount(
    ctx,
    user_secretAccount.newSigningKey1,
    user_secretAccount.newSigningKey2
);

5. Generate deposit proof

let proofAndPublicSignals = await secretSDK.deposit(
    ctx,
    receiver,
    BigInt(value), // the amount to be deposited
    Number(assetId), // the token to be deposited
    nonce // the nonce of current transaction, usually obtained from Wallet like Metamask
);

6. Generate send proof

let proofAndPublicSignals = await secretSDK.send(
    ctx,
    receiver,
    BigInt(value), // the amount to be sent 
    Number(assetId) // the token to be sent
);

7. Generate withdraw proof

 let proofAndPublicSignals = await secretSDK.withdraw(
    ctx,
    receiver,
    BigInt(value), // the amount to be withdrawn
    Number(assetId) // the token to be withdrawn
);

Readme

Keywords

none

Package Sidebar

Install

npm i @eigen-secret/sdk

Weekly Downloads

2

Version

1.0.7

License

UNLICENSED

Unpacked Size

73.4 kB

Total Files

5

Last publish

Collaborators

  • ieigen
  • sfyr