Repository navigation
Feat: build unsigned simple transactions - #6
Conversation
|
| Filename | Overview |
|---|---|
| src/provider.ts | Adds estimateTransactionFee method and normalizeNicksForRpc helper; changes sendTransaction return type to SendTransactionResponse; bigint normalization is correct and tested. |
| src/compat.ts | Adds SEND_TRANSACTION response mapping: normalizes legacy bare-string txid to { txid } for API 1 callers and strips back to bare txid for API 0 callers; defensive object-shape check handles pre-normalized responses correctly. |
| src/types.ts | Adds SendTransactionResponse, EstimateTransactionFeeRequest, EstimateTransactionFeeResponse; widens amount to NicksLike; makes fee optional with clear semantics in JSDoc. |
| src/constants.ts | Adds ESTIMATE_TRANSACTION_FEE: 'nock_estimateTransactionFee' constant; straightforward addition. |
| tests/provider-nicks.test.mjs | New regression tests covering bigint normalization, string/number passthrough, and omitted-fee handling; uses Node's built-in test runner, wired into CI. |
| .github/workflows/ci.yml | Adds npm test step after the example build to run the new regression suite in CI. |
| README.md | New README covering security model, compatibility notes, fee semantics, 0.3 migration guide, and trust-boundary documentation. |
Sequence Diagram
sequenceDiagram
participant dApp
participant NockchainProvider
participant InjectedWallet
Note over dApp,InjectedWallet: estimateTransactionFee (new, API 1 only)
dApp->>NockchainProvider: "estimateTransactionFee({ to, amount: 99n })"
NockchainProvider->>NockchainProvider: normalizeNicksForRpc(99n) → "99"
NockchainProvider->>InjectedWallet: "request({ method: nock_estimateTransactionFee, params: { to, amount: "99" } })"
InjectedWallet-->>NockchainProvider: "{ fee: "3" }"
NockchainProvider-->>dApp: "EstimateTransactionFeeResponse { fee: "3" }"
Note over dApp,InjectedWallet: sendTransaction — fee omitted (API 1)
dApp->>NockchainProvider: "sendTransaction({ to, amount: 42n })"
NockchainProvider->>NockchainProvider: normalizeNicksForRpc(42n) → "42"
NockchainProvider->>InjectedWallet: "request({ method: nock_sendTransaction, params: { to, amount: "42" } })"
InjectedWallet-->>NockchainProvider: "{ txid, amount, fee }"
NockchainProvider-->>dApp: "SendTransactionResponse { txid, amount?, fee? }"
Note over dApp,InjectedWallet: compat bridge: API 1 caller → legacy API 0 wallet
dApp->>NockchainProvider: sendTransaction(...)
NockchainProvider->>InjectedWallet: request (via requestBridge, fee omitted from params if absent)
InjectedWallet-->>NockchainProvider: "bare-txid-string"
NockchainProvider->>NockchainProvider: "mapResponse(!fromV1 → toV1): wrap → { txid }"
NockchainProvider-->>dApp: "SendTransactionResponse { txid }"
Reviews (2): Last reviewed commit: "fix: normalize bigint RPC inputs" | Re-trigger Greptile
Mirror the type-coercion note from SendTransactionRequest.amount so the two parallel interfaces document the same accepted runtime types (legacy number + canonical string/bigint). Addresses review feedback on PR #6.
Adds a public, read-only provider method so dApps can query the
required network fee for a simple send without duplicating wallet/WASM
transaction-building logic:
- PROVIDER_METHODS.ESTIMATE_TRANSACTION_FEE ('nock_estimateTransactionFee')
- EstimateTransactionFeeRequest / EstimateTransactionFeeResponse types
- NockchainProvider.estimateTransactionFee({ to, amount }) -> { fee }
(fee in nicks, canonical string)
Also documents the optional-fee semantics on SendTransactionRequest:
when fee is omitted the wallet estimates it for the approval popup,
auto-calculates the exact fee at build time, and reports the actual
fee used in the response.
The method is API 1-only; compat v0 mapping passes it through untouched
(default case), which is intentional.
Mirror the type-coercion note from SendTransactionRequest.amount so the two parallel interfaces document the same accepted runtime types (legacy number + canonical string/bigint). Addresses review feedback on PR #6.
d21922b to
e2bffef
Compare
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Summary
nock_buildSimpleTransactionprovider primitive. It returns the exact unsigned V1NockchainTx, selected native input-note sidecars, projected outputs, a witness-independentintentId, and canonical amount/fee/change metadata.estimateTransactionFee()as deprecated SDK convenience sugar overbuildSimpleTransaction(); there is no separate fee-estimation wire method.sendTransaction.feeto be omitted. Explicit fees remain exact overrides; omitted fees are calculated by the wallet.sendTransaction()to return the API 1 runtime object{ txid, amount, fee }instead of the inaccuratestringtype.{ txid }for API 1 callers, while preserving the bare-ID response for callers bridged back to API 0.bigintnicks inputs, normalizing bigint values before Chrome messaging.Security and lifecycle contract
intentIdis derived from the witnessless spends and remains stable across signing; callers must not bind approval to the unsigned raw transaction ID because signatures change it.notesare compatibility/inspection sidecars, not trusted signing authority. A wallet must resolve the transaction's committed input names against its own state.feeis the actual fee encoded in the transaction (curFee);minimumFeeis the independently calculated minimum (calcFee). Explicit fees below the minimum are rejected.Dependency status
#7 is merged and this branch is based on the resulting
iris-sdk/main.Do not merge or publish SDK 0.3.0 from this head yet. After
@nockbox/iris-wasm@0.2.1is published from the coordinatediris-rswork, update the SDK's exact WASM dependency from 0.2.0 to 0.2.1, regenerate the lockfile, and rerun validation on that final dependency graph.Compatibility
sendTransaction({ to, amount, fee? })request shapes and explicit-fee semantics are preserved.amountand actualfee; these fields remain optional only when bridging a legacy API 0 wallet that historically returned only a transaction ID.buildSimpleTransactionwas introduced with API 1. Compatibility mapping passes the method through unchanged; older wallets may return their normal method-not-found error.estimateTransactionFee()remains available as a deprecated SDK helper and now callsbuildSimpleTransaction().sendTransaction()is typed as returning an object rather thanstring; callers that used the result directly as a transaction ID must readresult.txid.Validation
Development-only Vite/PostCSS/esbuild advisories remain outside the shipped runtime dependency set; a major Vite upgrade is intentionally outside this focused change.