Skip to content
Merged
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
14 changes: 7 additions & 7 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
"send-sol": "tsx send-sol.ts",
"send-apt": "tsx send-apt.ts",
"send-sui": "tsx send-sui.ts",
"send-xrp": "tsx send-xrp.ts"
"send-xrp": "tsx send-xrp.ts",
"send-all": "tsx send-eth.ts && tsx send-btc.ts && tsx send-sol.ts && tsx send-apt.ts && tsx send-sui.ts && tsx send-xrp.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@aptos-labs/ts-sdk": "^2.0.1",
"@mysten/sui": "^1.30.5",
"@near-js/accounts": "^1.4.1",
"@near-js/crypto": "^1.4.2",
"@near-js/providers": "^1.0.3",
"@near-js/signers": "^0.1.1",
"@near-js/utils": "^1.1.0",
"@near-wallet-selector/wallet-utils": "^8.10.2",
"@near-js/accounts": "^2.2.4",
"@near-js/crypto": "^2.2.4",
"@near-js/providers": "^2.2.4",
"@near-js/signers": "^2.2.4",
"@near-js/utils": "^2.2.4",
"@noble/hashes": "^1.8.0",
"@solana/web3.js": "^1.98.2",
"chainsig.js": "file:../dist",
Expand Down
12 changes: 6 additions & 6 deletions examples/send-apt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { KeyPairString, KeyPair } from '@near-js/crypto'
import { contracts, chainAdapters } from '../src/index'
import { InMemorySigner } from '@near-js/signers'
import { KeyPairSigner } from '@near-js/signers'
import { JsonRpcProvider } from '@near-js/providers'
import { Account, Connection } from '@near-js/accounts'
import { Account } from '@near-js/accounts'
import { Aptos, AptosConfig, Network } from '@aptos-labs/ts-sdk'
import { createAction } from '@near-wallet-selector/wallet-utils'
import { getTransactionLastResult } from '@near-js/utils'
Expand All @@ -17,14 +17,14 @@ async function main() {
// Create a signer from a private key string
const privateKey = (process.env.PRIVATE_KEY || 'ed25519:3D4YudUahN1HMqD5VvhE6RdcjbJGgMvRpMYhtKZhKVGG5FNFMRik2bLBmXvSjSznKvJLhxpxehVLrDLpFAqbsciH') as KeyPairString
const keyPair = KeyPair.fromString(privateKey)
const signer = await InMemorySigner.fromKeyPair('testnet', accountId, keyPair)
const signer = new KeyPairSigner(keyPair)

const provider = new JsonRpcProvider({
url: 'https://test.rpc.fastnear.com',
})

const connection = new Connection('testnet', provider, signer as any, accountId)
const account = new Account(connection, accountId)
// Use Account constructor (accountId, provider, signer)
const account = new Account(accountId, provider, signer)

const contract = new contracts.ChainSignatureContract({
networkId: 'testnet',
Expand Down Expand Up @@ -84,7 +84,7 @@ const signature = await contract.sign({
const results = []

for (const tx of walletSelectorTransactions) {
const actions = tx.actions.map((a) => createAction(a))
const actions = tx.actions

const result = await account.signAndSendTransaction({
receiverId: tx.receiverId,
Expand Down
4 changes: 2 additions & 2 deletions examples/send-btc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { contracts, chainAdapters } from 'chainsig.js'

import dotenv from 'dotenv'
import { KeyPairString } from '@near-js/crypto'
import { createAction } from '@near-wallet-selector/wallet-utils'


async function main() {
// Load environment variables
Expand Down Expand Up @@ -84,7 +84,7 @@ async function main() {
const transactions = walletSelectorTransactions.map((tx) => {
return {
receiverId: tx.receiverId,
actions: tx.actions.map((a) => createAction(a)),
actions: tx.actions,
} satisfies { receiverId: string; actions: Action[] }
})

Expand Down
4 changes: 2 additions & 2 deletions examples/send-eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Action } from '@near-js/transactions'
import { contracts, chainAdapters } from 'chainsig.js'
import { createPublicClient, http } from 'viem'
import { sepolia } from 'viem/chains'
import { createAction } from '@near-wallet-selector/wallet-utils'


import dotenv from 'dotenv'
import { KeyPairString } from '@near-js/crypto'
Expand Down Expand Up @@ -87,7 +87,7 @@ async function main() {
const transactions = walletSelectorTransactions.map((tx) => {
return {
receiverId: tx.receiverId,
actions: tx.actions.map((a) => createAction(a)),
actions: tx.actions,
} satisfies { receiverId: string; actions: Action[] }
})

Expand Down
4 changes: 2 additions & 2 deletions examples/send-sol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Action } from '@near-js/transactions'
import { contracts, chainAdapters } from 'chainsig.js'
import { createPublicClient, http } from 'viem'
import { sepolia } from 'viem/chains'
import { createAction } from '@near-wallet-selector/wallet-utils'


import { Connection as SolanaConnection } from '@solana/web3.js'

Expand Down Expand Up @@ -85,7 +85,7 @@ async function main() {
const transactions = walletSelectorTransactions.map((tx) => {
return {
receiverId: tx.receiverId,
actions: tx.actions.map((a) => createAction(a)),
actions: tx.actions,
} satisfies { receiverId: string; actions: Action[] }
})

Expand Down
12 changes: 6 additions & 6 deletions examples/send-sui.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Account, Connection } from '@near-js/accounts'
import { Account } from '@near-js/accounts'
import { contracts, chainAdapters } from '../src/index'
import { KeyPairString, KeyPair } from '@near-js/crypto'
import { JsonRpcProvider } from '@near-js/providers'
import { InMemorySigner } from '@near-js/signers'
import { KeyPairSigner } from '@near-js/signers'
import { getFullnodeUrl, SuiClient } from '@mysten/sui/client'
import { Transaction } from '@mysten/sui/transactions'
import { Action } from '@near-js/transactions'
Expand All @@ -19,14 +19,14 @@ async function main() {
// Create a signer from a private key string
const privateKey = (process.env.PRIVATE_KEY || 'ed25519:3D4YudUahN1HMqD5VvhE6RdcjbJGgMvRpMYhtKZhKVGG5FNFMRik2bLBmXvSjSznKvJLhxpxehVLrDLpFAqbsciH') as KeyPairString
const keyPair = KeyPair.fromString(privateKey)
const signer = await InMemorySigner.fromKeyPair('testnet', accountId, keyPair)
const signer = new KeyPairSigner(keyPair)

const provider = new JsonRpcProvider({
url: 'https://test.rpc.fastnear.com',
})

const connection = new Connection('testnet', provider, signer as any, accountId)
const account = new Account(connection, accountId)
// Use Account constructor (accountId, provider, signer)
const account = new Account(accountId, provider, signer)

const contract = new contracts.ChainSignatureContract({
networkId: 'testnet',
Expand Down Expand Up @@ -83,7 +83,7 @@ const signature = await contract.sign({
const results = []

for (const tx of walletSelectorTransactions) {
const actions = tx.actions.map((a) => createAction(a))
const actions = tx.actions

const result = await account.signAndSendTransaction({
receiverId: tx.receiverId,
Expand Down
4 changes: 2 additions & 2 deletions examples/send-xrp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { connect } from 'near-api-js'
import { getTransactionLastResult } from '@near-js/utils'
import { Action } from '@near-js/transactions'
import { contracts, chainAdapters } from 'chainsig.js'
import { createAction } from '@near-wallet-selector/wallet-utils'


import dotenv from 'dotenv'
import { KeyPairString } from '@near-js/crypto'
Expand Down Expand Up @@ -86,7 +86,7 @@ async function main() {
const transactions = walletSelectorTransactions.map((tx) => {
return {
receiverId: tx.receiverId,
actions: tx.actions.map((a) => createAction(a)),
actions: tx.actions,
} satisfies { receiverId: string; actions: Action[] }
})

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"typedoc": "^0.28.7",
"typescript": "^5.4.3",
"vitest": "^3.0.4",
"vocs": "1.0.0-alpha.62"
"vocs": "^1.0.13"
},
"dependencies": {
"@aptos-labs/ts-sdk": "^2.0.1",
Expand All @@ -117,14 +117,14 @@
"@cosmjs/proto-signing": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
"@mysten/sui": "^1.30.1",
"@near-js/accounts": "^1.4.1",
"@near-js/crypto": "^1.4.2",
"@near-js/keystores": "^0.2.2",
"@near-js/providers": "^1.0.3",
"@near-js/signers": "^0.1.1",
"@near-js/transactions": "^1.3.3",
"@near-js/types": "^0.3.1",
"@near-js/utils": "^1.1.0",
"@near-js/accounts": "^2.2.4",
"@near-js/crypto": "^2.2.4",
"@near-js/keystores": "^2.2.4",
"@near-js/providers": "^2.2.4",
"@near-js/signers": "^2.2.4",
"@near-js/transactions": "^2.2.4",
"@near-js/types": "^2.2.4",
"@near-js/utils": "^2.2.4",
"@near-wallet-selector/core": "^9.0.2",
"@noble/hashes": "^1.8.0",
"@scure/base": "^1.2.4",
Expand Down
35 changes: 21 additions & 14 deletions src/contracts/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Account, Connection } from '@near-js/accounts'
import { Account } from '@near-js/accounts'
import { KeyPair } from '@near-js/crypto'
import { InMemoryKeyStore } from '@near-js/keystores'
import { JsonRpcProvider, type Provider } from '@near-js/providers'
import { KeyPairSigner } from '@near-js/signers'

import { DONT_CARE_ACCOUNT_ID } from '@contracts/constants'

Expand All @@ -24,19 +26,24 @@ export const getNearAccount = async ({
const keyStore = new InMemoryKeyStore()
await keyStore.setKey(networkId, accountId, keypair)

const connection = Connection.fromConfig({
networkId,
provider: {
type: 'JsonRpcProvider',
args: {
url: {
testnet: 'https://rpc.testnet.near.org',
mainnet: 'https://rpc.mainnet.near.org',
}[networkId],
},
},
signer: { type: 'InMemorySigner', keyStore },
// Get the RPC URL for the network
const rpcUrl = {
testnet: 'https://rpc.testnet.near.org',
mainnet: 'https://rpc.mainnet.near.org',
}[networkId]

if (!rpcUrl) {
throw new Error(`Unsupported network: ${networkId}`)
}

// Create provider using new v2.0.0+ API
const provider = new JsonRpcProvider({
url: rpcUrl,
})

return new Account(connection, accountId)
// Create signer using new v2.0.0+ API
const signer = new KeyPairSigner(keypair)

// Use Account constructor (accountId, provider, signer)
return new Account(accountId, provider as Provider, signer)
}
Loading