Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ A required object which includes all options for communication customization.

> The SDK is able to automatically differentiate Mainnet and Testnet from the url

- **chainId** – type string – optional – an Id or a PSR chain name to which the SDK being connected to. If not specified – it is automatically fetched by the JsonRpcApi from the endpoint provided.

- **chainId** type string – optional – an Id or a PSR chain name to which the SDK being connected to. If not specified – it is automatically fetched by the JsonRpc from the endpoint provided.
- **usePulseVM** - type boolean - optional - a flag to mark network as using PulseVM. Enables another implementation of JsonRpcApi
- **storage** – type LinkStorage – optional – if not specified, the new Storage is automatically created. In order to customize Storage, you should provide a custom LinkStorage interface with type specifications inside.
Expand Down
4 changes: 4 additions & 0 deletions examples/vue/env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_USE_PULSE_VM: boolean
}
1 change: 1 addition & 0 deletions examples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"dev:a-chain": "VITE_USE_PULSE_VM=true vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
Expand Down
32 changes: 24 additions & 8 deletions examples/vue/src/webSdk.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import ProtonWebSDK, { setUITheme, runUIDemo } from '@proton/web-sdk'
import type { ProtonWebLink, LinkSession, TransactResult, Link } from '@proton/web-sdk'
import { Serialize, JsonRpc } from '@proton/js'
import { Serialize, JsonRpc, JsonRpcPulseVM } from '@proton/js'
import type { RpcInterfaces } from '@proton/js'

export let link: ProtonWebLink | Link | undefined
export let session: LinkSession | undefined

const USE_PULSE_VM = !!import.meta.env.VITE_USE_PULSE_VM
const REQUEST_ACCOUNT = 'taskly'
const CHAIN_ID = '384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0'
const ENDPOINTS = ['https://proton.greymass.com']

const rpc = new JsonRpc(ENDPOINTS)
const CHAIN_ID = USE_PULSE_VM
? 'bef02258ee702d2d8df016ce2f2cbcf6bfa986dcd8c8641acd9068b8f9c4c7ef'
: '71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd'
const ENDPOINTS = USE_PULSE_VM
? [
'https://pulsevm-devnet-01.metalblockchain.org/ext/bc/2T6FphmDo8szR3UERGsDsXaQPb52xUn2djnAt7S6LECbHDhc5L/rpc',
]
: [
'https://rpc.api.testnet.metalx.com',
'https://proton-testnet1.eoscafeblock.com',
'https://test.proton.eosusa.io',
]

const SCHEME = USE_PULSE_VM ? 'achain' : undefined
const TOKEN_CONTRACT = USE_PULSE_VM ? 'pulse.token' : 'eosio.token'
const rpcClass = USE_PULSE_VM ? JsonRpcPulseVM : JsonRpc
const rpc = new rpcClass(ENDPOINTS)

export const createLink = async ({
restoreSession = false,
Expand All @@ -22,6 +36,8 @@ export const createLink = async ({
endpoints: ENDPOINTS,
chainId: CHAIN_ID,
restoreSession,
scheme: SCHEME,
usePulseVM: USE_PULSE_VM,
},
transportOptions: {
requestAccount: REQUEST_ACCOUNT,
Expand Down Expand Up @@ -95,7 +111,7 @@ export const transfer = async ({ to, amount }: { to: string; amount: string }) =
*/

// Token contract
account: 'eosio.token',
account: TOKEN_CONTRACT,

// Action name
name: 'transfer',
Expand Down Expand Up @@ -133,8 +149,8 @@ export async function getProtonAvatar(
): Promise<RpcInterfaces.UserInfo | undefined> {
try {
const result = await rpc.get_table_rows({
code: 'eosio.proton',
scope: 'eosio.proton',
code: TOKEN_CONTRACT,
scope: TOKEN_CONTRACT,
table: 'usersinfo',
key_type: 'i64',
lower_bound: account,
Expand Down
18 changes: 14 additions & 4 deletions packages/proton-link/src/link-options.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type {APIClient} from '@greymass/eosio'
import type {ChainIdType, SigningRequestEncodingOptions} from '@proton/signing-request'
import type {LinkStorage} from './link-storage'
import type {LinkTransport} from './link-transport'
import type {LinkCallbackService} from './link-callback'
import {JsonRpc} from '@proton/js'
import type {JsonRpcApi} from '@proton/js'

/**
* Type describing a EOSIO chain.
Expand All @@ -16,7 +15,12 @@ export interface LinkChainConfig {
/**
* URL to EOSIO node to communicate with (or a @greymass/eosio APIClient instance).
*/
nodeUrl: string | JsonRpc
nodeUrl: string | JsonRpcApi

/**
* Flag to mark network as using PulseVM. Enables another implementation of JsonRpcApi
*/
usePulseVM?: boolean
}

/**
Expand Down Expand Up @@ -53,7 +57,13 @@ export interface LinkOptions {
* URL to EOSIO node to communicate with or a `@greymass/eosio` APIClient instance.
* @deprecated Use [[chains]] instead.
*/
client?: string | JsonRpc
client?: string | JsonRpcApi

/**
* Flag to mark network as using PulseVM. Enables another implementation of JsonRpcApi
*/
usePulseVM?: boolean

/**
* URL to callback forwarder service or an object implementing [[LinkCallbackService]].
* See [buoy-nodejs](https://github.com/greymass/buoy-nodejs) and (buoy-golang)[https://github.com/greymass/buoy-golang]
Expand Down
17 changes: 12 additions & 5 deletions packages/proton-link/src/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {LinkTransport} from './link-transport'
import {LinkCreate} from './link-types'
import {BuoyCallbackService, LinkCallback, LinkCallbackService} from './link-callback'
import {sessionMetadata} from './utils'
import {JsonRpc, RpcInterfaces} from '@proton/js'
import {JsonRpc, type JsonRpcApi, JsonRpcPulseVM, type RpcInterfaces} from '@proton/js'

/**
* Payload accepted by the [[Link.transact]] method.
Expand Down Expand Up @@ -133,15 +133,20 @@ export class LinkChain implements AbiProvider {
/** EOSIO ChainID for which requests are valid. */
public chainId: ChainId
/** API client instance used to communicate with the chain. */
public client: JsonRpc
public client: JsonRpcApi

private abiCache = new Map<string, ABIDef>()
private pendingAbis = new Map<string, Promise<RpcInterfaces.GetAbiResult>>()

/** @internal */
constructor(chainId: ChainIdType, clientOrUrl: JsonRpc | string) {
constructor(
chainId: ChainIdType,
clientOrUrl: JsonRpcApi | string,
{usePulseVM}: {usePulseVM?: boolean} = {}
) {
this.chainId = ChainId.from(chainId)
this.client = typeof clientOrUrl === 'string' ? new JsonRpc(clientOrUrl) : clientOrUrl
const rpcClass = usePulseVM ? JsonRpcPulseVM : JsonRpc
this.client = typeof clientOrUrl === 'string' ? new rpcClass(clientOrUrl) : clientOrUrl
}

/**
Expand Down Expand Up @@ -218,7 +223,9 @@ export class Link {
}
let chains: LinkChainConfig[] = options.chains || []
if (options.chainId && options.client) {
chains = [{chainId: options.chainId, nodeUrl: options.client}]
chains = [
{chainId: options.chainId, nodeUrl: options.client, usePulseVM: options.usePulseVM},
]
}
if (chains.length === 0) {
throw new TypeError('options.chains is required')
Expand Down
25 changes: 18 additions & 7 deletions packages/proton-react-native-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './registerGlobals'
import ReactNativeTransport, {ReactNativeTransportOptions} from './transport'

import ProtonLink, {LinkOptions, LinkSession, LinkStorage, PermissionLevel} from '@proton/link'
import {JsonRpc} from '@proton/js'
import {JsonRpc, type JsonRpcApi, JsonRpcPulseVM} from '@proton/js'

import Storage from './storage'

Expand All @@ -11,7 +11,7 @@ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
interface ConnectWalletArgs {
linkOptions: PartialBy<LinkOptions, 'transport' | 'chains' | 'scheme'> & {
endpoints: string[]
rpc?: JsonRpc
rpc?: JsonRpcApi
storage?: LinkStorage
storagePrefix?: string
restoreSession?: boolean
Expand All @@ -21,7 +21,9 @@ interface ConnectWalletArgs {

const ConnectWallet = async ({linkOptions, transportOptions}: ConnectWalletArgs) => {
// Add RPC
linkOptions.client = linkOptions.rpc || new JsonRpc(linkOptions.endpoints)
const rpcClass = linkOptions.usePulseVM ? JsonRpcPulseVM : JsonRpc

linkOptions.client = linkOptions.rpc || new rpcClass(linkOptions.endpoints)

// Add chain ID if not present
if (!linkOptions.chainId) {
Expand All @@ -46,10 +48,19 @@ const ConnectWallet = async ({linkOptions, transportOptions}: ConnectWalletArgs)

let session, loginResult

if (linkOptions.chainId === '71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd') {
linkOptions.scheme = 'proton-dev'
} else {
linkOptions.scheme = 'proton'
// Set scheme
if (!linkOptions.scheme) {
if (linkOptions.usePulseVM) {
linkOptions.scheme = 'achain'
} else {
if (
linkOptions.chainId === '71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd'
) {
linkOptions.scheme = 'proton-dev'
} else {
linkOptions.scheme = 'proton'
}
}
}

const transport = new ReactNativeTransport({
Expand Down
2 changes: 1 addition & 1 deletion packages/proton-signing-request/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@proton/signing-request",
"version": "5.0.0-rc-1",
"version": "5.0.0-rc-2",
"description": "Proton Signing Request (ESR / EEP-7) encoder and decoder",
"homepage": "https://github.com/XPRNetwork/proton-web-sdk",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/proton-signing-request/src/signing-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export interface SigningRequestEncodingOptions {
/** Optional signature provider, will be used to create a request signature if provided. */
signatureProvider?: SignatureProvider
/** Custom Scheme . */
scheme: 'esr' | 'proton' | 'proton-dev'
scheme: 'esr' | 'proton' | 'proton-dev' | 'achain'
}

export type AbiMap = Map<string, ABI>
Expand Down
4 changes: 3 additions & 1 deletion packages/proton-web-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ A required object which includes all options for communication customization.

> The SDK is able to automatically differentiate Mainnet and Testnet from the url

- **usePulseVM** - type boolean - optional - a flag to mark network as using PulseVM. Enables another implementation of JsonRpcApi

- **chainId** – type string – optional – an Id or a PSR chain name to which the SDK being connected to. If not specified – it is automatically fetched by the JsonRpc from the endpoint provided.

- **chainId** – type string – optional – an Id or a PSR chain name to which the SDK being connected to. If not specified – it is automatically fetched by the JsonRpcApi from the endpoint provided.
- **storage** – type LinkStorage – optional – if not specified, the new Storage is automatically created. In order to customize Storage, you should provide a custom LinkStorage interface with type specifications inside.
Expand Down
26 changes: 19 additions & 7 deletions packages/proton-web-sdk/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {LinkOptions, PermissionLevel} from '@proton/link'
import {ProtonWebLink} from './links/protonWeb'
import {Storage} from './storage'
import type {ConnectWalletArgs, ConnectWalletRet, LoginOptions, UIOptions} from './types'
import {JsonRpc} from '@proton/js'
import {JsonRpc, JsonRpcPulseVM} from '@proton/js'
import {WebRenderer} from '@proton/web-renderer'

let renderer: WebRenderer | undefined
Expand Down Expand Up @@ -33,7 +33,8 @@ export const ConnectWallet = async ({
uiOptions = {},
}: ConnectWalletArgs): Promise<ConnectWalletRet> => {
// Add RPC
const rpc = new JsonRpc(linkOptions.endpoints)
const rpcClass = linkOptions.usePulseVM ? JsonRpcPulseVM : JsonRpc
const rpc = new rpcClass(linkOptions.endpoints)
linkOptions.client = rpc

// Add Chain ID
Expand Down Expand Up @@ -113,11 +114,22 @@ const login = async (
}

// Set scheme
let scheme = 'proton'
if (walletType === 'anchor') {
scheme = 'esr'
} else if (chain === 'proton-test') {
scheme = 'proton-dev'
let scheme: string | undefined = undefined

if (loginOptions.linkOptions.scheme) {
scheme = loginOptions.linkOptions.scheme
} else if (loginOptions.linkOptions.usePulseVM) {
scheme = 'achain'
}

if (!scheme) {
if (walletType === 'anchor') {
scheme = 'esr'
} else if (chain === 'proton-test') {
scheme = 'proton-dev'
} else {
scheme = 'proton'
}
}

const options = {
Expand Down
7 changes: 4 additions & 3 deletions packages/proton-web-sdk/src/links/protonWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
TransactArgs,
TransactOptions,
} from '@proton/link'
import {JsonRpc} from '@proton/js'
import {JsonRpc, type JsonRpcApi, JsonRpcPulseVM} from '@proton/js'

const OPEN_SETTINGS = 'menubar=1,resizable=1,width=400,height=600'

Expand Down Expand Up @@ -41,7 +41,7 @@ export class ProtonWebLink {
deferredLogin: Deferred | undefined
scheme: string
storage: LinkStorage | null | undefined
client: JsonRpc | undefined
client: JsonRpcApi | undefined
testUrl: string | undefined
transport: LinkTransport
chainId: string
Expand All @@ -55,8 +55,9 @@ export class ProtonWebLink {
}

constructor(options: LinkOptions & {testUrl?: string}) {
const rpcClass = options.usePulseVM ? JsonRpcPulseVM : JsonRpc
this.scheme = options.scheme
this.client = typeof options.client === 'string' ? new JsonRpc(options.client) : options.client
this.client = typeof options.client === 'string' ? new rpcClass(options.client) : options.client
this.storage = options.storage
this.testUrl = options.testUrl
this.transport = options.transport
Expand Down
Loading