@enc-protocol/wdk-wallet-enc

0.2.2

ENC Protocol wallet module for Tether WDK

npm i @enc-protocol/wdk-wallet-enc

@enc-protocol/wdk-wallet-enc

ENC Protocol wallet module for Tether WDK. Registers ENC as a "blockchain" in WDK alongside EVM, BTC, TON, etc.

Install

npm install @enc-protocol/wdk-wallet-enc @tetherto/wdk

Usage

import WDK from '@tetherto/wdk'
import { WalletEvm } from '@tetherto/wdk-wallet-evm'
import { WalletEnc } from '@enc-protocol/wdk-wallet-enc'

const wdk = new WDK(seedPhrase)
wdk.register(new WalletEvm({ provider: rpcUrl }))
wdk.register(new WalletEnc({ nodeUrl: 'https://node.enc.dev' }))

// Same seed, two identities
const evm = await wdk.getAccount('evm')   // EVM address
const enc = await wdk.getAccount('enc')   // ENC identity

// ENC account
enc.getAddress()      // x-only pubkey hex (ENC identity)
enc.getEvmAddress()   // EVM address (same key, ECDSA)
enc.sign(message)     // Schnorr signature
enc.ecdh(theirPub)    // ECDH shared secret (DM encryption)
enc.keyPair           // { publicKey, privateKey } raw bytes

Key Derivation

Uses the same BIP-44 path as EVM: m/44'/60'/0'/0/{index}. The same 32-byte secp256k1 private key serves both:

  • EVM: ECDSA signing → Ethereum address
  • ENC: Schnorr signing → x-only pubkey (enclave identity)

Platforms

Works everywhere WDK works:

  • Node.js
  • React Native (iOS/Android)
  • Bare runtime

API

WalletManagerEnc

new WalletEnc({ nodeUrl, registryUrl })

Extends WalletManager. Registered via wdk.register().

WalletAccountEnc

MethodReturnsDescription
getAddress()stringx-only pubkey hex (64 chars)
getEvmAddress()stringEVM address from same key
sign(message)Uint8ArrayBIP-340 Schnorr signature
verify(message, sig)booleanVerify Schnorr signature
ecdh(theirPubHex)Uint8ArrayECDH shared secret
keyPair{ publicKey, privateKey }Raw key bytes
pubHexstringShorthand for x-only pubkey hex
dispose()voidSecurely wipe private key

Static

MethodDescription
WalletAccountEnc.encPubToEvmAddress(hex)Resolve x-only → [evenY, oddY] EVM candidates

Payment Middleware

Wraps EVM transfer() to automatically create encrypted DM messages with tx_hash when payments succeed.

import WDK from '@tetherto/wdk'
import { WalletEvm } from '@tetherto/wdk-wallet-evm'
import { WalletEnc, createPaymentMiddleware } from '@enc-protocol/wdk-wallet-enc'
import { DMSDK } from '@enc-protocol/dm'

const wdk = new WDK(seedPhrase)
wdk.register(new WalletEvm({ provider: rpcUrl }))
wdk.register(new WalletEnc({ nodeUrl }))

const enc = await wdk.getAccount('enc')
const dm = new DMSDK({ privateKey: enc.keyPair.privateKey, nodeUrl, registryUrl })

// Register middleware — wraps EVM transfers with DM notifications
wdk.registerMiddleware('ethereum', createPaymentMiddleware({
  dmSdk: dm,
  resolvePub: async (evmAddr) => {
    // Resolve EVM address → ENC pubkey via registry
    return registry.lookupByEvmAddress(evmAddr)
  },
  onCommit: (result) => console.log('DM sent:', result),
  onError: (err) => console.warn('DM failed (payment succeeded):', err),
}))

// Now any EVM transfer auto-creates a DM
const evm = await wdk.getAccount('evm')
await evm.transfer({
  token: 'USDT0',
  recipient: '0xBob...',
  amount: '10.00',
})
// → USDT0 sent on-chain
// → Encrypted DM "Sent 10.00 USDT0" with tx_hash auto-sent to Bob

Options:

OptionTypeDescription
dmSdkDMSDKInitialized DM SDK instance
resolvePub`async (evmAddr) => string \null`Resolve EVM address to ENC pubkey. If null, DM is skipped.
onCommitasync (result) => voidCalled after DM commit succeeds
onError(err) => voidCalled if DM fails (payment still succeeds)

Behavior: Payment is the primary action — if it fails, nothing happens. DM is best-effort: if the ENC commit fails, the payment still succeeds and the error is passed to onError. The user can retry the DM manually.