Skip to content

portis-project/starkware-controller

 
 

Repository files navigation

starkware-controller npm version

Starkware JSON-RPC Controller Library

Example

import { Wallet } from 'ethers';
import StarkwareController from 'starkware-controller';

const rpcUrl = 'https://ropsten.mycustomnode.com';

const mnemonic = `puzzle number lab sense puzzle escape glove faith strike poem acoustic picture grit struggle know tuna soul indoor thumb dune fit job timber motor`;

const wallet = Wallet.fromMnemonic(mnemonic).connect(rpcUrl);

const store = {
  set: async (key: string, data: any) => {
    window.localStorage.setItem(key, JSON.stringify(data));
  },
  get: async (key: string) => {
    return JSON.parse(window.localStorage.getItem(key));
  },
  remove: async (key: string) => {
    window.localStorage.removeItem(key);
  },
};

//  Create StarkwareController
const controller = new StarkwareController(wallet, store);

// Initiate
await controller.init();

// Example payload
const payload = {
  id: 1,
  jsonrpc: '2.0',
  method: 'stark_account',
  params: {
    layer: 'starkex',
    application: 'starkexdvf',
    index: '0',
  },
};

// Resolve payload
const result = await controller.resolve(payload);
// {
//     "id": 1,
//     "jsonrpc": "2.0",
//     "result": {
//         "starkPublicKey":"0x59a543d42bcc9475917247fa7f136298bb385a6388c3df7309955fcb39b8dd4",
//     }
// }

API

interface StarkwareController {
  setProvider(provider: string | providers.JsonRpcProvider): void;
  getStarkPublicKey(path?: string): Promise<string>;
  getActiveKeyPair();
  account(
    layer: string,
    application: string,
    index: string
  ): Promise<MethodResults.StarkAccountResult>;
  register(
    contractAddress: string,
    starkPublicKey: string,
    operatorSignature: string
  ): Promise<MethodResults.StarkRegisterResult>;
  deposit(
    contractAddress: string,
    starkPublicKey: string,
    quantizedAmount: string,
    token: starkwareCrypto.Token,
    vaultId: string
  ): Promise<MethodResults.StarkDepositResult>;
  depositCancel(
    contractAddress: string,
    starkPublicKey: string,
    token: starkwareCrypto.Token,
    vaultId: string
  ): Promise<MethodResults.StarkDepositCancelResult>;
  depositReclaim(
    contractAddress: string,
    starkPublicKey: string,
    token: starkwareCrypto.Token,
    vaultId: string
  ): Promise<MethodResults.StarkDepositReclaimResult>;
  transfer(
    from: starkwareCrypto.TransferParams,
    to: starkwareCrypto.TransferParams,
    token: starkwareCrypto.Token,
    quantizedAmount: string,
    nonce: string,
    expirationTimestamp: string
  ): Promise<MethodResults.StarkTransferResult>;
  createOrder(
    starkPublicKey: string,
    sell: starkwareCrypto.OrderParams,
    buy: starkwareCrypto.OrderParams,
    nonce: string,
    expirationTimestamp: string
  ): Promise<MethodResults.StarkCreateOrderResult>;
  withdrawal(
    contractAddress: string,
    starkPublicKey: string,
    token: starkwareCrypto.Token
  ): Promise<MethodResults.StarkWithdrawalResult>;
  fullWithdrawal(
    contractAddress: string,
    starkPublicKey: string,
    vaultId: string
  ): Promise<MethodResults.StarkFullWithdrawalResult>;
  freeze(
    contractAddress: string,
    starkPublicKey: string,
    vaultId: string
  ): Promise<MethodResults.StarkFreezeResult>;
  verifyEscape(
    contractAddress: string,
    starkPublicKey: string,
    proof: string[]
  ): Promise<MethodResults.StarkVerifyEscapeResult>;
  escape(
    contractAddress: string,
    starkPublicKey: string,
    vaultId: string,
    token: starkwareCrypto.Token,
    quantizedAmount: string
  ): Promise<MethodResults.StarkEscapeResult>;
  resolve(payload: any);
}

namespace MethodResults {
  export type StarkAccountResult = { starkPublicKey: string };
  export type StarkRegisterResult = { txhash: string };
  export type StarkDepositResult = { txhash: string };
  export type StarkDepositCancelResult = { txhash: string };
  export type StarkDepositReclaimResult = { txhash: string };
  export type StarkTransferResult = { starkSignature: string };
  export type StarkCreateOrderResult = { starkSignature: string };
  export type StarkWithdrawalResult = { txhash: string };
  export type StarkFullWithdrawalResult = { txhash: string };
  export type StarkFreezeResult = { txhash: string };
  export type StarkVerifyEscapeResult = { txhash: string };
  export type StarkEscapeResult = { txhash: string };
}

About

Starkware JSON-RPC Controller Library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 98.1%
  • JavaScript 1.9%