Skip to content

Commit

Permalink
Merge pull request #3 from AAStarCommunity/v0.01-rc0
Browse files Browse the repository at this point in the history
V0.01 rc0
  • Loading branch information
cherry-yl-sh authored Apr 15, 2024
2 parents 2ddb57a + aa507c5 commit d346419
Show file tree
Hide file tree
Showing 30 changed files with 14,297 additions and 103 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/deploy-alpha.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Publish Package to npmjs

on:
push:
branches-ignore: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm publish --access public --tag alpha
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
19 changes: 19 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Publish Package to npmjs

on:
push:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ bin-release/
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
# should NOT be excluded as they contain compiler settings and other important
# information for Eclipse / Flash Builder.
node_modules

.idea
.vscode
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Codegeex.Chat.LanguagePreference": "English"
}
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
# EthPaymaster_sdk_ts
EthPaymaster typescript Sdk

```tsx
let client = EthPaymasterClient.development(address)

const healthResponse = await client.health()

const authResponse = await client.auth("API-KEY")

const token = authResponse.token

const strategyResponse = await client.getSupportStrategyV1(Network.Ethereum, authResponse.token)

const entrypointResponse = await client.getSupportEntryPointV1(Network.Ethereum, authResponse.token)

const request: TryPayUserOpRequestV1 = {
force_strategy_id: "1",
user_operation: {
call_data: "0xb61d27f6000000000000000000000000c206b552ab127608c3f666156c8e03a8471c72df000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
call_gas_limit: "39837",
init_code: "0xe19e9755942bb0bd0cccce25b1742596b8a8250b3bf2c3e700000000000000000000000078d4f01f56b982a3b03c4e127a5d3afa8ebee6860000000000000000000000008b388a082f370d8ac2e2b3997e9151168bd09ff50000000000000000000000000000000000000000000000000000000000000000",
max_fee_per_gas: "44020",
max_priority_fee_per_gas: "1743509478",
nonce: "1",
pre_verification_gas: "44020",
sender: "0x4A2FD3215420376DA4eD32853C19E4755deeC4D1",
signature: "0x760868cd7d9539c6e31c2169c4cab6817beb8247516a90e4301e929011451658623455035b83d38e987ef2e57558695040a25219c39eaa0e31a0ead16a5c925c1c",
verification_gas_limit: "100000",
paymaster_and_data : "0x"
}

}
const tryPayResponse = await client.tryPayUserOperationV1(authResponse.token, request)
```
19 changes: 19 additions & 0 deletions __test__/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
interface Person {
firstName: string;
lastName: string;

}
class Student implements Person{
fullName: string;
constructor(public firstName: string, public middleInitial: string, public lastName: string) {


this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}

export function greeter(person: Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}

let user = { firstName: "Jane", lastName: "User" };
72 changes: 72 additions & 0 deletions __test__/paymaster.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// import { describe, test } from "@jest/globals";
// import { health } from "../dist/index.esm.js";

// const devAddres = "https://relay-ethpaymaster-pr-20.onrender.com/"
// describe("PAYMASTER Health", () => {
// test("Health", async () => {
// const response = await health()
// console.log("response :" + JSON.stringify(response))
// console.log(response);

// })
// })

// describe("PAYMASTER Auth", () => {
// test("Auth", async () => {
// let client = EthPaymasterClient.development(devAddres)
// const response = await client.auth("string")
// console.log("response :" + JSON.stringify(response))
// })
// })
// describe("PAYMASTER Try Pay Sponsor Operation", () => {
// test("Try Pay Sponsor Operation", async () => {
// let client = EthPaymasterClient.development(devAddres)
// const authResponse = await client.auth("string");
// const token = authResponse.token
// console.log("token : " + token)
// const request: TryPayUserOpRequestV1 = {
// force_strategy_id: "1",
// user_operation: {
// call_data: "0xb61d27f6000000000000000000000000c206b552ab127608c3f666156c8e03a8471c72df000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
// call_gas_limit: "39837",
// init_code: "0xe19e9755942bb0bd0cccce25b1742596b8a8250b3bf2c3e700000000000000000000000078d4f01f56b982a3b03c4e127a5d3afa8ebee6860000000000000000000000008b388a082f370d8ac2e2b3997e9151168bd09ff50000000000000000000000000000000000000000000000000000000000000000",
// max_fee_per_gas: "44020",
// max_priority_fee_per_gas: "1743509478",
// nonce: "1",
// pre_verification_gas: "44020",
// sender: "0x4A2FD3215420376DA4eD32853C19E4755deeC4D1",
// signature: "0x760868cd7d9539c6e31c2169c4cab6817beb8247516a90e4301e929011451658623455035b83d38e987ef2e57558695040a25219c39eaa0e31a0ead16a5c925c1c",
// verification_gas_limit: "100000",
// paymaster_and_data: "0x"
// }

// }
// const response = await client.tryPayUserOperationV1(authResponse.token, request)
// console.log("response :" + JSON.stringify(response))
// })
// })

// describe("PAYMASTER Get Support Entry Point", () => {
// test("Get Support Entry Point", async () => {
// let client = EthPaymasterClient.development(devAddres)
// const authResponse = await client.auth("string");
// const token = authResponse.token
// console.log("token : " + token)
// const response = await client.getSupportEntryPointV1(Network.Ethereum, authResponse.token)
// console.log("response :" + JSON.stringify(response))
// })
// })
// describe("PAYMASTER Get Support Strategy", () => {
// test("Get Support Strategy", async () => {
// let client = EthPaymasterClient.development(devAddres)
// const authResponse = await client.auth("string");
// const token = authResponse.token
// console.log("token : " + token)
// const response = await client.getSupportStrategyV1(Network.Ethereum, authResponse.token)
// console.log("response :" + JSON.stringify(response))
// })

// })



16 changes: 16 additions & 0 deletions __test__/util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// import {describe, test} from "@jest/globals";
// import {Path} from "../src/common/path";
// import {utils} from "ethers";
// import {generateUrl} from "../src/common/PaymasterUtil";
// import {ENV} from "../src/common/type";
// import {DefaultProdHost} from "../src/ethPaymasterClient";

// describe("UTIL", () => {
// test("generateUrl", () => {
// const health = Path.Health
// let str = generateUrl(DefaultProdHost, Path.Health)
// console.log(str)
// })

// })

6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
};
3 changes: 0 additions & 3 deletions common/error.ts

This file was deleted.

16 changes: 0 additions & 16 deletions common/userOperation.ts

This file was deleted.

3 changes: 0 additions & 3 deletions common/util.ts

This file was deleted.

6 changes: 6 additions & 0 deletions dist/__test__/hello.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface Person {
firstName: string;
lastName: string;
}
export declare function greeter(person: Person): string;
export {};
Empty file.
Empty file added dist/__test__/util.test.d.ts
Empty file.
1 change: 1 addition & 0 deletions dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions dist/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HealthRes, AuthRes, EntryPointRes, StrategyRes, UserOpReq, TryPayUserOpRes } from './types/response';
/**
* Change the base url to the production or development url
*
* @param isProdUrl is production url
*/
export declare function init(isProdUrl?: boolean): void;
/**
*
* @returns server is health or not
*/
export declare const health: () => Promise<HealthRes | any>;
/**
*
* @param apiKey
* @returns
*/
export declare const auth: (apiKey: string) => Promise<AuthRes | any>;
export declare const getSupportEntryPointV1: (network?: string) => Promise<EntryPointRes | any>;
export declare const getSupportStrategyV1: (network?: string) => Promise<StrategyRes | any>;
export declare const tryPayUserOperationV1: (data: UserOpReq) => Promise<TryPayUserOpRes | any>;
99 changes: 99 additions & 0 deletions dist/src/types/response.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
interface BaseRes {
code: number;
message: string;
cost: string;
}
export interface HealthRes extends BaseRes {
data: {
environment: string;
hello: string;
time: string;
version: string;
};
}
export interface AuthRes {
code: number;
expire: string;
token: string;
}
export interface EntryPoint {
address: string;
desc: string;
network: string;
strategy_id: string;
}
export interface EntryPointRes extends BaseRes {
data: EntryPoint[];
}
interface ExecuteRestriction {
ban_sender_address: string;
effective_start_time: number;
effective_end_time: number;
global_max_usd: number;
global_max_op_count: number;
}
interface Strategy {
description: string;
enable_4844: boolean;
enable_7560: boolean;
enable_currency: boolean;
enable_eoa: boolean;
enable_erc20: boolean;
entrypoint_address: string;
entrypoint_tag: string;
execute_restriction: ExecuteRestriction[];
id: string;
network: string;
pay_type: string;
paymaster_address: string;
token: string;
}
export interface StrategyRes extends BaseRes {
data: Strategy[];
}
export interface TryPayUserOpRes extends BaseRes {
data: {
strategy_id: string;
entrypoint_address: string;
paymaster_address: string;
paymaster_signature: string;
paymaster_and_data: string;
pay_receipt: {
transaction_hash: string;
sponsor: string;
};
gas_info: {
gas_info: {
max_base_price_wei: number;
max_base_price_gwei: number;
max_base_price_ether: string;
max_priority_price_wei: number;
max_priority_price_gwei: number;
max_priority_price_ether: string;
};
token_cost: string;
network: string;
token: string;
usd_cost: number;
blob_enable: boolean;
max_fee: number;
};
};
}
export interface UserOpReq {
forceStrategyId: string;
userOperation: {
callData: string;
callGasLimit: string;
initCode: string;
maxFeePerGas: string;
maxPriorityFeePerGas: string;
nonce: string;
preVerificationGas: string;
sender: string;
signature: string;
verificationGasLimit: string;
paymasterAndData: string;
};
}
export {};
4 changes: 4 additions & 0 deletions dist/src/utils/path.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare const Path: {
[key: string]: string;
};
export default Path;
Loading

0 comments on commit d346419

Please sign in to comment.