Skip to content

Conversation

@GregProuty
Copy link
Collaborator

@GregProuty GregProuty commented Aug 15, 2025

feat(near): add NEAR adapter; consolidate to @near-js v2; update examples

  • Add NEAR adapter (prepare/serialize/finalize/broadcast) using @near-js/* v2
  • Add optional self-funding util: ensureDerivedAccountExists
  • Migrate NEAR internals to @near-js/* v2; remove near-api-js

Examples needed to be changed:

  • Avoid version-mismatch/runtime Borsh errors by unifying on @near-js/* v2
  • Remove duplicate deps (e.g., near-api-js, extra @solana/web3.js) to fix type conflicts
  • Standardize wallet-selector callback: build/sign/send NEAR FunctionCall via v2 provider
  • Pin versions in examples to ensure consistent behavior

private readonly contract: ChainSignatureContract
private readonly networkId: 'mainnet' | 'testnet'

constructor(args: { rpcUrl: string; networkId: 'mainnet' | 'testnet'; contract: ChainSignatureContract }) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all the other chains we take the provider directly, I would suggest to do the same (as providers might need API Keys)

const res = (await this.provider.query<any>(`account/${address}`, '')) as any
return { balance: BigInt(res.amount), decimals: 24 }
} catch (e) {
if (this.isAccountDoesNotExistError(e)) {
Copy link
Collaborator

@gagdiez gagdiez Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that this library in particular should not handle the isAccountDoesNotExistError, since by nature chainsig.js only handles getting signatures

Otherwise, the chains acts in one way for NEAR, and in a totally different for the other chains

Here we could either return 0 on error (which would make sense) or raise the error further app

async deriveAddressAndPublicKey(predecessor: string, path: string): Promise<{ address: string; publicKey: string }> {
const derivedKey = await this.contract.getDerivedPublicKey({ path, predecessor, IsEd25519: true })
const pk = NearPublicKey.fromString(derivedKey as string)
const derivedAccountId = `${path}.${predecessor}`
Copy link
Collaborator

@gagdiez gagdiez Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this look weird to me, since I would have expected the derived account to be:

  • either an implicit account
  • either ${predecessor} (always return predecessor indifferent to the path)

@GregProuty GregProuty closed this Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants