diff --git a/.github/workflows/npm-publish.yaml b/.github/workflows/npm-publish.yaml
index 538a670..6a6a0e8 100644
--- a/.github/workflows/npm-publish.yaml
+++ b/.github/workflows/npm-publish.yaml
@@ -27,6 +27,7 @@ jobs:
- name: Check if version changed
run: |
npm install -g pnpm
+ pnpm install
for dir in packages/*/ packages/networks/*/; do
if [ -d "$dir" ] && [ "$(basename "$dir")" != "boilerplate" ]; then
diff --git a/README.md b/README.md
index e69de29..d746267 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1,7 @@
+# MultipleChain standard for JavaScript
+
+## Introduction
+
+MultipleChain aims for easy access by simplifying the complex structure of many blockchains. For example, each blockchain network has a different structure for transfer initiation or transaction data. You may need to learn new things from scratch for each blockchain network. This is necessary if you want to go into detail. But if you just want to get to the basics. MultipleChain will make your work much easier. In many different programming languages.
+
+#### 📚 [Documentation](https://multiplechain.gitbook.io/multiplechain-docs)
\ No newline at end of file
diff --git a/index.example.html b/index.example.html
deleted file mode 100644
index 4273020..0000000
--- a/index.example.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
- MultipleChain JS
-
-
-
-
-
diff --git a/packages/networks/bitcoin/README.md b/packages/networks/bitcoin/README.md
index e69de29..d746267 100644
--- a/packages/networks/bitcoin/README.md
+++ b/packages/networks/bitcoin/README.md
@@ -0,0 +1,7 @@
+# MultipleChain standard for JavaScript
+
+## Introduction
+
+MultipleChain aims for easy access by simplifying the complex structure of many blockchains. For example, each blockchain network has a different structure for transfer initiation or transaction data. You may need to learn new things from scratch for each blockchain network. This is necessary if you want to go into detail. But if you just want to get to the basics. MultipleChain will make your work much easier. In many different programming languages.
+
+#### 📚 [Documentation](https://multiplechain.gitbook.io/multiplechain-docs)
\ No newline at end of file
diff --git a/packages/networks/bitcoin/index.html b/packages/networks/bitcoin/index.example.html
similarity index 99%
rename from packages/networks/bitcoin/index.html
rename to packages/networks/bitcoin/index.example.html
index 2324a82..84be06a 100644
--- a/packages/networks/bitcoin/index.html
+++ b/packages/networks/bitcoin/index.example.html
@@ -224,7 +224,7 @@
}
const wallet = new Bitcoin.browser.Wallet(adapter)
- const adapterProvider = await wallet.connect(provider, {
+ const adapterProvider = await wallet.connect({
projectId: '113d9f5689edd84ff230c2a6d679c80c'
})
diff --git a/packages/networks/bitcoin/package.json b/packages/networks/bitcoin/package.json
index 7040f81..0dfe736 100644
--- a/packages/networks/bitcoin/package.json
+++ b/packages/networks/bitcoin/package.json
@@ -27,6 +27,16 @@
"types": "./dist/browser/index.d.ts"
}
},
+ "typesVersions": {
+ "*": {
+ "node": [
+ "./dist/index.d.ts"
+ ],
+ "browser": [
+ "./dist/browser/index.d.ts"
+ ]
+ }
+ },
"files": [
"dist",
"README.md",
@@ -62,8 +72,8 @@
"url": "https://github.com/MultipleChain/js/issues"
},
"dependencies": {
- "@multiplechain/types": "^0.1.56",
- "@multiplechain/utils": "^0.1.20",
+ "@multiplechain/types": "^0.1.63",
+ "@multiplechain/utils": "^0.1.21",
"axios": "^1.6.8",
"bitcore-lib": "^10.0.28",
"sats-connect": "^2.3.1",
diff --git a/packages/networks/bitcoin/pnpm-lock.yaml b/packages/networks/bitcoin/pnpm-lock.yaml
index 3cc25a4..86ea398 100644
--- a/packages/networks/bitcoin/pnpm-lock.yaml
+++ b/packages/networks/bitcoin/pnpm-lock.yaml
@@ -6,11 +6,11 @@ settings:
dependencies:
'@multiplechain/types':
- specifier: ^0.1.56
- version: 0.1.56
+ specifier: ^0.1.63
+ version: 0.1.63
'@multiplechain/utils':
- specifier: ^0.1.20
- version: 0.1.20
+ specifier: ^0.1.21
+ version: 0.1.21
axios:
specifier: ^1.6.8
version: 1.6.8
@@ -31,12 +31,12 @@ devDependencies:
packages:
- /@multiplechain/types@0.1.56:
- resolution: {integrity: sha512-tnkgDwW0AWxEfhE/392LR6ZPE7Pxz5/Ei1XYsQISGkOfYYZrsvJXr69fXTjDOHCq7RCuQqytKmhnKs5K4xHd7w==}
+ /@multiplechain/types@0.1.63:
+ resolution: {integrity: sha512-4C201vUsN6F1S/M7vT+GZS0wTdKGZXHqn4YmC6ouC8n0uxMCEFdI2sSCadyHKFKG5OBPo16X1oFCX9MVwPqMoA==}
dev: false
- /@multiplechain/utils@0.1.20:
- resolution: {integrity: sha512-4eEs4YR/V4F2Qnkl5KTZvPpewRQiX7C193d0tjpQuIfyumTEBJtdHYm1CW9CoJ6EjQUaB0oqSRKXomhzfK1qkw==}
+ /@multiplechain/utils@0.1.21:
+ resolution: {integrity: sha512-4mRlnhvXcS+7Hb1By5s2eoCH02kqOSQzV8qj0DHqZK20FtxtduaoGCtcClrFgEjN/HAXnHgdDc1pxTpveIkvRQ==}
dependencies:
'@types/ws': 8.5.10
bignumber.js: 9.1.2
diff --git a/packages/networks/bitcoin/src/assets/Coin.ts b/packages/networks/bitcoin/src/assets/Coin.ts
index a50d1ea..aa981de 100644
--- a/packages/networks/bitcoin/src/assets/Coin.ts
+++ b/packages/networks/bitcoin/src/assets/Coin.ts
@@ -2,10 +2,15 @@ import axios from 'axios'
import { Provider } from '../services/Provider.ts'
import { fromSatoshi, toSatoshi } from '../utils.ts'
import { Transaction, Script, Address } from 'bitcore-lib'
-import { ErrorTypeEnum, type CoinInterface } from '@multiplechain/types'
-import { CoinTransactionSigner } from '../services/TransactionSigner.ts'
+import { TransactionSigner } from '../services/TransactionSigner.ts'
+import {
+ ErrorTypeEnum,
+ type CoinInterface,
+ type TransferAmount,
+ type WalletAddress
+} from '@multiplechain/types'
-export class Coin implements CoinInterface {
+export class Coin implements CoinInterface {
/**
* Blockchain network provider
*/
@@ -40,10 +45,10 @@ export class Coin implements CoinInterface {
}
/**
- * @param {string} owner Wallet address
+ * @param {WalletAddress} owner Wallet address
* @returns {Promise} Wallet balance as currency of COIN
*/
- async getBalance(owner: string): Promise {
+ async getBalance(owner: WalletAddress): Promise {
const addressStatsApi = this.provider.createEndpoint('address/' + owner)
const addressStats = await axios.get(addressStatsApi).then((res) => res.data)
const balanceSat =
@@ -52,16 +57,16 @@ export class Coin implements CoinInterface {
}
/**
- * @param {string} sender Sender wallet address
- * @param {string} receiver Receiver wallet address
- * @param {number} amount Amount of assets that will be transferred
+ * @param {WalletAddress} sender Sender wallet address
+ * @param {WalletAddress} receiver Receiver wallet address
+ * @param {TransferAmount} amount Amount of assets that will be transferred
* @returns {Promise} Transaction signer
*/
async transfer(
- sender: string,
- receiver: string,
- amount: number
- ): Promise {
+ sender: WalletAddress,
+ receiver: WalletAddress,
+ amount: TransferAmount
+ ): Promise {
if (amount < 0) {
throw new Error(ErrorTypeEnum.INVALID_AMOUNT)
}
@@ -99,7 +104,7 @@ export class Coin implements CoinInterface {
transaction.change(sender)
transaction.to(receiver, satoshiToSend)
- return new CoinTransactionSigner({
+ return new TransactionSigner({
sender,
receiver,
amount: satoshiToSend,
diff --git a/packages/networks/bitcoin/src/assets/Contract.ts b/packages/networks/bitcoin/src/assets/Contract.ts
deleted file mode 100644
index 14044c0..0000000
--- a/packages/networks/bitcoin/src/assets/Contract.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import { Provider } from '../services/Provider.ts'
-import type { ContractInterface } from '@multiplechain/types'
-
-export class Contract implements ContractInterface {
- /**
- * Contract address
- */
- address: string
-
- /**
- * Blockchain network provider
- */
- provider: Provider
-
- /**
- * @param {string} address Contract address
- * @param {Provider} provider Blockchain network provider
- */
- constructor(address: string, provider?: Provider) {
- this.address = address
- this.provider = provider ?? Provider.instance
- throw new Error('This class is not implemented for Bitcoin.')
- }
-
- /**
- * @returns {string} Contract address
- */
- getAddress(): string {
- return this.address
- }
-
- /**
- * @param {string} method Method name
- * @param {any[]} args Method parameters
- * @returns {Promise} Method result
- */
- async callMethod(method: string, ...args: any[]): Promise {
- return {}
- }
-
- /**
- * @param {string} method Method name
- * @param {any[]} args Sender wallet address
- * @returns {Promise} Encoded method data
- */
- async getMethodData(method: string, ...args: any[]): Promise {
- return {}
- }
-
- /**
- * @param {string} method Method name
- * @param {string} from Sender wallet address
- * @param {any[]} args Method parameters
- * @returns {Promise} Encoded method data
- */
- async createTransactionData(method: string, from: string, ...args: any[]): Promise {
- return ''
- }
-}
diff --git a/packages/networks/bitcoin/src/assets/NFT.ts b/packages/networks/bitcoin/src/assets/NFT.ts
deleted file mode 100644
index 0a89a51..0000000
--- a/packages/networks/bitcoin/src/assets/NFT.ts
+++ /dev/null
@@ -1,96 +0,0 @@
-import { Contract } from './Contract.ts'
-import type { NftInterface } from '@multiplechain/types'
-import { NftTransactionSigner } from '../services/TransactionSigner.ts'
-
-export class NFT extends Contract implements NftInterface {
- /**
- * @returns {Promise} NFT name
- */
- async getName(): Promise {
- return 'example'
- }
-
- /**
- * @returns {Promise} NFT symbol
- */
- async getSymbol(): Promise {
- return 'example'
- }
-
- /**
- * @param {string} owner Wallet address
- * @returns {Promise} Wallet balance as currency of NFT
- */
- async getBalance(owner: string): Promise {
- return 0
- }
-
- /**
- * @param {number | string} nftId NFT ID
- * @returns {Promise} Wallet address of the owner of the NFT
- */
- async getOwner(nftId: number | string): Promise {
- return 'example'
- }
-
- /**
- * @param {number | string} nftId NFT ID
- * @returns {Promise} URI of the NFT
- */
- async getTokenURI(nftId: number | string): Promise {
- return 'example'
- }
-
- /**
- * @param {number | string} nftId ID of the NFT that will be transferred
- * @returns {Promise} Wallet address of the approved spender
- */
- async getApproved(nftId: number | string): Promise {
- return 'example'
- }
-
- /**
- * @param {string} sender Sender address
- * @param {string} receiver Receiver address
- * @param {number | string} nftId NFT ID
- * @returns {Promise} Transaction signer
- */
- async transfer(
- sender: string,
- receiver: string,
- nftId: number | string
- ): Promise {
- return new NftTransactionSigner('example')
- }
-
- /**
- * @param {string} spender Spender address
- * @param {string} owner Owner address
- * @param {string} receiver Receiver address
- * @param {number | string} nftId NFT ID
- * @returns {Promise} Transaction signer
- */
- async transferFrom(
- spender: string,
- owner: string,
- receiver: string,
- nftId: number | string
- ): Promise {
- return new NftTransactionSigner('example')
- }
-
- /**
- * Gives permission to the spender to spend owner's tokens
- * @param {string} owner Address of owner of the tokens that will be used
- * @param {string} spender Address of the spender that will use the tokens of owner
- * @param {number | string} nftId ID of the NFT that will be transferred
- * @returns {Promise} Transaction signer
- */
- async approve(
- owner: string,
- spender: string,
- nftId: number | string
- ): Promise {
- return new NftTransactionSigner('example')
- }
-}
diff --git a/packages/networks/bitcoin/src/assets/Token.ts b/packages/networks/bitcoin/src/assets/Token.ts
deleted file mode 100644
index a090488..0000000
--- a/packages/networks/bitcoin/src/assets/Token.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-import { Contract } from './Contract.ts'
-import type { TokenInterface } from '@multiplechain/types'
-import { TokenTransactionSigner } from '../services/TransactionSigner.ts'
-
-export class Token extends Contract implements TokenInterface {
- /**
- * @returns {Promise} Token name
- */
- async getName(): Promise {
- return 'example'
- }
-
- /**
- * @returns {Promise} Token symbol
- */
- async getSymbol(): Promise {
- return 'example'
- }
-
- /**
- * @returns {Promise} Decimal value of the token
- */
- async getDecimals(): Promise {
- return 18
- }
-
- /**
- * @param {string} owner Wallet address
- * @returns {Promise} Wallet balance as currency of TOKEN
- */
- async getBalance(owner: string): Promise {
- return 0
- }
-
- /**
- * @returns {Promise} Total supply of the token
- */
- async getTotalSupply(): Promise {
- return 0
- }
-
- /**
- * @param {string} owner Address of owner of the tokens that is being used
- * @param {string} spender Address of the spender that is using the tokens of owner
- * @returns {Promise} Amount of tokens that the spender is allowed to spend
- */
- async getAllowance(owner: string, spender: string): Promise {
- return 0
- }
-
- /**
- * transfer() method is the main method for processing transfers for fungible assets (TOKEN, COIN)
- * @param {string} sender Sender wallet address
- * @param {string} receiver Receiver wallet address
- * @param {number} amount Amount of assets that will be transferred
- * @returns {Promise} Transaction signer
- */
- async transfer(
- sender: string,
- receiver: string,
- amount: number
- ): Promise {
- return new TokenTransactionSigner('example')
- }
-
- /**
- * @param {string} spender Address of the spender of transaction
- * @param {string} owner Sender wallet address
- * @param {string} receiver Receiver wallet address
- * @param {number} amount Amount of tokens that will be transferred
- * @returns {Promise} Transaction signer
- */
- async transferFrom(
- spender: string,
- owner: string,
- receiver: string,
- amount: number
- ): Promise {
- return new TokenTransactionSigner('example')
- }
-
- /**
- * Gives permission to the spender to spend owner's tokens
- * @param {string} owner Address of owner of the tokens that will be used
- * @param {string} spender Address of the spender that will use the tokens of owner
- * @param {number} amount Amount of the tokens that will be used
- * @returns {Promise} Transaction signer
- */
- async approve(owner: string, spender: string, amount: number): Promise {
- return new TokenTransactionSigner('example')
- }
-}
diff --git a/packages/networks/bitcoin/src/assets/index.ts b/packages/networks/bitcoin/src/assets/index.ts
index 7ea522f..5742d2b 100644
--- a/packages/networks/bitcoin/src/assets/index.ts
+++ b/packages/networks/bitcoin/src/assets/index.ts
@@ -1,4 +1 @@
-export * from './NFT.ts'
export * from './Coin.ts'
-export * from './Token.ts'
-export * from './Contract.ts'
diff --git a/packages/networks/bitcoin/src/browser/Wallet.ts b/packages/networks/bitcoin/src/browser/Wallet.ts
index cb8e8d0..7520be9 100644
--- a/packages/networks/bitcoin/src/browser/Wallet.ts
+++ b/packages/networks/bitcoin/src/browser/Wallet.ts
@@ -2,12 +2,15 @@ import {
type WalletInterface,
type WalletAdapterInterface,
type WalletPlatformEnum,
- type TransactionSignerInterface,
- type ProviderInterface,
- ErrorTypeEnum
+ ErrorTypeEnum,
+ type UnknownConfig,
+ type ConnectConfig,
+ type WalletAddress,
+ type SignedMessage,
+ type TransactionId
} from '@multiplechain/types'
import { Provider } from '../services/Provider.ts'
-import type { TransactionData } from '../services/TransactionSigner.ts'
+import type { TransactionSigner } from '../services/TransactionSigner.ts'
export interface BitcoinWalletAdapter {
getAddress: () => Promise
@@ -30,18 +33,20 @@ const rejectMap = (error: any, reject: (a: any) => any): any => {
return reject(error)
}
-export class Wallet implements WalletInterface {
- adapter: WalletAdapterInterface
+type WalletAdapter = WalletAdapterInterface
+
+export class Wallet implements WalletInterface {
+ adapter: WalletAdapter
walletProvider: BitcoinWalletAdapter
networkProvider: Provider
/**
- * @param {WalletAdapterInterface} adapter
+ * @param {WalletAdapter} adapter
* @param {Provider} provider
*/
- constructor(adapter: WalletAdapterInterface, provider?: Provider) {
+ constructor(adapter: WalletAdapter, provider?: Provider) {
this.adapter = adapter
this.networkProvider = provider ?? Provider.instance
}
@@ -83,28 +88,27 @@ export class Wallet implements WalletInterface {
/**
* @param {string} url
- * @param {object} ops
+ * @param {UnknownConfig} config
* @returns {string}
*/
- createDeepLink(url: string, ops?: object): string | null {
+ createDeepLink(url: string, config?: UnknownConfig): string | null {
if (this.adapter.createDeepLink === undefined) {
return null
}
- return this.adapter.createDeepLink(url, ops)
+ return this.adapter.createDeepLink(url, config)
}
/**
- * @param {ProviderInterface} provider
- * @param {Object} ops
- * @returns {Promise}
+ * @param {ConnectConfig} config
+ * @returns {Promise}
*/
- async connect(provider?: ProviderInterface, ops?: object): Promise {
+ async connect(config?: ConnectConfig): Promise {
return await new Promise((resolve, reject) => {
this.adapter
- .connect(provider, ops)
+ .connect(this.networkProvider, config)
.then(async (provider) => {
- this.walletProvider = provider as BitcoinWalletAdapter
+ this.walletProvider = provider
resolve(await this.getAddress())
})
.catch((error) => {
@@ -135,26 +139,45 @@ export class Wallet implements WalletInterface {
}
/**
- * @returns {Promise}
+ * @returns {Promise}
*/
- async getAddress(): Promise {
+ async getAddress(): Promise {
return await this.walletProvider.getAddress()
}
/**
* @param {string} message
+ * @returns {Promise}
*/
- async signMessage(message: string): Promise {
- return await this.walletProvider.signMessage(message)
+ async signMessage(message: string): Promise {
+ return await new Promise((resolve, reject) => {
+ this.walletProvider
+ .signMessage(message)
+ .then((signature) => {
+ resolve(signature)
+ })
+ .catch((error) => {
+ rejectMap(error, reject)
+ })
+ })
}
/**
- * @param {TransactionSignerInterface} transactionSigner
- * @returns {Promise}
+ * @param {TransactionSigner} transactionSigner
+ * @returns {Promise}
*/
- async sendTransaction(transactionSigner: TransactionSignerInterface): Promise {
- const data = (await transactionSigner.getRawData()) as TransactionData
- return await this.walletProvider.sendBitcoin(data.receiver, data.amount)
+ async sendTransaction(transactionSigner: TransactionSigner): Promise {
+ const data = transactionSigner.getRawData()
+ return await new Promise((resolve, reject) => {
+ this.walletProvider
+ .sendBitcoin(data.receiver, data.amount)
+ .then((txHash) => {
+ resolve(txHash)
+ })
+ .catch((error) => {
+ rejectMap(error, reject)
+ })
+ })
}
/**
diff --git a/packages/networks/bitcoin/src/browser/adapters/Leather.ts b/packages/networks/bitcoin/src/browser/adapters/Leather.ts
index 3f363fa..f2863af 100644
--- a/packages/networks/bitcoin/src/browser/adapters/Leather.ts
+++ b/packages/networks/bitcoin/src/browser/adapters/Leather.ts
@@ -1,7 +1,8 @@
import icons from './icons.ts'
import { WalletPlatformEnum } from '@multiplechain/types'
-import type { ProviderInterface, WalletAdapterInterface } from '@multiplechain/types'
+import type { WalletAdapterInterface } from '@multiplechain/types'
import type { BitcoinWalletAdapter } from '../Wallet.ts'
+import type { Provider } from '../../services/Provider.ts'
declare global {
interface Window {
@@ -16,15 +17,16 @@ declare global {
let connected = false
-const Leather: WalletAdapterInterface = {
+const Leather: WalletAdapterInterface = {
id: 'leather',
name: 'Leather',
icon: icons.Leather,
+ provider: window.LeatherProvider,
platforms: [WalletPlatformEnum.BROWSER],
downloadLink: 'https://leather.io/install-extension',
isDetected: () => Boolean(window.LeatherProvider),
isConnected: async () => connected,
- connect: async (provider?: ProviderInterface): Promise => {
+ connect: async (provider?: Provider): Promise => {
return await new Promise((resolve, reject) => {
const leather = window.LeatherProvider
diff --git a/packages/networks/bitcoin/src/browser/adapters/UniSat.ts b/packages/networks/bitcoin/src/browser/adapters/UniSat.ts
index b089c8c..a285d5c 100644
--- a/packages/networks/bitcoin/src/browser/adapters/UniSat.ts
+++ b/packages/networks/bitcoin/src/browser/adapters/UniSat.ts
@@ -1,7 +1,8 @@
import icons from './icons.ts'
import { WalletPlatformEnum } from '@multiplechain/types'
-import type { ProviderInterface, WalletAdapterInterface } from '@multiplechain/types'
import type { BitcoinWalletAdapter } from '../Wallet.ts'
+import type { Provider } from '../../services/Provider.ts'
+import type { WalletAdapterInterface } from '@multiplechain/types'
declare global {
interface Window {
@@ -17,15 +18,16 @@ declare global {
}
}
-const UniSat: WalletAdapterInterface = {
+const UniSat: WalletAdapterInterface = {
id: 'unisat',
name: 'UniSat',
icon: icons.UniSat,
+ provider: window.unisat,
platforms: [WalletPlatformEnum.BROWSER],
downloadLink: 'https://unisat.io/download',
isDetected: () => Boolean(window.unisat?.requestAccounts),
isConnected: async () => window?.unisat?._isConnected ?? false,
- connect: async (provider?: ProviderInterface): Promise => {
+ connect: async (provider?: Provider): Promise => {
return await new Promise((resolve, reject) => {
const network = provider !== undefined && provider?.isTestnet() ? 'testnet' : 'livenet'
diff --git a/packages/networks/bitcoin/src/browser/adapters/Xverse.ts b/packages/networks/bitcoin/src/browser/adapters/Xverse.ts
index ef50592..a6cdde8 100644
--- a/packages/networks/bitcoin/src/browser/adapters/Xverse.ts
+++ b/packages/networks/bitcoin/src/browser/adapters/Xverse.ts
@@ -3,7 +3,6 @@ import type { BitcoinWalletAdapter } from '../Wallet.ts'
import {
ErrorTypeEnum,
WalletPlatformEnum,
- type ProviderInterface,
type WalletAdapterInterface
} from '@multiplechain/types'
import {
@@ -13,18 +12,20 @@ import {
signMessage,
AddressPurpose
} from 'sats-connect'
+import type { Provider } from '../../services/Provider.ts'
let connected = false
-const Xverse: WalletAdapterInterface = {
+const Xverse: WalletAdapterInterface = {
id: 'xverse',
name: 'Xverse',
icon: icons.Xverse,
+ provider: window.XverseProviders?.BitcoinProvider,
platforms: [WalletPlatformEnum.BROWSER, WalletPlatformEnum.MOBILE],
downloadLink: 'https://www.xverse.app/download',
isDetected: () => Boolean(window.XverseProviders?.BitcoinProvider),
isConnected: async () => connected,
- connect: async (provider?: ProviderInterface): Promise => {
+ connect: async (provider?: Provider): Promise => {
return await new Promise((resolve, reject) => {
const type =
provider !== undefined && provider?.isTestnet()
diff --git a/packages/networks/bitcoin/src/browser/index.ts b/packages/networks/bitcoin/src/browser/index.ts
index 787e9bd..0695fc8 100644
--- a/packages/networks/bitcoin/src/browser/index.ts
+++ b/packages/networks/bitcoin/src/browser/index.ts
@@ -1,4 +1,5 @@
-import { Wallet } from './Wallet.ts'
+import type { Provider } from 'sats-connect'
+import { Wallet, type BitcoinWalletAdapter } from './Wallet.ts'
import * as adapterList from './adapters/index.ts'
import type {
WalletAdapterListType,
@@ -6,9 +7,11 @@ import type {
RegisterWalletAdapterType
} from '@multiplechain/types'
-const adapters: WalletAdapterListType = {}
+const adapters: WalletAdapterListType = {}
-const registerAdapter: RegisterWalletAdapterType = (adapter: WalletAdapterInterface): void => {
+const registerAdapter: RegisterWalletAdapterType = (
+ adapter: WalletAdapterInterface
+): void => {
if (Object.values(adapters).find((a) => a.id === adapter.id) !== undefined) {
throw new Error(`Adapter with id ${adapter.id} already exists`)
}
diff --git a/packages/networks/bitcoin/src/models/CoinTransaction.ts b/packages/networks/bitcoin/src/models/CoinTransaction.ts
index d681e05..353e75d 100644
--- a/packages/networks/bitcoin/src/models/CoinTransaction.ts
+++ b/packages/networks/bitcoin/src/models/CoinTransaction.ts
@@ -1,42 +1,42 @@
import { fromSatoshi } from '../utils.ts'
import { Transaction } from './Transaction.ts'
-import { TransactionStatusEnum } from '@multiplechain/types'
-import { AssetDirectionEnum, type CoinTransactionInterface } from '@multiplechain/types'
+import { TransactionStatusEnum, AssetDirectionEnum } from '@multiplechain/types'
+import type { WalletAddress, CoinTransactionInterface, TransferAmount } from '@multiplechain/types'
export class CoinTransaction extends Transaction implements CoinTransactionInterface {
/**
- * @returns {Promise} Wallet address of the receiver of transaction
+ * @returns {Promise} Wallet address of the receiver of transaction
*/
- async getReceiver(): Promise {
+ async getReceiver(): Promise {
const data = await this.getData()
return data?.vout[0].scriptpubkey_address ?? ''
}
/**
- * @returns {Promise} Wallet address of the sender of transaction
+ * @returns {Promise} Wallet address of the sender of transaction
*/
- async getSender(): Promise {
+ async getSender(): Promise {
return await this.getSigner()
}
/**
- * @returns {Promise} Amount of coin that will be transferred
+ * @returns {Promise} Amount of coin that will be transferred
*/
- async getAmount(): Promise {
+ async getAmount(): Promise {
const data = await this.getData()
return fromSatoshi(data?.vout[0].value ?? 0)
}
/**
* @param {AssetDirectionEnum} direction - Direction of the transaction (asset)
- * @param {string} address - Wallet address of the receiver or sender of the transaction, dependant on direction
- * @param {number} amount Amount of assets that will be transferred
+ * @param {WalletAddress} address - Wallet address of the receiver or sender of the transaction, dependant on direction
+ * @param {TransferAmount} amount Amount of assets that will be transferred
* @returns {Promise} Status of the transaction
*/
async verifyTransfer(
direction: AssetDirectionEnum,
- address: string,
- amount: number
+ address: WalletAddress,
+ amount: TransferAmount
): Promise {
const status = await this.getStatus()
diff --git a/packages/networks/bitcoin/src/models/ContractTransaction.ts b/packages/networks/bitcoin/src/models/ContractTransaction.ts
deleted file mode 100644
index 4813a5a..0000000
--- a/packages/networks/bitcoin/src/models/ContractTransaction.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { Transaction } from './Transaction.ts'
-import type { Provider } from '../services/Provider.ts'
-import type { ContractTransactionInterface } from '@multiplechain/types'
-
-export class ContractTransaction extends Transaction implements ContractTransactionInterface {
- /**
- * @param {string} id Transaction id
- * @param {Provider} provider Blockchain network provider
- */
- constructor(id: string, provider?: Provider) {
- super(id, provider)
- throw new Error('This class is not implemented for Bitcoin.')
- }
-
- /**
- * @returns {Promise} Contract address of the transaction
- */
- async getAddress(): Promise {
- return 'example'
- }
-}
diff --git a/packages/networks/bitcoin/src/models/NftTransaction.ts b/packages/networks/bitcoin/src/models/NftTransaction.ts
deleted file mode 100644
index 09b8d80..0000000
--- a/packages/networks/bitcoin/src/models/NftTransaction.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import { ContractTransaction } from './ContractTransaction.ts'
-import { TransactionStatusEnum } from '@multiplechain/types'
-import type { NftTransactionInterface, AssetDirectionEnum } from '@multiplechain/types'
-
-export class NftTransaction extends ContractTransaction implements NftTransactionInterface {
- /**
- * @returns {Promise} Receiver wallet address
- */
- async getReceiver(): Promise {
- return 'example'
- }
-
- /**
- * @returns {Promise} Wallet address of the sender of transaction
- */
- async getSender(): Promise {
- return 'example'
- }
-
- /**
- * @returns {Promise} NFT ID
- */
- async getNftId(): Promise {
- return 0
- }
-
- /**
- * @param {AssetDirectionEnum} direction - Direction of the transaction (nft)
- * @param {string} address - Wallet address of the receiver or sender of the transaction, dependant on direction
- * @param {number} nftId ID of the NFT that will be transferred
- * @override verifyTransfer() in AssetTransactionInterface
- * @returns {Promise} Status of the transaction
- */
- async verifyTransfer(
- direction: AssetDirectionEnum,
- address: string,
- nftId: number | string
- ): Promise {
- return TransactionStatusEnum.PENDING
- }
-}
diff --git a/packages/networks/bitcoin/src/models/TokenTransaction.ts b/packages/networks/bitcoin/src/models/TokenTransaction.ts
deleted file mode 100644
index b1ea29e..0000000
--- a/packages/networks/bitcoin/src/models/TokenTransaction.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import { ContractTransaction } from './ContractTransaction.ts'
-import { TransactionStatusEnum } from '@multiplechain/types'
-import type { AssetDirectionEnum, TokenTransactionInterface } from '@multiplechain/types'
-
-export class TokenTransaction extends ContractTransaction implements TokenTransactionInterface {
- /**
- * @returns {Promise} Wallet address of the receiver of transaction
- */
- async getReceiver(): Promise {
- return 'example'
- }
-
- /**
- * @returns {Promise} Wallet address of the sender of transaction
- */
- async getSender(): Promise {
- return 'example'
- }
-
- /**
- * @returns {Promise} Amount of tokens that will be transferred
- */
- async getAmount(): Promise {
- return 0
- }
-
- /**
- * @param {AssetDirectionEnum} direction - Direction of the transaction (token)
- * @param {string} address - Wallet address of the owner or spender of the transaction, dependant on direction
- * @param {number} amount Amount of tokens that will be approved
- * @returns {Promise} Status of the transaction
- */
- async verifyTransfer(
- direction: AssetDirectionEnum,
- address: string,
- amount: number
- ): Promise {
- return TransactionStatusEnum.PENDING
- }
-}
diff --git a/packages/networks/bitcoin/src/models/Transaction.ts b/packages/networks/bitcoin/src/models/Transaction.ts
index 4cdeed8..2026094 100644
--- a/packages/networks/bitcoin/src/models/Transaction.ts
+++ b/packages/networks/bitcoin/src/models/Transaction.ts
@@ -1,8 +1,17 @@
import { fromSatoshi, sleep } from '../utils.ts'
import axios, { type AxiosError } from 'axios'
import { Provider } from '../services/Provider.ts'
-import type { TransactionInterface } from '@multiplechain/types'
import { ErrorTypeEnum, TransactionStatusEnum } from '@multiplechain/types'
+import {
+ TransactionTypeEnum,
+ type BlockConfirmationCount,
+ type BlockNumber,
+ type BlockTimestamp,
+ type TransactionFee,
+ type TransactionId,
+ type TransactionInterface,
+ type WalletAddress
+} from '@multiplechain/types'
export interface VinObject {
txid: string
@@ -48,11 +57,11 @@ export interface TransactionData {
let counter = 0
-export class Transaction implements TransactionInterface {
+export class Transaction implements TransactionInterface {
/**
* Each transaction has its own unique ID defined by the user
*/
- id: string
+ id: TransactionId
/**
* Blockchain network provider
@@ -65,10 +74,10 @@ export class Transaction implements TransactionInterface {
data: TransactionData | null = null
/**
- * @param {string} id Transaction id
+ * @param {TransactionId} id Transaction id
* @param {Provider} provider Blockchain network provider
*/
- constructor(id: string, provider?: Provider) {
+ constructor(id: TransactionId, provider?: Provider) {
this.id = id
this.provider = provider ?? Provider.instance
}
@@ -129,12 +138,19 @@ export class Transaction implements TransactionInterface {
}
/**
- * @returns {string} Transaction ID
+ * @returns {TransactionId} Transaction ID
*/
- getId(): string {
+ getId(): TransactionId {
return this.id
}
+ /**
+ * @returns {Promise} Transaction type
+ */
+ async getType(): Promise {
+ return TransactionTypeEnum.COIN
+ }
+
/**
* @returns {string} Transaction URL
*/
@@ -143,41 +159,41 @@ export class Transaction implements TransactionInterface {
}
/**
- * @returns {Promise} Wallet address of the sender of transaction
+ * @returns {Promise} Wallet address of the sender of transaction
*/
- async getSigner(): Promise {
+ async getSigner(): Promise {
const data = await this.getData()
return data?.vin[0].prevout.scriptpubkey_address ?? ''
}
/**
- * @returns {Promise} Transaction fee
+ * @returns {Promise} Transaction fee
*/
- async getFee(): Promise {
+ async getFee(): Promise {
const data = await this.getData()
return fromSatoshi(data?.fee ?? 0)
}
/**
- * @returns {Promise} Block number that transaction
+ * @returns {Promise} Block number that transaction
*/
- async getBlockNumber(): Promise {
+ async getBlockNumber(): Promise {
const data = await this.getData()
return data?.status?.block_height ?? 0
}
/**
- * @returns {Promise} Block timestamp that transaction
+ * @returns {Promise} Block timestamp that transaction
*/
- async getBlockTimestamp(): Promise {
+ async getBlockTimestamp(): Promise {
const data = await this.getData()
return data?.status?.block_time ?? 0
}
/**
- * @returns {Promise} Confirmation count of the block
+ * @returns {Promise} Confirmation count of the block
*/
- async getBlockConfirmationCount(): Promise {
+ async getBlockConfirmationCount(): Promise {
const data = await this.getData()
if (data === null) {
return 0
diff --git a/packages/networks/bitcoin/src/models/index.ts b/packages/networks/bitcoin/src/models/index.ts
index cc0a27c..f4c3f87 100644
--- a/packages/networks/bitcoin/src/models/index.ts
+++ b/packages/networks/bitcoin/src/models/index.ts
@@ -1,5 +1,2 @@
export * from './Transaction.ts'
-export * from './NftTransaction.ts'
export * from './CoinTransaction.ts'
-export * from './TokenTransaction.ts'
-export * from './ContractTransaction.ts'
diff --git a/packages/networks/bitcoin/src/services/Provider.ts b/packages/networks/bitcoin/src/services/Provider.ts
index 30086e2..1553561 100644
--- a/packages/networks/bitcoin/src/services/Provider.ts
+++ b/packages/networks/bitcoin/src/services/Provider.ts
@@ -7,7 +7,7 @@ export interface BitcoinNetworkConfigInterface {
blockCypherToken?: string
}
-export class Provider implements Omit {
+export class Provider implements ProviderInterface {
/**
* Network configuration of the provider
*/
@@ -113,7 +113,8 @@ export class Provider implements Omit {
/**
* Update network configuration of the provider
- * @param network - Network configuration of the provider
+ * @param {BitcoinNetworkConfigInterface} network - Network configuration
+ * @returns {void}
*/
update(network: BitcoinNetworkConfigInterface): void {
this.network = network
@@ -148,7 +149,7 @@ export class Provider implements Omit {
/**
* Get the current network configuration is testnet or not
- * @returns boolean
+ * @returns {boolean} Testnet or not
*/
isTestnet(): boolean {
return this.network?.testnet ?? false
diff --git a/packages/networks/bitcoin/src/services/TransactionListener.ts b/packages/networks/bitcoin/src/services/TransactionListener.ts
index 04fa972..62feff9 100644
--- a/packages/networks/bitcoin/src/services/TransactionListener.ts
+++ b/packages/networks/bitcoin/src/services/TransactionListener.ts
@@ -2,16 +2,14 @@ import type {
TransactionTypeEnum,
DynamicTransactionType,
TransactionListenerInterface,
- DynamicTransactionListenerFilterType
+ DynamicTransactionListenerFilterType,
+ TransactionId
} from '@multiplechain/types'
import WebSocket from 'ws'
import { Provider } from './Provider.ts'
import { fromSatoshi } from '../utils.ts'
import { Transaction } from '../models/Transaction.ts'
-import type { NftTransaction } from '../models/NftTransaction.ts'
import { CoinTransaction } from '../models/CoinTransaction.ts'
-import type { TokenTransaction } from '../models/TokenTransaction.ts'
-import type { ContractTransaction } from '../models/ContractTransaction.ts'
import { checkWebSocket, objectsEqual } from '@multiplechain/utils'
import { TransactionListenerProcessIndex } from '@multiplechain/types'
@@ -25,10 +23,10 @@ interface Values {
type TransactionListenerTriggerType = DynamicTransactionType<
T,
Transaction,
- ContractTransaction,
+ Transaction,
CoinTransaction,
- TokenTransaction,
- NftTransaction
+ Transaction,
+ Transaction
>
type TransactionListenerCallbackType<
@@ -48,29 +46,29 @@ export class TransactionListener<
type: T
/**
- * Transaction listener callback
+ * Provider
*/
- callbacks: CallBackType[] = []
+ provider: Provider
/**
- * Transaction listener filter
+ * Listener status
*/
- filter?: DynamicTransactionListenerFilterType | Record
+ status: boolean = false
/**
- * Provider
+ * Transaction listener callback
*/
- provider: Provider
+ callbacks: CallBackType[] = []
/**
- * Listener status
+ * Triggered transactions
*/
- status: boolean = false
+ triggeredTransactions: TransactionId[] = []
/**
- * Triggered transactions
+ * Transaction listener filter
*/
- triggeredTransactions: string[] = []
+ filter?: DynamicTransactionListenerFilterType | Record
/**
* WebSocket
diff --git a/packages/networks/bitcoin/src/services/TransactionSigner.ts b/packages/networks/bitcoin/src/services/TransactionSigner.ts
index 15ae13a..e0526c5 100644
--- a/packages/networks/bitcoin/src/services/TransactionSigner.ts
+++ b/packages/networks/bitcoin/src/services/TransactionSigner.ts
@@ -1,12 +1,8 @@
import axios from 'axios'
import type { AxiosError } from 'axios'
import { Provider } from '../services/Provider.ts'
-import { Transaction } from '../models/Transaction.ts'
-import { NftTransaction } from '../models/NftTransaction.ts'
-import { CoinTransaction } from '../models/CoinTransaction.ts'
-import { TokenTransaction } from '../models/TokenTransaction.ts'
-import { type TransactionSignerInterface } from '@multiplechain/types'
import type { Transaction as BitcoreLibTransactionData } from 'bitcore-lib'
+import type { PrivateKey, TransactionId, TransactionSignerInterface } from '@multiplechain/types'
export interface TransactionData {
sender: string
@@ -15,7 +11,7 @@ export interface TransactionData {
bitcoreLib: BitcoreLibTransactionData
}
-export class TransactionSigner implements TransactionSignerInterface {
+export class TransactionSigner implements TransactionSignerInterface {
/**
* Transaction data from the blockchain network
*/
@@ -33,6 +29,7 @@ export class TransactionSigner implements TransactionSignerInterface {
/**
* @param {TransactionData} rawData - Transaction data
+ * @param {Provider} provider - Blockchain network provider
*/
constructor(rawData: TransactionData, provider?: Provider) {
this.rawData = rawData
@@ -41,10 +38,10 @@ export class TransactionSigner implements TransactionSignerInterface {
/**
* Sign the transaction
- * @param {string} privateKey - Transaction data
- * @returns {Promise} Signed transaction data
+ * @param {PrivateKey} privateKey - Transaction data
+ * @returns {Promise} Signed transaction data
*/
- async sign(privateKey: string): Promise {
+ async sign(privateKey: PrivateKey): Promise {
this.rawData.bitcoreLib.sign(privateKey)
this.signedData = this.rawData.bitcoreLib.serialize()
return this
@@ -52,16 +49,16 @@ export class TransactionSigner implements TransactionSignerInterface {
/**
* Send the transaction to the blockchain network
- * @returns {Promise}
+ * @returns {Promise}
*/
- async send(): Promise {
+ async send(): Promise {
try {
const result = await axios({
method: 'POST',
url: `https://blockstream.info/testnet/api/tx`,
data: this.signedData
})
- return new Transaction(result.data as string)
+ return result.data as TransactionId
} catch (error: any) {
throw new Error(JSON.stringify((error as AxiosError).response?.data))
}
@@ -69,7 +66,7 @@ export class TransactionSigner implements TransactionSignerInterface {
/**
* Get the raw transaction data
- * @returns Transaction data
+ * @returns {TransactionData}
*/
getRawData(): TransactionData {
return this.rawData
@@ -77,39 +74,9 @@ export class TransactionSigner implements TransactionSignerInterface {
/**
* Get the signed transaction data
- * @returns Signed transaction data
+ * @returns {string}
*/
getSignedData(): string {
return this.signedData ?? ''
}
}
-
-export class CoinTransactionSigner extends TransactionSigner {
- /**
- * Send the transaction to the blockchain network
- * @returns {Promise} Transaction data
- */
- async send(): Promise {
- return new CoinTransaction((await super.send()).getId())
- }
-}
-
-export class TokenTransactionSigner extends TransactionSigner {
- /**
- * Send the transaction to the blockchain network
- * @returns {Promise} Transaction data
- */
- async send(): Promise {
- return new TokenTransaction((await super.send()).getId())
- }
-}
-
-export class NftTransactionSigner extends TransactionSigner {
- /**
- * Send the transaction to the blockchain network
- * @returns {Promise} Transaction data
- */
- async send(): Promise {
- return new NftTransaction((await super.send()).getId())
- }
-}
diff --git a/packages/networks/bitcoin/tests/assets.spec.ts b/packages/networks/bitcoin/tests/assets.spec.ts
index 36147df..5edb0a1 100644
--- a/packages/networks/bitcoin/tests/assets.spec.ts
+++ b/packages/networks/bitcoin/tests/assets.spec.ts
@@ -3,7 +3,7 @@ import { describe, it, expect, assert } from 'vitest'
import { Coin } from '../src/assets/Coin.ts'
import { math } from '@multiplechain/utils'
import { Transaction } from '../src/models/Transaction.ts'
-import { TransactionStatusEnum } from '@multiplechain/types'
+import { TransactionStatusEnum, type TransactionId } from '@multiplechain/types'
import { TransactionSigner } from '../src/services/TransactionSigner.ts'
const testAmount = Number(process.env.BTC_TRANSFER_AMOUNT)
@@ -24,8 +24,8 @@ const checkSigner = async (signer: TransactionSigner, privateKey?: string): Prom
assert.isString(signer.getSignedData())
}
-const checkTx = async (transaction: Transaction): Promise => {
- expect(transaction).toBeInstanceOf(Transaction)
+const checkTx = async (transactionId: TransactionId): Promise => {
+ const transaction = new Transaction(transactionId)
const status = await transaction.wait(10 * 1000)
expect(status).toBe(TransactionStatusEnum.CONFIRMED)
}
diff --git a/packages/networks/boilerplate/README.md b/packages/networks/boilerplate/README.md
index e69de29..d746267 100644
--- a/packages/networks/boilerplate/README.md
+++ b/packages/networks/boilerplate/README.md
@@ -0,0 +1,7 @@
+# MultipleChain standard for JavaScript
+
+## Introduction
+
+MultipleChain aims for easy access by simplifying the complex structure of many blockchains. For example, each blockchain network has a different structure for transfer initiation or transaction data. You may need to learn new things from scratch for each blockchain network. This is necessary if you want to go into detail. But if you just want to get to the basics. MultipleChain will make your work much easier. In many different programming languages.
+
+#### 📚 [Documentation](https://multiplechain.gitbook.io/multiplechain-docs)
\ No newline at end of file
diff --git a/packages/networks/boilerplate/index.html b/packages/networks/boilerplate/index.example.html
similarity index 99%
rename from packages/networks/boilerplate/index.html
rename to packages/networks/boilerplate/index.example.html
index 4e508e4..cc91fa0 100644
--- a/packages/networks/boilerplate/index.html
+++ b/packages/networks/boilerplate/index.example.html
@@ -230,7 +230,7 @@
}
const wallet = new Boilerplate.browser.Wallet(adapter)
- const adapterProvider = await wallet.connect(provider, {
+ const adapterProvider = await wallet.connect({
projectId: '113d9f5689edd84ff230c2a6d679c80c'
})
diff --git a/packages/networks/boilerplate/package.json b/packages/networks/boilerplate/package.json
index 9e3607a..144af60 100644
--- a/packages/networks/boilerplate/package.json
+++ b/packages/networks/boilerplate/package.json
@@ -27,6 +27,16 @@
"types": "./dist/browser/index.d.ts"
}
},
+ "typesVersions": {
+ "*": {
+ "node": [
+ "./dist/index.d.ts"
+ ],
+ "browser": [
+ "./dist/browser/index.d.ts"
+ ]
+ }
+ },
"files": [
"dist",
"README.md",
@@ -62,7 +72,7 @@
"url": "https://github.com/MultipleChain/js/issues"
},
"dependencies": {
- "@multiplechain/types": "^0.1.56",
- "@multiplechain/utils": "^0.1.20"
+ "@multiplechain/types": "^0.1.63",
+ "@multiplechain/utils": "^0.1.21"
}
}
\ No newline at end of file
diff --git a/packages/networks/boilerplate/pnpm-lock.yaml b/packages/networks/boilerplate/pnpm-lock.yaml
index 08e12c2..c63ee4e 100644
--- a/packages/networks/boilerplate/pnpm-lock.yaml
+++ b/packages/networks/boilerplate/pnpm-lock.yaml
@@ -6,20 +6,20 @@ settings:
dependencies:
'@multiplechain/types':
- specifier: ^0.1.56
- version: 0.1.56
+ specifier: ^0.1.63
+ version: 0.1.63
'@multiplechain/utils':
- specifier: ^0.1.20
- version: 0.1.20
+ specifier: ^0.1.21
+ version: 0.1.21
packages:
- /@multiplechain/types@0.1.56:
- resolution: {integrity: sha512-tnkgDwW0AWxEfhE/392LR6ZPE7Pxz5/Ei1XYsQISGkOfYYZrsvJXr69fXTjDOHCq7RCuQqytKmhnKs5K4xHd7w==}
+ /@multiplechain/types@0.1.63:
+ resolution: {integrity: sha512-4C201vUsN6F1S/M7vT+GZS0wTdKGZXHqn4YmC6ouC8n0uxMCEFdI2sSCadyHKFKG5OBPo16X1oFCX9MVwPqMoA==}
dev: false
- /@multiplechain/utils@0.1.20:
- resolution: {integrity: sha512-4eEs4YR/V4F2Qnkl5KTZvPpewRQiX7C193d0tjpQuIfyumTEBJtdHYm1CW9CoJ6EjQUaB0oqSRKXomhzfK1qkw==}
+ /@multiplechain/utils@0.1.21:
+ resolution: {integrity: sha512-4mRlnhvXcS+7Hb1By5s2eoCH02kqOSQzV8qj0DHqZK20FtxtduaoGCtcClrFgEjN/HAXnHgdDc1pxTpveIkvRQ==}
dependencies:
'@types/ws': 8.5.10
bignumber.js: 9.1.2
diff --git a/packages/networks/boilerplate/src/assets/Coin.ts b/packages/networks/boilerplate/src/assets/Coin.ts
index 1c2d8b3..2b7df88 100644
--- a/packages/networks/boilerplate/src/assets/Coin.ts
+++ b/packages/networks/boilerplate/src/assets/Coin.ts
@@ -1,8 +1,8 @@
import { Provider } from '../services/Provider.ts'
-import type { CoinInterface } from '@multiplechain/types'
-import { CoinTransactionSigner } from '../services/TransactionSigner.ts'
+import { TransactionSigner } from '../services/TransactionSigner.ts'
+import type { CoinInterface, TransferAmount, WalletAddress } from '@multiplechain/types'
-export class Coin implements CoinInterface {
+export class Coin implements CoinInterface {
/**
* Blockchain network provider
*/
@@ -37,24 +37,24 @@ export class Coin implements CoinInterface {
}
/**
- * @param {string} owner Wallet address
+ * @param {WalletAddress} owner Wallet address
* @returns {Promise} Wallet balance as currency of COIN
*/
- async getBalance(owner: string): Promise {
+ async getBalance(owner: WalletAddress): Promise {
return 0
}
/**
- * @param {string} sender Sender wallet address
- * @param {string} receiver Receiver wallet address
- * @param {number} amount Amount of assets that will be transferred
+ * @param {WalletAddress} sender Sender wallet address
+ * @param {WalletAddress} receiver Receiver wallet address
+ * @param {TransferAmount} amount Amount of assets that will be transferred
* @returns {Promise} Transaction signer
*/
async transfer(
- sender: string,
- receiver: string,
- amount: number
- ): Promise {
- return new CoinTransactionSigner('example')
+ sender: WalletAddress,
+ receiver: WalletAddress,
+ amount: TransferAmount
+ ): Promise {
+ return new TransactionSigner('example')
}
}
diff --git a/packages/networks/boilerplate/src/assets/Contract.ts b/packages/networks/boilerplate/src/assets/Contract.ts
index ee3a295..5b63d07 100644
--- a/packages/networks/boilerplate/src/assets/Contract.ts
+++ b/packages/networks/boilerplate/src/assets/Contract.ts
@@ -1,11 +1,11 @@
import { Provider } from '../services/Provider.ts'
-import type { ContractInterface } from '@multiplechain/types'
+import type { ContractAddress, ContractInterface, WalletAddress } from '@multiplechain/types'
export class Contract implements ContractInterface {
/**
* Contract address
*/
- address: string
+ address: ContractAddress
/**
* Blockchain network provider
@@ -13,46 +13,50 @@ export class Contract implements ContractInterface {
provider: Provider
/**
- * @param {string} address Contract address
+ * @param {ContractAddress} address Contract address
* @param {Provider} provider Blockchain network provider
*/
- constructor(address: string, provider?: Provider) {
+ constructor(address: ContractAddress, provider?: Provider) {
this.address = address
this.provider = provider ?? Provider.instance
}
/**
- * @returns {string} Contract address
+ * @returns {ContractAddress} Contract address
*/
- getAddress(): string {
+ getAddress(): ContractAddress {
return this.address
}
/**
* @param {string} method Method name
- * @param {any[]} args Method parameters
- * @returns {Promise} Method result
+ * @param {unknown[]} args Method parameters
+ * @returns {Promise} Method result
*/
- async callMethod(method: string, ...args: any[]): Promise {
+ async callMethod(method: string, ...args: unknown[]): Promise {
return {}
}
/**
* @param {string} method Method name
- * @param {any[]} args Sender wallet address
- * @returns {Promise} Encoded method data
+ * @param {unknown[]} args Sender wallet address
+ * @returns {Promise} Encoded method data
*/
- async getMethodData(method: string, ...args: any[]): Promise {
+ async getMethodData(method: string, ...args: unknown[]): Promise {
return {}
}
/**
* @param {string} method Method name
- * @param {string} from Sender wallet address
- * @param {any[]} args Method parameters
- * @returns {Promise} Encoded method data
+ * @param {WalletAddress} from Sender wallet address
+ * @param {unknown[]} args Method parameters
+ * @returns {Promise} Encoded method data
*/
- async createTransactionData(method: string, from: string, ...args: any[]): Promise {
+ async createTransactionData(
+ method: string,
+ from: WalletAddress,
+ ...args: any[]
+ ): Promise {
return ''
}
}
diff --git a/packages/networks/boilerplate/src/assets/NFT.ts b/packages/networks/boilerplate/src/assets/NFT.ts
index 0a89a51..5452c21 100644
--- a/packages/networks/boilerplate/src/assets/NFT.ts
+++ b/packages/networks/boilerplate/src/assets/NFT.ts
@@ -1,8 +1,8 @@
import { Contract } from './Contract.ts'
-import type { NftInterface } from '@multiplechain/types'
-import { NftTransactionSigner } from '../services/TransactionSigner.ts'
+import { TransactionSigner } from '../services/TransactionSigner.ts'
+import type { NftId, NftInterface, WalletAddress } from '@multiplechain/types'
-export class NFT extends Contract implements NftInterface {
+export class NFT extends Contract implements NftInterface {
/**
* @returns {Promise} NFT name
*/
@@ -18,79 +18,79 @@ export class NFT extends Contract implements NftInterface {
}
/**
- * @param {string} owner Wallet address
+ * @param {WalletAddress} owner Wallet address
* @returns {Promise} Wallet balance as currency of NFT
*/
- async getBalance(owner: string): Promise {
+ async getBalance(owner: WalletAddress): Promise {
return 0
}
/**
- * @param {number | string} nftId NFT ID
- * @returns {Promise} Wallet address of the owner of the NFT
+ * @param {NftId} nftId NFT ID
+ * @returns {Promise} Wallet address of the owner of the NFT
*/
- async getOwner(nftId: number | string): Promise {
+ async getOwner(nftId: NftId): Promise {
return 'example'
}
/**
- * @param {number | string} nftId NFT ID
+ * @param {NftId} nftId NFT ID
* @returns {Promise} URI of the NFT
*/
- async getTokenURI(nftId: number | string): Promise {
+ async getTokenURI(nftId: NftId): Promise {
return 'example'
}
/**
- * @param {number | string} nftId ID of the NFT that will be transferred
- * @returns {Promise} Wallet address of the approved spender
+ * @param {NftId} nftId ID of the NFT that will be transferred
+ * @returns {Promise} Wallet address of the approved spender
*/
- async getApproved(nftId: number | string): Promise {
+ async getApproved(nftId: NftId): Promise {
return 'example'
}
/**
- * @param {string} sender Sender address
- * @param {string} receiver Receiver address
- * @param {number | string} nftId NFT ID
- * @returns {Promise} Transaction signer
+ * @param {WalletAddress} sender Sender address
+ * @param {WalletAddress} receiver Receiver address
+ * @param {NftId} nftId NFT ID
+ * @returns {Promise} Transaction signer
*/
async transfer(
- sender: string,
- receiver: string,
- nftId: number | string
- ): Promise {
- return new NftTransactionSigner('example')
+ sender: WalletAddress,
+ receiver: WalletAddress,
+ nftId: NftId
+ ): Promise {
+ return new TransactionSigner('example')
}
/**
- * @param {string} spender Spender address
- * @param {string} owner Owner address
- * @param {string} receiver Receiver address
- * @param {number | string} nftId NFT ID
- * @returns {Promise} Transaction signer
+ * @param {WalletAddress} spender Spender address
+ * @param {WalletAddress} owner Owner address
+ * @param {WalletAddress} receiver Receiver address
+ * @param {NftId} nftId NFT ID
+ * @returns {Promise} Transaction signer
*/
async transferFrom(
- spender: string,
- owner: string,
- receiver: string,
- nftId: number | string
- ): Promise {
- return new NftTransactionSigner('example')
+ spender: WalletAddress,
+ owner: WalletAddress,
+ receiver: WalletAddress,
+ nftId: NftId
+ ): Promise {
+ return new TransactionSigner('example')
}
/**
* Gives permission to the spender to spend owner's tokens
- * @param {string} owner Address of owner of the tokens that will be used
- * @param {string} spender Address of the spender that will use the tokens of owner
- * @param {number | string} nftId ID of the NFT that will be transferred
+ * @param {WalletAddress} owner Address of owner of the tokens that will be used
+ * @param {WalletAddress} spender Address of the spender that will use the tokens of owner
+ * @param {NftId} nftId ID of the NFT that will be transferred
* @returns {Promise} Transaction signer
*/
async approve(
- owner: string,
- spender: string,
- nftId: number | string
- ): Promise {
- return new NftTransactionSigner('example')
+ owner: WalletAddress,
+ spender: WalletAddress,
+ nftId: NftId
+ ): Promise {
+ return new TransactionSigner('example')
}
}
diff --git a/packages/networks/boilerplate/src/assets/Token.ts b/packages/networks/boilerplate/src/assets/Token.ts
index 8d30a0d..0f640e4 100644
--- a/packages/networks/boilerplate/src/assets/Token.ts
+++ b/packages/networks/boilerplate/src/assets/Token.ts
@@ -1,8 +1,8 @@
import { Contract } from './Contract.ts'
-import type { TokenInterface } from '@multiplechain/types'
-import { TokenTransactionSigner } from '../services/TransactionSigner.ts'
+import { TransactionSigner } from '../services/TransactionSigner.ts'
+import type { TokenInterface, TransferAmount, WalletAddress } from '@multiplechain/types'
-export class Token extends Contract implements TokenInterface {
+export class Token extends Contract implements TokenInterface {
/**
* @returns {Promise} Token name
*/
@@ -25,10 +25,10 @@ export class Token extends Contract implements TokenInterface {
}
/**
- * @param {string} owner Wallet address
+ * @param {WalletAddress} owner Wallet address
* @returns {Promise} Wallet balance as currency of TOKEN
*/
- async getBalance(owner: string): Promise {
+ async getBalance(owner: WalletAddress): Promise {
return 0
}
@@ -40,57 +40,57 @@ export class Token extends Contract implements TokenInterface {
}
/**
- * @param {string} owner Address of owner of the tokens that is being used
- * @param {string} spender Address of the spender that is using the tokens of owner
+ * @param {WalletAddress} owner Address of owner of the tokens that is being used
+ * @param {WalletAddress} spender Address of the spender that is using the tokens of owner
* @returns {Promise} Amount of tokens that the spender is allowed to spend
*/
- async getAllowance(owner: string, spender: string): Promise {
+ async getAllowance(owner: WalletAddress, spender: WalletAddress): Promise {
return 0
}
/**
* transfer() method is the main method for processing transfers for fungible assets (TOKEN, COIN)
- * @param {string} sender Sender wallet address
- * @param {string} receiver Receiver wallet address
- * @param {number} amount Amount of assets that will be transferred
+ * @param {WalletAddress} sender Sender wallet address
+ * @param {WalletAddress} receiver Receiver wallet address
+ * @param {TransferAmount} amount Amount of assets that will be transferred
* @returns {Promise} Transaction signer
*/
async transfer(
- sender: string,
- receiver: string,
- amount: number
- ): Promise {
- return new TokenTransactionSigner('example')
+ sender: WalletAddress,
+ receiver: WalletAddress,
+ amount: TransferAmount
+ ): Promise {
+ return new TransactionSigner('example')
}
/**
- * @param {string} spender Address of the spender of transaction
- * @param {string} owner Sender wallet address
- * @param {string} receiver Receiver wallet address
- * @param {number} amount Amount of tokens that will be transferred
- * @returns {Promise} Transaction signer
+ * @param {WalletAddress} spender Address of the spender of transaction
+ * @param {WalletAddress} owner Sender wallet address
+ * @param {WalletAddress} receiver Receiver wallet address
+ * @param {TransferAmount} amount Amount of tokens that will be transferred
+ * @returns {Promise} Transaction signer
*/
async transferFrom(
- spender: string,
- owner: string,
- receiver: string,
- amount: number
- ): Promise {
- return new TokenTransactionSigner('example')
+ spender: WalletAddress,
+ owner: WalletAddress,
+ receiver: WalletAddress,
+ amount: TransferAmount
+ ): Promise {
+ return new TransactionSigner('example')
}
/**
* Gives permission to the spender to spend owner's tokens
- * @param {string} owner Address of owner of the tokens that will be used
- * @param {string} spender Address of the spender that will use the tokens of owner
- * @param {number} amount Amount of the tokens that will be used
+ * @param {WalletAddress} owner Address of owner of the tokens that will be used
+ * @param {WalletAddress} spender Address of the spender that will use the tokens of owner
+ * @param {TransferAmount} amount Amount of the tokens that will be used
* @returns {Promise} Transaction signer
*/
async approve(
- owner: string,
- spender: string,
- amount: number
- ): Promise {
- return new TokenTransactionSigner('example')
+ owner: WalletAddress,
+ spender: WalletAddress,
+ amount: TransferAmount
+ ): Promise {
+ return new TransactionSigner('example')
}
}
diff --git a/packages/networks/boilerplate/src/browser/Wallet.ts b/packages/networks/boilerplate/src/browser/Wallet.ts
index 83ade3f..3d75a8a 100644
--- a/packages/networks/boilerplate/src/browser/Wallet.ts
+++ b/packages/networks/boilerplate/src/browser/Wallet.ts
@@ -1,24 +1,39 @@
+import { Provider } from '../services/Provider.ts'
+import type { TransactionSigner } from '../services/TransactionSigner.ts'
import type {
WalletInterface,
WalletAdapterInterface,
WalletPlatformEnum,
- TransactionSignerInterface,
- ProviderInterface
+ TransactionId,
+ SignedMessage,
+ WalletAddress,
+ ConnectConfig,
+ UnknownConfig
} from '@multiplechain/types'
-import { Provider } from '../services/Provider.ts'
-export class Wallet implements WalletInterface {
- adapter: WalletAdapterInterface
+type WalletAdapter = WalletAdapterInterface
- walletProvider: object
+export class Wallet implements WalletInterface {
+ /**
+ * WalletAdapter instance
+ */
+ adapter: WalletAdapter
+ /**
+ * Wallet provider is the instance of the wallet connection
+ */
+ walletProvider: unknown
+
+ /**
+ * Network provider is the instance of the blockchain network connection
+ */
networkProvider: Provider
/**
- * @param {WalletAdapterInterface} adapter
+ * @param {WalletAdapter} adapter
* @param {Provider} provider
*/
- constructor(adapter: WalletAdapterInterface, provider?: Provider) {
+ constructor(adapter: WalletAdapter, provider?: Provider) {
this.adapter = adapter
this.networkProvider = provider ?? Provider.instance
}
@@ -60,23 +75,22 @@ export class Wallet implements WalletInterface {
/**
* @param {string} url
- * @param {object} ops
+ * @param {UnknownConfig} config
* @returns {string}
*/
- createDeepLink(url: string, ops?: object): string | null {
+ createDeepLink(url: string, config?: UnknownConfig): string | null {
if (this.adapter.createDeepLink === undefined) {
return null
}
- return this.adapter.createDeepLink(url, ops)
+ return this.adapter.createDeepLink(url, config)
}
/**
- * @param {ProviderInterface} provider
- * @param {Object} ops
- * @returns {Promise}
+ * @param {ConnectConfig} config
+ * @returns {Promise}
*/
- async connect(provider?: ProviderInterface, ops?: object): Promise {
+ async connect(config?: ConnectConfig): Promise {
await this.adapter.connect()
return 'wallet address'
}
@@ -96,24 +110,25 @@ export class Wallet implements WalletInterface {
}
/**
- * @returns {Promise}
+ * @returns {Promise}
*/
- async getAddress(): Promise {
+ async getAddress(): Promise {
return 'wallet address'
}
/**
* @param {string} message
+ * @returns {Promise}
*/
- async signMessage(message: string): Promise {
+ async signMessage(message: string): Promise {
return 'signed message'
}
/**
- * @param {TransactionSignerInterface} transactionSigner
- * @returns {Promise}
+ * @param {TransactionSigner} transactionSigner
+ * @returns {Promise}
*/
- async sendTransaction(transactionSigner: TransactionSignerInterface): Promise {
+ async sendTransaction(transactionSigner: TransactionSigner): Promise {
return 'transaction hash'
}
diff --git a/packages/networks/boilerplate/src/browser/adapters/Example.ts b/packages/networks/boilerplate/src/browser/adapters/Example.ts
index b7390b3..54fe875 100644
--- a/packages/networks/boilerplate/src/browser/adapters/Example.ts
+++ b/packages/networks/boilerplate/src/browser/adapters/Example.ts
@@ -1,5 +1,6 @@
+import type { Provider } from '../../services/Provider'
import { WalletPlatformEnum } from '@multiplechain/types'
-import type { WalletAdapterInterface } from '@multiplechain/types'
+import type { ConnectConfig, UnknownConfig, WalletAdapterInterface } from '@multiplechain/types'
declare global {
interface Window {
@@ -7,20 +8,20 @@ declare global {
}
}
-const Example: WalletAdapterInterface = {
+const Example: WalletAdapterInterface = {
id: 'example',
name: 'Example',
icon: 'icon base64 string here',
platforms: [WalletPlatformEnum.BROWSER, WalletPlatformEnum.MOBILE],
downloadLink: 'wallet download link here',
- createDeepLink(url: string, ops?: object): string {
+ createDeepLink(url: string, config?: UnknownConfig): string {
return `https://example.com/dapp/${url}`
},
isDetected: () => Boolean(window?.example),
isConnected: async () => {
return true // return true if connected
},
- connect: async () => {
+ connect: async (provider?: Provider, config?: ConnectConfig) => {
// connect wallet here
return window.example
}
diff --git a/packages/networks/boilerplate/src/browser/index.ts b/packages/networks/boilerplate/src/browser/index.ts
index 787e9bd..5bc8eb8 100644
--- a/packages/networks/boilerplate/src/browser/index.ts
+++ b/packages/networks/boilerplate/src/browser/index.ts
@@ -1,14 +1,17 @@
import { Wallet } from './Wallet.ts'
import * as adapterList from './adapters/index.ts'
+import type { Provider } from '../services/Provider.ts'
import type {
WalletAdapterListType,
WalletAdapterInterface,
RegisterWalletAdapterType
} from '@multiplechain/types'
-const adapters: WalletAdapterListType = {}
+const adapters: WalletAdapterListType = {}
-const registerAdapter: RegisterWalletAdapterType = (adapter: WalletAdapterInterface): void => {
+const registerAdapter: RegisterWalletAdapterType = (
+ adapter: WalletAdapterInterface
+): void => {
if (Object.values(adapters).find((a) => a.id === adapter.id) !== undefined) {
throw new Error(`Adapter with id ${adapter.id} already exists`)
}
diff --git a/packages/networks/boilerplate/src/models/CoinTransaction.ts b/packages/networks/boilerplate/src/models/CoinTransaction.ts
index 9857f2e..0f35f9b 100644
--- a/packages/networks/boilerplate/src/models/CoinTransaction.ts
+++ b/packages/networks/boilerplate/src/models/CoinTransaction.ts
@@ -1,39 +1,39 @@
import { Transaction } from './Transaction.ts'
import { TransactionStatusEnum } from '@multiplechain/types'
-import type { AssetDirectionEnum, CoinTransactionInterface } from '@multiplechain/types'
+import type { AssetDirectionEnum, CoinTransactionInterface, TransferAmount, WalletAddress } from '@multiplechain/types'
export class CoinTransaction extends Transaction implements CoinTransactionInterface {
/**
- * @returns {Promise} Wallet address of the receiver of transaction
+ * @returns {Promise} Wallet address of the receiver of transaction
*/
- async getReceiver(): Promise {
+ async getReceiver(): Promise {
return 'example'
}
/**
- * @returns {Promise} Wallet address of the sender of transaction
+ * @returns {Promise} Wallet address of the sender of transaction
*/
- async getSender(): Promise {
+ async getSender(): Promise {
return 'example'
}
/**
- * @returns {Promise} Amount of coin that will be transferred
+ * @returns {Promise} Amount of coin that will be transferred
*/
- async getAmount(): Promise