0.1.30 • Published 11 months ago

@xudean/pado-ao-sdk v0.1.30

Weekly downloads
-
License
-
Repository
github
Last release
11 months ago

pado-ao-sdk

Overview

The pado-ao-sdk helps developers use PADO Network, which provides trustless and confidential computing capabilities. You can learn more about PADO Network.

Quick Start

  • Demos

Usage

Installation

Install package by npm

npm install --save @padolabs/pado-ao-sdk

import wasm

Introduce lhe.js into the HTML file as follows:

<!--    When the JS is introduced, the WASM will automatically load. -->
<script type="text/javascript" src="https://pado-online.s3.ap-northeast-1.amazonaws.com/resources/v2/lhe.js"></script>

The WASM version and SDK version have a strict correspondence. The specific relationship is as follows:

Wasm VersionSDK VersionWasm Link
v2>=0.2.0https://pado-online.s3.ap-northeast-1.amazonaws.com/resources/v2/lhe.js
V10.0.1<= version<0.2.0https://pado-online.s3.ap-northeast-1.amazonaws.com/resources/v1/lhe.js

If you meet the following error in your browser's console:

_stream_writable.js:57 Uncaught ReferenceError: process is not defined
    at node_modules/readable-stream/lib/_stream_writable.js (_stream_writable.js:57:18)
    at __require2 (chunk-BYPFWIQ6.js?v=4d6312bd:19:50)

You can refer to project using vite. link

Getting Started

Utils

Generate Key

Generate public-private key pairs for submitting tasks and retrieving task results.

generateKey(param_obj?: any): Promise<KeyInfo>;
  • Example
import {Utils} from "@padolabs/pado-ao-sdk";

//The generated key pair will be used for submitTask() and `getTaskResult()
const keyInfo = await new Utils().generateKey();

PadoNetworkContractClient

Import Client
import {PadoNetworkContractClient} from '@padolabs/pado-ao-sdk'
Instantiate Client

The constructor for the PadoNetworkContractClient.

  constructor(chainName: ChainName, wallet: any, storageType: StorageType = StorageType.ARSEEDING);

Parameters

  • chainName: The blockchain the client wants to connect to. Learn more about ChainName
  • wallet: The wallet that interacts with the blockchain.
  • storageType (optional): The storage option the client wants to use for data. The default is StorageType.ARSEEDING. Learn more about StorageType

Note:

By default, StorageType is ARWEAVE when chainName is ao, and ARSEEDING when chainName is holesky or ethereum.

chainNamestorageTypeWallet
aoARWEAVEwindow.arweaveWallet
holeskyARSEEDINGwindow.ethereum
ethereumARSEEDINGwindow.ethereum
  • Returns

  • Example

const chainName = 'holesky';
const storageType = StorageType.ARSEEDING;
//if chainName is holesky or ethereum, wallet should be window.ethereum;
//if chainName is ao, wallet should be window.arweaveWallet;
const wallet = window.ethereum;
const padoNetworkClient = new PadoNetworkContractClient(chainName, wallet, storageType);
Upload Data

Uploading data to the storage chain.

uploadData(data: Uint8Array, dataTag: CommonObject, priceInfo: PriceInfo, encryptionSchema?: EncryptionSchema): Promise<string>;
  • Parameters

    • data: The data to be uploaded, which should be of type Uint8Array.

    • dataTag: The data's metadata object. Note: Please use an object format, not a string.

    • priceInfo: The data price symbol. Leran more bout PriceInfo Different chainName values correspond to different symbols.

      chainNamesymbolminimum price(1 means)
      aowAR(the Wrapped AR in AO)0.000000000001 wAR
      holeskyETH1 wei
      ethereumETH1 wei
  • encryptionSchema(optional): Parameters used by the algorithm. The default is:

    {
      t: '2',
      n: '3'
    }
  • Returns

    • dataId: A unique identifier for the data.
  • Example

//padoNetworkClient is the object instantiated in the previous section 
const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
const dataTag = { 'filename': 'testFileName' };
const priceInfo = { price: '200000000', symbol: 'wAR' };

const dataId = await padoNetworkClient.uploadData(data, dataTag, priceInfo);
Submit Task

Submit a task to the PADO Network. You must pay both the data fee corresponding to the data provider and the computing fee for the workers.

submitTask(taskType: string, dataId: string): Promise<string>;

Note:

The public key passed when initialising the client is used to encrypt the task result when submitting the task.

  • Parameters

    • taskType: The type of the task; defaults to 0 now.

    • dataId: The dataId returned by the uploadData interface.

  • Returns

    • taskId: The ID of the task.
  • Example
const userDataId = 'returned by the uploadData';
const taskId = await padoNetworkClient.submitTask(0, userDataId)
Get Task Result

Get the result of the task.

getTaskResult(taskId: string, timeout?: number): Promise<Uint8Array>;

Note

The task result will be decrypted using the private key in the key pair passed when initialising the client, make sure that the submitTask and getTaskResult interfaces are the same PadoNetworkClient instance!

  • Parameters
    • taskId: taskId returned by submitTask interface
    • timeout(optional): The timeout in milliseconds for getting the result, if you wait longer than this time a timeout exception will be thrown. Default 10000(10 seconds).
  • Returns
    • Uint8Array: The result of the task in plain text.
  • Example
const taskId = 'returned by the getTaskResult';
const timeout = 20000;//milliseconds
//The format of data is Uint8Array, you should handle this data additionally, such as saving it to a file etc.
const data = await padoNetworkClient.getTaskResult(taskId,);

Type And Enum

KeyInfo

type KeyInfo = {
		//publick key
    pk: string;
    //private key
    sk: string;
};
ChainName

type ChainName = 'ao' | 'holesky' | 'ethereum';
StorageType

enum StorageType {
    ARWEAVE = "arweave",
    ARSEEDING = "arseeding"
}
PriceInfo

/**
 * Price of data
 * if symbol is 'wAR'(chainName is ao), a price of 1 means that the data price is 0.000000000001 wAR.
 * if symbol is 'ETH'(chainName is holesky or ethereum),a price of 1 means that the data price is 1wei
 * price: The price of data
 * symbol: The token symbol of price
 */
interface PriceInfo {
    price: string;
    symbol: string;
}

0.1.30

11 months ago

0.1.29

11 months ago

0.1.28

11 months ago

0.1.27

11 months ago

0.1.26

11 months ago

0.1.25

11 months ago

0.1.24

11 months ago

0.1.23

11 months ago

0.1.22

1 year ago

0.2.21

1 year ago

0.1.21

1 year ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.18

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.1

1 year ago

0.1.2

1 year ago

0.1.0

1 year ago

0.1.0-alpha.5

1 year ago

0.1.0-alpha.4

1 year ago

0.1.0-alpha.3

1 year ago

0.1.0-alpha.2

1 year ago

0.1.0-alpha.1

1 year ago

0.1.0-alpha.0

1 year ago