live · mainnetoc · docs
specs · api · guides
docs / documentation

@orangecheck/pledge-core


@orangecheck/pledge-core / wrapPledgeEnvelope

Function: wrapPledgeEnvelope()

function wrapPledgeEnvelope(
   input: PledgeCanonicalInput, 
   sigValue: string, 
   opts?: {
  sigPubkey?: string;
  viaDelegation?: {
     agentAddress: string;
     delegationId: string;
  };
}): PledgeEnvelope;

Defined in: pledge-core/src/pledge.ts:146

Build a pledge envelope from a canonical input + an externally-obtained BIP-322 signature. Companion to createPledge for callers who sign outside the SDK — typically web apps that use a wallet-extension's signMessage API directly rather than wrapping it as a Bip322Signer.

The caller is responsible for:

  • Producing sigValue over the lowercase-hex pledge id (SPEC §3.5). Compute the id via computePledgeId(input) first; pass that exact hex string to the wallet's signMessage.
  • Identifying which address signed (sigPubkey). For non-agent pledges this MUST equal input.swearer. For agent pledges (viaDelegation set), sigPubkey SHOULD equal viaDelegation.agentAddress since that's the cryptographic signer; verifiers under SPEC §7.3 use agent_address from the envelope as the BIP-322 verification key regardless of what's in sig.pubkey.

Throws PledgeError if the canonical input is invalid (same gates as createPledge).

Parameters

ParameterType
inputPledgeCanonicalInput
sigValuestring
opts?{ sigPubkey?: string; viaDelegation?: { agentAddress: string; delegationId: string; }; }
opts.sigPubkey?string
opts.viaDelegation?{ agentAddress: string; delegationId: string; }
opts.viaDelegation.agentAddress?string
opts.viaDelegation.delegationId?string

Returns

PledgeEnvelope