Skip to content

Add msig:propose-updateauth for WA keys under multisig - #46

Merged
pbatmetal merged 8 commits into
XPRNetwork:masterfrom
blasrodri:feature/msig-propose-updateauth-wa
Oct 28, 2026
Merged

pbatmetal merged 8 commits into
XPRNetwork:masterfrom
blasrodri:feature/msig-propose-updateauth-wa

Conversation

@blasrodri

@blasrodri blasrodri commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Follows up on #45, which added generic multisig lifecycle commands but no dedicated flow for the reported WebAuthn-under-multisig updateauth case (Explorer /wallet/msig rejects PUB_WA_ with base-58/checksum errors, and there is no CLI path for it).

What this adds:

  • New msig:propose-updateauth command wrapping eosio::updateauth in an eosio.msig propose, reusing the Add multisig actions and tests #45 propose flow (serialize, required-accounts resolution, deterministic requested sorting).
  • Early key validation with Numeric.stringToPublicKey, so undecodable keys fail fast instead of a UI cache error.
  • Threshold/total-weight checks, owner parent handling (empty parent), and chain-order authority sorting including WA keys.
  • Maintained tests: unit suite for the builder plus command-level coverage. README command reference updated.

Scope notes:

  • Canonical authority sorting in sortRequiredAuth also applies to the existing permission and contract:enableinline save paths; regression tests now cover both.
  • Keys/accounts must meet --threshold without waits. Authorities that delay alone could satisfy are intentionally rejected.
  • Parent/account/expiry checks use chain state at propose time; state can change before eosio.msig::exec, so an approved proposal can still fail at exec.

Verification:

  • tsc --noEmit clean; ESLint clean on touched files.
  • Node v23.11.0 (repo .nvmrc): 80 mocha tests passing across the loadable suites (updateauth/msig utils, msig:propose-updateauth, contract:enableinline, permission, msig, network).
  • Docker Leap localnet: bootstrapped eosio.boot/bios/msig, created a new trading permission authorized by its parent active, then proposed/approved/executed an updateauth replacing active and read the result back from chain state.

Example ( victorcrisan shape, threshold-1 WA active ):
proton msig:propose-updateauth waprop victorcrisan ruter1@active --threshold 1 --keys PUB_WA_...

New msig:propose-updateauth wraps eosio::updateauth in an eosio.msig propose, with early PUB_WA_/PUB_K1_/PUB_R1_ validation, threshold/weight checks, and chain-order sorting. Covers the WebAuthn-under-multisig case PR XPRNetwork#45 left without a dedicated flow.
Validate the permission side of --accounts entries, accept 13-character EOSIO names with a restricted final character, and pin the key-sort test to an explicit order.
Comment thread src/utils/updateauth.ts Outdated
})
}

export const buildUpdateauthAuth = (options: {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it intentional to have the word auth twice here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not really!

buildUpdateauthAuth -> buildRequiredAuth

Thanks :)

buildUpdateauthAuth -> buildRequiredAuth (matches RpcInterfaces.RequiredAuth return type); buildUpdateauthAction -> buildUpdateAuthAction (camelCase fix). Update caller and tests.

@squdgy squdgy left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Static review of head 7c770ce (read from the diff and the helpers it calls; tests and the CLI were not run).

Blocking: bugs in src/utils/sortRequiredAuth.ts (not in this diff, but buildRequiredAuth calls it on every proposal)

  1. Crash with 2+ waits (sortRequiredAuth.ts:26): a.wait_sec.localeCompare(b.wait_sec) is called on numbers (parseWaitWeights returns wait_sec: Number(...)). --waits 86400,3600:2 should throw TypeError: a.wait_sec.localeCompare is not a function. The any annotation hides it from tsc. With 0 or 1 waits the comparator never runs, which is why no test hits it. Even if it ran on strings, '10000' would sort before '9'; it needs a numeric compare.
  2. Accounts sorted by actor only (sortRequiredAuth.ts:25): --accounts a@owner,a@active has equal actors, so input order is kept. As I understand it the chain wants (actor, permission) order, so updateauth would be rejected at exec time, after approvals are collected. localeCompare is also not EOSIO name order; this PR's own compareNames is the right comparator.
  3. Keys fall back to localeCompare on the base58 string (sortRequiredAuth.ts:49): only WA-vs-WA pairs are compared bytewise. K1/R1 pairs and mixed K1/WA pairs use locale string order, which is not the chain's (type, bytes) order. sorts keys deterministically only uses two K1 keys that differ in the first character, so it can't catch this.

Points 2 and 3 are from my knowledge of EOSIO canonical-form rules and were not checked against a node. Point 1 follows directly from the code.

Other

  • isPositiveInteger (src/utils/integer.ts:1) accepts '0' (n >= 0), so --waits 0 is accepted. Also see the inline comment on range limits.
  • Test coverage: nothing exercises multiple waits, mixed K1/WA keys, several permissions for one actor, or duplicates through buildRequiredAuth (inline comment on the test file). These are the cases that break the sorting.

Inline comments below cover the lines that are in this diff.

Comment thread src/utils/updateauth.ts Outdated
throw new Error(`--threshold ${threshold} exceeds total weight ${total}`)
}

const auth: RpcInterfaces.RequiredAuth = {threshold, keys, accounts, waits}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No duplicate or range validation before the authority is built. --keys K,K, --accounts a@active,a@active, a weight above 65535 (uint16), or a threshold/wait above 2^32-1 all pass here and, as I understand the chain rules, fail only when eosio.msig::exec runs, after approvals are collected. Suggest rejecting duplicates and out-of-range values here. (Chain-side limits not verified against a node.)

Comment thread src/utils/updateauth.ts Outdated
const seconds = separator === -1 ? entry : entry.slice(0, separator)
const weight = separator === -1 ? 1 : parseWeight(entry, entry.slice(separator + 1), argument)

if (!isPositiveInteger(seconds)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

isPositiveInteger returns true for '0' (it checks n >= 0), so --waits 0 yields wait_sec: 0, and the error text says "positive integer". parseWeight already guards this with Number(value) < 1; do the same here. A value above the uint32 range also passes.

Comment thread src/utils/updateauth.ts

parent = ''
} else {
parent = parent === undefined || parent === '' ? 'owner' : parent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When --parent is omitted, any non-owner permission is parented to owner. For an existing custom permission such as trading (parent active), this silently reparents it and changes who can act on it. Either look up the current parent via the chain API and default to that, or require --parent for anything other than active.

Comment thread src/utils/updateauth.ts Outdated
return {
account: 'eosio',
name: 'updateauth',
authorization: [{actor: account, permission}],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Question, not verified: the action is authorized by account@permission (the permission being changed). For a brand-new permission, getRequiredAccounts(account, 'newperm') in the command cannot resolve and throws "could not resolve required accounts" for what may be a valid operation. If chain rules want the parent's (or an existing permission's) authority here, the signer set in requested may also differ from what the chain demands. Worth confirming against a node, with a test for a new permission.

Comment thread src/commands/msig/propose-updateauth.ts Outdated
async run(): Promise<void> {
const {args, flags: commandFlags} = this.parse(MultisigProposeUpdateauth)
const authorization = parseAuthorization(args.auth)
const permission = commandFlags.permission || 'active'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

commandFlags.permission || 'active' turns an empty --permission (e.g. --permission "$PERM" with an unset variable) into active, silently rewriting the wrong permission. Only default when the flag is undefined and reject an empty string. The help text also describes defaults that oclif doesn't apply.

accounts: commandFlags.accounts as string | undefined,
waits: commandFlags.waits as string | undefined,
})
const updateAuthAction = buildUpdateAuthAction({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This builds a proposal that can replace owner or active with no diff of old vs new authority, no warning, and no check that the new key set can satisfy the threshold on its own. A mistyped but valid key becomes permanent lockout once approved and executed. Suggest printing the authority being replaced and the new one, and requiring an explicit confirm flag (e.g. --yes) when --permission owner is used. This is an irreversible account-control change, so it should also go through your compliance/infosec review path.

0,
)

// Find required signers

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This required-signer resolution (and the compareNames-based sort below) duplicates the body of msig:propose, and propose.ts keeps its own private compareNames while utils/updateauth.ts now exports a second copy. A future fix to signer resolution or ordering would have to be made twice, in a signer-selection path. Suggest a shared helper in utils/multisig.ts taking parsedActions, used by both commands.

.catch((error: Error & {oclif?: {exit?: number}}) => {
expect(error.oclif?.exit).to.equal(1)
})
.it('exits non-zero when the proposal fails')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

exits non-zero when the proposal fails is the same command as rejects empty authorities and passes because validation throws, not because a proposal failed. Nothing covers a rejecting network.transact or getRequiredAccounts (including the empty-required-accounts error). Stub one of those to reject and assert the exit code and message.

assert.deepEqual(requiredAuth.waits, [])
})

it('sorts keys deterministically', () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Coverage gap: no test sends multiple waits, mixed K1/WA keys, several permissions for one actor, or duplicates through buildRequiredAuth. parseWaitWeights is only tested on its own, so its output is never sorted in a test, which is how the localeCompare crash on wait_sec goes unnoticed. Add those cases (they should fail today).

…fer parent and auth defaults

Fix waits crash (numeric compare), sort accounts by (actor, permission) and keys by (type, bytes) with compareNames. Reject weights above uint16, delays and thresholds above uint32, zero waits, and duplicate keys, accounts, and waits. Require explicit --parent for custom permissions and default to the on-chain parent otherwise. Authorize new permissions with the parent authority, require --yes to replace owner, reject empty --permission, print old and proposed authorities, and share signer resolution between msig:propose and msig:propose-updateauth. Cover all of it with tests and sync the README flags.
…ecode-once key sort

Validate proposal name, account, permission, and authorization before any chain call. Reject a parent permission that does not exist on the account. Make the new-permission authorization rule explicit via buildUpdateAuthAction actionPermission instead of mutating the built action. Decode authority keys once when sorting instead of per comparison. Rename argument parameters to flagName/label and validName to isValidEosioName. Add tests for all of it.
Match Leap updateauth rules: canonical EOSIO names without trailing-dot aliases, reserved eosio. permissions, immutable parents, active parent owner, existing account authorities, chain maximum delay, the 2^16 authority entry cap, and field-wise WebAuthn key ordering. Reject waits-only satisfaction, self-referential and otherwise invalid direct authorities, and malformed WebAuthn payloads without echoing mistakenly supplied private keys. Dedupe and validate multisig approver resolution, add ABI serialization coverage, and rename sortRequiredAuth to kebab case so touched files pass lint.
@blasrodri

Copy link
Copy Markdown
Contributor Author

@squdgy Thanks for the careful review. I fixed the sorting and validation issues, tightened the parent/owner handling, and added tests for the cases you called out. PTAL.

@squdgy squdgy left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Follow-up review of head 12bc245. The three new commits resolve all nine points from my previous review (numeric wait sort, (actor, permission) account order, type-then-bytes key order, duplicate/range checks, --waits 0, explicit/existing parent, --yes for owner, empty --permission, shared resolveRequestedApprovers, real failing-transact test). I checked these in the code.

What I ran

  • tsc --noEmit: no errors.
  • test/updateauth-utils.test.ts and test/msig-utils.test.ts: 38 passing.
  • Not verified: the oclif command tests (test/commands/msig-propose-updateauth.test.ts), npm test coverage and the eslint posttest. Every oclif test file fails to load in my environment (TypeError: Cannot read properties of undefined (reading 'filename') from @oclif/test, Node v24.16.0), and it does the same on master, so this looks environmental, but please confirm in CI.

On the EOSIO rule that updateauth is authorized by the existing permission, or by the parent when the permission is new: that matches my recollection of the chain source, but I did not verify it against a node.

Remaining items are inline. Only the first needs action before merge, in my view.

}
}

export const sortRequiredAuth = (auth: RpcInterfaces.RequiredAuth): void => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Scope note: sortRequiredAuth is also used by permission and contract:enableinline (their imports are renamed in this PR). Their behaviour changes: WA keys are now compared by RP ID bytes instead of localeCompare, key order is now type-then-bytes, and an undecodable key now throws from Numeric.stringToPublicKey instead of being string-compared. The new order is more correct, but neither command has a test, and the PR description doesn't mention it. Suggest a regression test for each command's sort path and a line in the description.

Comment thread src/commands/msig/propose-updateauth.ts Outdated

try {
return [actor, await network.rpc.get_account(actor)] as const
} catch {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This bare catch reports any get_account failure as account "x" does not exist. A node outage, timeout or rate limit would send the user hunting for a typo. Only map a genuine not-found response to this message and rethrow anything else, and add a test that stubs a non-not-found rejection.


// A parent that does not exist would only fail at exec, after approvals
// are collected. Reject it now while the chain state is in hand.
if (parent !== undefined && parent !== '' && !onChain.permissions.some(entry => entry.perm_name === parent)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Low: the parent, account, permission and max-delay checks are a snapshot of chain state at propose time. Approvals can take up to expireSeconds (default 7 days), and the state can change before eosio.msig::exec, so a proposal that validates now can still fail at exec. Worth a sentence in the command description or help text.

Comment thread src/utils/updateauth.ts
throw new Error(`${labels.threshold} ${auth.threshold} exceeds total weight ${total}`)
}

const principalWeight = [...auth.keys, ...auth.accounts].reduce((sum, entry) => sum + entry.weight, 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Low: rejecting authorities that waits alone could satisfy is stricter than the chain requires. It is a sensible safety rule, but it is a policy choice and is not mentioned in the flag help or the PR description. Document it so it isn't a surprise to users who intentionally build delay-based permissions.

Add save-path regression tests for permission and contract:enableinline now that they share canonical authority sorting. Only map genuine account-not-found RPC failures to the missing-account message, document the propose-time chain snapshot caveat, and state the waits-alone threshold policy in help and README.
@blasrodri

Copy link
Copy Markdown
Contributor Author

@squdgy pushed fixes for the four remaining items: sort regression tests for permission/enableinline, RPC timeout handling + test, and help/PR notes for the snapshot caveat and waits policy. 80 passing locally on Node 23.11; tsc/eslint clean. PTAL.

@squdgy squdgy left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code changes look good to me. @blasrodri How do we test this on testnet before publishing to npm?

@blasrodri

blasrodri commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Code changes look good to me. @blasrodri How do we test this on testnet before publishing to npm?

Tested the msig:propose-updateauth branch end-to-end on proton-test with account msigtest1111
(https://testnet.explorer.xprnetwork.org/account/msigtest1111) (created fresh for this). Zero proposals
left pending, owner untouched throughout.

Happy paths (propose → approve → exec, all verified on-chain):

• New permission, 1 K1 key → testperm11 — tx 8598edc3
(https://testnet.explorer.xprnetwork.org/tx/8598edc318f2f6ad21679b224e1bd77bdcd8a7c4b99eb6d4101c817d46ceb1ae?tab=traces)
• Update existing active to 2 keys, canonical sort confirmed — tx 625e5b48
(https://testnet.explorer.xprnetwork.org/tx/625e5b481e5516716124fa2e24aeb4e70a21281ce271b10407dbfe6edf99146b?tab=traces)
• Keys + account + 60s wait, threshold 2 → testperm12 — tx b69cf2d7
(https://testnet.explorer.xprnetwork.org/tx/b69cf2d76cb426a330f04fac2b096c42fa0862aa0746da903c7b3dafd9857436?tab=traces)
• Weighted keys 2+1, threshold 3 → testperm13 — tx 774aa4e5
(https://testnet.explorer.xprnetwork.org/tx/774aa4e5666074fd330b035676ee15e2a07918dbab7e3ca79a24a6c34da92b47?tab=traces)
• Non-active account authority (msigtest1111@testperm11) → testperm21 — tx 3247915d
(https://testnet.explorer.xprnetwork.org/tx/3247915db1385310c17823327f1dd082a09f7d619a6a79c69c65ee629e57348e?tab=traces)
• WebAuthn key → testperm23 live with PUB_WA_ key — tx cb616658
(https://testnet.explorer.xprnetwork.org/tx/cb61665809446773add0e1568e864e49028dbf3ae2b8a8b3e4f31ddac7ca602a?tab=traces) (fixture key; CLI only carries WA keys as authority data, never signs as them)
• Bare account auth defaults to @Active — tx f4ac261c
(https://testnet.explorer.xprnetwork.org/tx/f4ac261cb3371dac427ef7215e0146b60d04c9660a0219c08a08a39377989e2f?tab=traces)
• Approve → unapprove → exec fails → re-approve → exec — tx cd8f2b5e
(https://testnet.explorer.xprnetwork.org/tx/cd8f2b5ecd95ceb4bc8d29adb41d280c8e8e87632ae8707154a4517454e58e19?tab=traces)
• Exec with no approval fails, then approve + exec — tx b0b6af94
(https://testnet.explorer.xprnetwork.org/tx/b0b6af9450859427c4425cd0cfc759c0ce5bdc7b827808f577860f9a80f7f214?tab=traces)
• Owner change with --yes proposed, then cancelled unapproved — owner untouched

Negative paths (all rejected client-side, nothing touched chain): bad proposal name, nonexistent parent,
changing an existing permission's parent, unknown --accounts permission, wait over chain max (3888000s),
duplicate key / duplicate wait, threshold 0, weight 0, wait 0, empty authority, waits-only authority,
threshold exceeding total weight, invalid key (value not echoed), eosio.* reserved permission, owner
without --yes. Plus: exec for a permission whose key you don't hold fails with
transaction authorization failed, and msig:cancel cleans up.

@pbatmetal
pbatmetal requested a review from andreyjamer October 27, 2026 19:35
@paulgnz

paulgnz commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Thanks for this. Nice work, especially the canonical authority sorting. I reviewed it and checked a few things against a live chain using only read RPCs (nothing signed or broadcast).

Bug: --waits has no effect, and the usual key + delay setup is rejected

src/utils/updateauth.ts (the principalWeight < auth.threshold check) rejects any authority where keys and accounts together weigh less than the threshold. If keys and accounts already meet the threshold, a wait can never change whether the authority is satisfied, so --waits does nothing. The normal use of waits, which nodeos accepts because validate() only requires total_weight >= threshold, is refused:

proton msig:propose-updateauth p acct a@active --threshold 2 --keys PUB_K1_…:1 --waits 86400:1
→ keys and accounts must provide at least the threshold weight; waits alone must not satisfy an authority

The PR description says the goal is to reject authorities that a delay alone could satisfy. That check would be waitWeight >= threshold, which is much narrower than the current one.

Tests don't exercise real serialization

msig-propose-updateauth.test.ts replaces serializeActions with an identity stub and also stubs transact. The stubbed generateTransactionSettings returns only 3 header fields, so real serialization would fail with missing transaction.max_net_usage_words. I checked the real path separately and it works: I wrapped eosio.token::transfer, eosio::updateauth (2×K1 + 2×WA keys, an account, a wait) and buyrambytes in a propose, serialized it, deserialized it, and compared. The data came back identical, including through Api.transact({sign:false, broadcast:false}). An integration test without stubs, using a mocked RPC, would catch future breakage there.

Things I verified that look right

  • Key ordering matches fc's public_key::operator< (variant index, then key bytes; for WA keys: key bytes, then presence, then rpid as a string, not the length-prefixed serialized form). The rpid test covers that.
  • compareNames agrees with uint64 name ordering: 0 mismatches across 200k random name pairs.
  • The new sorting also fixes the existing permission and contract:enableinline save paths. The old code sorted accounts by actor only, sorted K1 keys by their base58 string, and called localeCompare on numeric wait_sec, which throws when an authority has 2 or more waits.

Minor limitation: the inner updateauth for an existing permission is always authorized as account@<permission>. There's no option to authorize it through the parent (owner), even though the chain allows that.

@pbatmetal
pbatmetal merged commit 89277b8 into XPRNetwork:master Oct 28, 2026
@blasrodri
blasrodri deleted the feature/msig-propose-updateauth-wa branch October 28, 2026 19:41
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.

5 participants