@1sat/templates 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export { default as OrdLock } from './ordlock/ordlock.js';
7
7
  export { default as Lock } from './lock/lock.js';
8
8
  export { default as Cosign } from './cosign/cosign.js';
9
9
  export type { CosignData } from './cosign/cosign.js';
10
+ export { default as P2MS } from './multisig/multisig.js';
11
+ export type { P2MSData } from './multisig/multisig.js';
10
12
  export { default as BitCom } from './bitcom/bitcom.js';
11
13
  export { default as AIP } from './bitcom/aip.js';
12
14
  export { default as B } from './bitcom/b.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC5D,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGzC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAA;AACtD,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAGpD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,OAAO,IAAI,CAAC,EAAE,MAAM,eAAe,CAAA;A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AAkB,EAClB,mBAAmB,GACnB,MAAM,iBAAiB,CAAA;AAKxB,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAKxD,YAAY,EACX,GAAG,EACH,SAAS,EACT,YAAY,EACZ,YAAY,GACZ,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAK1E,OAAO,EACN,iBAAiB,EACjB,cAAc,GACd,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EACX,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,cAAc,EACd,YAAY,EACZ,cAAc,GACd,MAAM,sBAAsB,CAAA"}
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export { default as BSV21 } from './bsv21/bsv21.js';
7
7
  export { default as OrdLock } from './ordlock/ordlock.js';
8
8
  export { default as Lock } from './lock/lock.js';
9
9
  export { default as Cosign } from './cosign/cosign.js';
10
+ export { default as P2MS } from './multisig/multisig.js';
10
11
  // BitCom Protocols
11
12
  export { default as BitCom } from './bitcom/bitcom.js';
12
13
  export { default as AIP } from './bitcom/aip.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG5D,mBAAmB;AACnB,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO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EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAM7D,OAAO,EACN,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,iBAAiB,CAAA;AAMxB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAWxD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE1E,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAC/E,OAAO,EACN,iBAAiB,EACjB,cAAc,GACd,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,132 @@
1
+ import { LockingScript, type PrivateKey, type Script, type Transaction, UnlockingScript, type WalletInterface, type WalletProtocol } from '@bsv/sdk';
2
+ /**
3
+ * P2MS decoded data structure
4
+ */
5
+ export interface P2MSData {
6
+ /** Compressed pubkeys (33-byte hex) in lock order */
7
+ pubKeys: string[];
8
+ /** Number of signatures required to spend (M) */
9
+ threshold: number;
10
+ /** Total number of pubkeys in the lock (N == pubKeys.length) */
11
+ total: number;
12
+ }
13
+ /**
14
+ * P2MS - Bare M-of-N multisig (OP_CHECKMULTISIG) template.
15
+ *
16
+ * Locking script:
17
+ * OP_<M> <pubKey1> <pubKey2> ... <pubKeyN> OP_<N> OP_CHECKMULTISIG
18
+ *
19
+ * Unlocking script (top of stack last):
20
+ * OP_0 <sig1+hashtype> <sig2+hashtype> ... <sigM+hashtype>
21
+ *
22
+ * The leading OP_0 compensates for OP_CHECKMULTISIG's off-by-one (it pops
23
+ * one extra item before processing).
24
+ *
25
+ * Multi-party signing happens externally to this template. Each party
26
+ * produces their own portion via {@link unlockSingle} or
27
+ * {@link unlockSingleWithWallet}. The coordinator collects portions keyed
28
+ * by signing pubkey and assembles the final unlock via {@link unlock}.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * // 2-of-3 lock
33
+ * const lock = P2MS.lock([pkA, pkB, pkC], 2)
34
+ *
35
+ * // Each approver produces their own portion (one per party):
36
+ * const portionA = await P2MS.unlockSingle(tx, inputIndex, keyA)
37
+ * const portionC = await P2MS.unlockSingle(tx, inputIndex, keyC)
38
+ *
39
+ * // Coordinator collects portions keyed by signing pubkey:
40
+ * const portions = new Map<string, UnlockingScript>()
41
+ * portions.set(pkA, portionA)
42
+ * portions.set(pkC, portionC)
43
+ *
44
+ * // Assemble — order is derived from the lock script on the input:
45
+ * const unlocker = P2MS.unlock(portions)
46
+ * tx.inputs[inputIndex].unlockingScriptTemplate = unlocker
47
+ * await tx.sign()
48
+ * ```
49
+ */
50
+ export default class P2MS {
51
+ /**
52
+ * Builds a P2MS locking script.
53
+ *
54
+ * @param pubKeys - Compressed pubkeys (33-byte hex) in lock order. This
55
+ * order matters for unlock — sigs are matched against pubkeys
56
+ * left-to-right by OP_CHECKMULTISIG.
57
+ * @param threshold - M, the number of signatures required to spend.
58
+ * @throws if `threshold` is out of range, `pubKeys.length` exceeds
59
+ * {@link MAX_PARTIES}, or any pubkey is not 33 bytes.
60
+ */
61
+ static lock(pubKeys: string[], threshold: number): LockingScript;
62
+ /**
63
+ * Decodes a pure P2MS locking script.
64
+ *
65
+ * Returns null if the script is not a pure P2MS pattern (no prefix
66
+ * data, no trailing chunks).
67
+ */
68
+ static decode(script: Script): P2MSData | null;
69
+ /** Returns true if the script is a pure P2MS pattern. */
70
+ static isP2MS(script: Script): boolean;
71
+ /**
72
+ * Produces this signer's portion of a P2MS unlock using a raw private
73
+ * key. The returned UnlockingScript contains a single push:
74
+ * `<sig+hashtype>`.
75
+ *
76
+ * The portion gets handed to the coordinator, which keys it by the
77
+ * signing pubkey and eventually combines it with the other portions
78
+ * via {@link unlock}.
79
+ *
80
+ * @param tx - The unsigned transaction.
81
+ * @param inputIndex - Index of the P2MS input being signed.
82
+ * @param privateKey - The signing key. Must correspond to one of the
83
+ * pubkeys in the lock.
84
+ * @param sighashType - SIGHASH_ALL | NONE | SINGLE (default 'all').
85
+ * @param anyoneCanPay - Whether SIGHASH_ANYONECANPAY is set.
86
+ * @param sourceSatoshis - Override for the source output amount.
87
+ * @param lockingScript - Override for the source output's locking script.
88
+ */
89
+ static unlockSingle(tx: Transaction, inputIndex: number, privateKey: PrivateKey, sighashType?: 'all' | 'none' | 'single', anyoneCanPay?: boolean, sourceSatoshis?: number, lockingScript?: Script): Promise<UnlockingScript>;
90
+ /**
91
+ * Produces this signer's portion of a P2MS unlock using a BRC-100
92
+ * wallet. The returned UnlockingScript contains a single push:
93
+ * `<sig+hashtype>`.
94
+ *
95
+ * The wallet's `protocolID` / `keyID` / `counterparty` triple
96
+ * determines which derived key signs. The same derivation must be used
97
+ * to register this party's pubkey in the lock script.
98
+ *
99
+ * @param tx - The unsigned transaction.
100
+ * @param inputIndex - Index of the P2MS input being signed.
101
+ * @param wallet - A BRC-100 WalletInterface.
102
+ * @param protocolID - Protocol ID for key derivation.
103
+ * @param keyID - Key ID for key derivation.
104
+ * @param counterparty - Counterparty for key derivation (default 'self').
105
+ * @param sighashType - SIGHASH_ALL | NONE | SINGLE (default 'all').
106
+ * @param anyoneCanPay - Whether SIGHASH_ANYONECANPAY is set.
107
+ * @param sourceSatoshis - Override for the source output amount.
108
+ * @param lockingScript - Override for the source output's locking script.
109
+ */
110
+ static unlockSingleWithWallet(tx: Transaction, inputIndex: number, wallet: WalletInterface, protocolID: WalletProtocol, keyID: string, counterparty?: string, sighashType?: 'all' | 'none' | 'single', anyoneCanPay?: boolean, sourceSatoshis?: number, lockingScript?: Script): Promise<UnlockingScript>;
111
+ /**
112
+ * Coordinator-side: assembles the full unlocking script from collected
113
+ * portions. Returns the standard ScriptTemplateUnlock shape so it can
114
+ * be plugged into `tx.inputs[i].unlockingScriptTemplate` and run
115
+ * through `tx.sign()` like any other template.
116
+ *
117
+ * `sign(tx, inputIndex)` reads the locking script from the input's
118
+ * sourceTransaction, decodes it, walks the pubkeys in order, and picks
119
+ * the first M portions present in the map. Throws if fewer than M
120
+ * matching portions are available.
121
+ *
122
+ * @param portionsByPubKey - Map keyed by the compressed signing pubkey
123
+ * (hex), each value being an UnlockingScript with a single
124
+ * `<sig+hashtype>` push as produced by {@link unlockSingle} or
125
+ * {@link unlockSingleWithWallet}.
126
+ */
127
+ static unlock(portionsByPubKey: Map<string, UnlockingScript>): {
128
+ sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
129
+ estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>;
130
+ };
131
+ }
132
+ //# sourceMappingURL=multisig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multisig.d.ts","sourceRoot":"","sources":["../../src/multisig/multisig.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,aAAa,EAEb,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,WAAW,EAEhB,eAAe,EAEf,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,MAAM,UAAU,CAAA;AAEjB;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,qDAAqD;IACrD,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAA;CACb;AA2GD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,OAAO,OAAO,IAAI;IACxB;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa;IAiChE;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI;IA6B9C,yDAAyD;IACzD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAItC;;;;;;;;;;;;;;;;;OAiBG;WACU,YAAY,CACxB,EAAE,EAAE,WAAW,EACf,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,UAAU,EACtB,WAAW,GAAE,KAAK,GAAG,MAAM,GAAG,QAAgB,EAC9C,YAAY,UAAQ,EACpB,cAAc,CAAC,EAAE,MAAM,EACvB,aAAa,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,eAAe,CAAC;IAqB3B;;;;;;;;;;;;;;;;;;;OAmBG;WACU,sBAAsB,CAClC,EAAE,EAAE,WAAW,EACf,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,cAAc,EAC1B,KAAK,EAAE,MAAM,EACb,YAAY,SAAS,EACrB,WAAW,GAAE,KAAK,GAAG,MAAM,GAAG,QAAgB,EAC9C,YAAY,UAAQ,EACpB,cAAc,CAAC,EAAE,MAAM,EACvB,aAAa,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,eAAe,CAAC;IA6B3B;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG;QAC9D,IAAI,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,CAAA;QACvE,cAAc,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;KACxE;CAkCD"}
@@ -0,0 +1,325 @@
1
+ import { Hash, LockingScript, OP, TransactionSignature, UnlockingScript, Utils, } from '@bsv/sdk';
2
+ /**
3
+ * Maximum N (and therefore maximum M) supported by this template, set by
4
+ * the single-byte OP_1..OP_16 encoding. Larger sets are valid in BSV
5
+ * consensus but require pushing the count as a script number; a trivial
6
+ * extension if ever needed.
7
+ */
8
+ const MAX_PARTIES = 16;
9
+ /** Returns the opcode byte for a small integer N in 1..16 (OP_1..OP_16). */
10
+ function opForN(n) {
11
+ if (n < 1 || n > MAX_PARTIES) {
12
+ throw new Error(`P2MS: integer ${n} out of OP_1..OP_${MAX_PARTIES} range`);
13
+ }
14
+ return OP.OP_1 + (n - 1);
15
+ }
16
+ /** Inverse of opForN — returns null for non-OP_1..OP_16 opcodes. */
17
+ function nForOp(op) {
18
+ if (op === undefined)
19
+ return null;
20
+ if (op >= OP.OP_1 && op <= OP.OP_16) {
21
+ return op - OP.OP_1 + 1;
22
+ }
23
+ return null;
24
+ }
25
+ /**
26
+ * Resolves the source output's locking script and satoshi amount for the
27
+ * input being signed, using overrides if provided and otherwise reaching
28
+ * into the input's sourceTransaction.
29
+ */
30
+ function resolveSourceContext(tx, inputIndex, sourceSatoshis, lockingScript) {
31
+ const input = tx.inputs[inputIndex];
32
+ const sourceTXID = input.sourceTXID ?? input.sourceTransaction?.id('hex');
33
+ if (!sourceTXID) {
34
+ throw new Error('P2MS: input sourceTXID or sourceTransaction is required for signing');
35
+ }
36
+ const resolvedSatoshis = sourceSatoshis ??
37
+ input.sourceTransaction?.outputs[input.sourceOutputIndex].satoshis;
38
+ if (resolvedSatoshis === undefined) {
39
+ throw new Error('P2MS: sourceSatoshis or input sourceTransaction is required for signing');
40
+ }
41
+ const resolvedLock = lockingScript ??
42
+ input.sourceTransaction?.outputs[input.sourceOutputIndex].lockingScript;
43
+ if (!resolvedLock) {
44
+ throw new Error('P2MS: lockingScript or input sourceTransaction is required for signing');
45
+ }
46
+ return {
47
+ sourceTXID,
48
+ sourceSatoshis: resolvedSatoshis,
49
+ lockingScript: resolvedLock,
50
+ };
51
+ }
52
+ /** Builds the sighash scope byte from the public sighash options. */
53
+ function buildSighashScope(sighashType, anyoneCanPay) {
54
+ let scope = TransactionSignature.SIGHASH_FORKID;
55
+ if (sighashType === 'all')
56
+ scope |= TransactionSignature.SIGHASH_ALL;
57
+ if (sighashType === 'none')
58
+ scope |= TransactionSignature.SIGHASH_NONE;
59
+ if (sighashType === 'single')
60
+ scope |= TransactionSignature.SIGHASH_SINGLE;
61
+ if (anyoneCanPay)
62
+ scope |= TransactionSignature.SIGHASH_ANYONECANPAY;
63
+ return scope;
64
+ }
65
+ /** Builds the sighash preimage for a P2MS input. */
66
+ function buildPreimage(tx, inputIndex, scope, sourceTXID, sourceSatoshis, subscript) {
67
+ const input = tx.inputs[inputIndex];
68
+ const otherInputs = tx.inputs.filter((_, i) => i !== inputIndex);
69
+ return TransactionSignature.format({
70
+ sourceTXID,
71
+ sourceOutputIndex: input.sourceOutputIndex,
72
+ sourceSatoshis,
73
+ transactionVersion: tx.version,
74
+ otherInputs,
75
+ inputIndex,
76
+ outputs: tx.outputs,
77
+ inputSequence: input.sequence ?? 0xffffffff,
78
+ subscript,
79
+ lockTime: tx.lockTime,
80
+ scope,
81
+ });
82
+ }
83
+ /**
84
+ * P2MS - Bare M-of-N multisig (OP_CHECKMULTISIG) template.
85
+ *
86
+ * Locking script:
87
+ * OP_<M> <pubKey1> <pubKey2> ... <pubKeyN> OP_<N> OP_CHECKMULTISIG
88
+ *
89
+ * Unlocking script (top of stack last):
90
+ * OP_0 <sig1+hashtype> <sig2+hashtype> ... <sigM+hashtype>
91
+ *
92
+ * The leading OP_0 compensates for OP_CHECKMULTISIG's off-by-one (it pops
93
+ * one extra item before processing).
94
+ *
95
+ * Multi-party signing happens externally to this template. Each party
96
+ * produces their own portion via {@link unlockSingle} or
97
+ * {@link unlockSingleWithWallet}. The coordinator collects portions keyed
98
+ * by signing pubkey and assembles the final unlock via {@link unlock}.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * // 2-of-3 lock
103
+ * const lock = P2MS.lock([pkA, pkB, pkC], 2)
104
+ *
105
+ * // Each approver produces their own portion (one per party):
106
+ * const portionA = await P2MS.unlockSingle(tx, inputIndex, keyA)
107
+ * const portionC = await P2MS.unlockSingle(tx, inputIndex, keyC)
108
+ *
109
+ * // Coordinator collects portions keyed by signing pubkey:
110
+ * const portions = new Map<string, UnlockingScript>()
111
+ * portions.set(pkA, portionA)
112
+ * portions.set(pkC, portionC)
113
+ *
114
+ * // Assemble — order is derived from the lock script on the input:
115
+ * const unlocker = P2MS.unlock(portions)
116
+ * tx.inputs[inputIndex].unlockingScriptTemplate = unlocker
117
+ * await tx.sign()
118
+ * ```
119
+ */
120
+ export default class P2MS {
121
+ /**
122
+ * Builds a P2MS locking script.
123
+ *
124
+ * @param pubKeys - Compressed pubkeys (33-byte hex) in lock order. This
125
+ * order matters for unlock — sigs are matched against pubkeys
126
+ * left-to-right by OP_CHECKMULTISIG.
127
+ * @param threshold - M, the number of signatures required to spend.
128
+ * @throws if `threshold` is out of range, `pubKeys.length` exceeds
129
+ * {@link MAX_PARTIES}, or any pubkey is not 33 bytes.
130
+ */
131
+ static lock(pubKeys, threshold) {
132
+ if (threshold < 1) {
133
+ throw new Error(`P2MS.lock: threshold must be >= 1 (got ${threshold})`);
134
+ }
135
+ if (pubKeys.length < threshold) {
136
+ throw new Error(`P2MS.lock: threshold ${threshold} exceeds pubkey count ${pubKeys.length}`);
137
+ }
138
+ if (pubKeys.length > MAX_PARTIES) {
139
+ throw new Error(`P2MS.lock: pubkey count ${pubKeys.length} exceeds maximum ${MAX_PARTIES}`);
140
+ }
141
+ const script = new LockingScript();
142
+ script.writeOpCode(opForN(threshold));
143
+ for (const pubKeyHex of pubKeys) {
144
+ const bytes = Utils.toArray(pubKeyHex, 'hex');
145
+ if (bytes.length !== 33) {
146
+ throw new Error(`P2MS.lock: invalid pubkey (expected 33-byte compressed, got ${bytes.length})`);
147
+ }
148
+ script.writeBin(bytes);
149
+ }
150
+ script.writeOpCode(opForN(pubKeys.length));
151
+ script.writeOpCode(OP.OP_CHECKMULTISIG);
152
+ return script;
153
+ }
154
+ /**
155
+ * Decodes a pure P2MS locking script.
156
+ *
157
+ * Returns null if the script is not a pure P2MS pattern (no prefix
158
+ * data, no trailing chunks).
159
+ */
160
+ static decode(script) {
161
+ try {
162
+ const chunks = script.chunks;
163
+ if (chunks.length < 4)
164
+ return null;
165
+ if (chunks[chunks.length - 1].op !== OP.OP_CHECKMULTISIG)
166
+ return null;
167
+ const total = nForOp(chunks[chunks.length - 2].op);
168
+ if (total === null)
169
+ return null;
170
+ if (chunks.length !== total + 3)
171
+ return null;
172
+ const pubKeys = [];
173
+ for (let i = 1; i <= total; i++) {
174
+ const c = chunks[i];
175
+ if (!c.data || c.data.length !== 33)
176
+ return null;
177
+ pubKeys.push(Utils.toHex(c.data));
178
+ }
179
+ const threshold = nForOp(chunks[0].op);
180
+ if (threshold === null)
181
+ return null;
182
+ if (threshold < 1 || threshold > total)
183
+ return null;
184
+ return { pubKeys, threshold, total };
185
+ }
186
+ catch {
187
+ return null;
188
+ }
189
+ }
190
+ /** Returns true if the script is a pure P2MS pattern. */
191
+ static isP2MS(script) {
192
+ return P2MS.decode(script) !== null;
193
+ }
194
+ /**
195
+ * Produces this signer's portion of a P2MS unlock using a raw private
196
+ * key. The returned UnlockingScript contains a single push:
197
+ * `<sig+hashtype>`.
198
+ *
199
+ * The portion gets handed to the coordinator, which keys it by the
200
+ * signing pubkey and eventually combines it with the other portions
201
+ * via {@link unlock}.
202
+ *
203
+ * @param tx - The unsigned transaction.
204
+ * @param inputIndex - Index of the P2MS input being signed.
205
+ * @param privateKey - The signing key. Must correspond to one of the
206
+ * pubkeys in the lock.
207
+ * @param sighashType - SIGHASH_ALL | NONE | SINGLE (default 'all').
208
+ * @param anyoneCanPay - Whether SIGHASH_ANYONECANPAY is set.
209
+ * @param sourceSatoshis - Override for the source output amount.
210
+ * @param lockingScript - Override for the source output's locking script.
211
+ */
212
+ static async unlockSingle(tx, inputIndex, privateKey, sighashType = 'all', anyoneCanPay = false, sourceSatoshis, lockingScript) {
213
+ const scope = buildSighashScope(sighashType, anyoneCanPay);
214
+ const ctx = resolveSourceContext(tx, inputIndex, sourceSatoshis, lockingScript);
215
+ const preimage = buildPreimage(tx, inputIndex, scope, ctx.sourceTXID, ctx.sourceSatoshis, ctx.lockingScript);
216
+ const sig = privateKey.sign(Hash.sha256(preimage));
217
+ const sigDER = sig.toDER();
218
+ return new UnlockingScript().writeBin([...sigDER, scope & 0xff]);
219
+ }
220
+ /**
221
+ * Produces this signer's portion of a P2MS unlock using a BRC-100
222
+ * wallet. The returned UnlockingScript contains a single push:
223
+ * `<sig+hashtype>`.
224
+ *
225
+ * The wallet's `protocolID` / `keyID` / `counterparty` triple
226
+ * determines which derived key signs. The same derivation must be used
227
+ * to register this party's pubkey in the lock script.
228
+ *
229
+ * @param tx - The unsigned transaction.
230
+ * @param inputIndex - Index of the P2MS input being signed.
231
+ * @param wallet - A BRC-100 WalletInterface.
232
+ * @param protocolID - Protocol ID for key derivation.
233
+ * @param keyID - Key ID for key derivation.
234
+ * @param counterparty - Counterparty for key derivation (default 'self').
235
+ * @param sighashType - SIGHASH_ALL | NONE | SINGLE (default 'all').
236
+ * @param anyoneCanPay - Whether SIGHASH_ANYONECANPAY is set.
237
+ * @param sourceSatoshis - Override for the source output amount.
238
+ * @param lockingScript - Override for the source output's locking script.
239
+ */
240
+ static async unlockSingleWithWallet(tx, inputIndex, wallet, protocolID, keyID, counterparty = 'self', sighashType = 'all', anyoneCanPay = false, sourceSatoshis, lockingScript) {
241
+ const scope = buildSighashScope(sighashType, anyoneCanPay);
242
+ const ctx = resolveSourceContext(tx, inputIndex, sourceSatoshis, lockingScript);
243
+ const preimage = buildPreimage(tx, inputIndex, scope, ctx.sourceTXID, ctx.sourceSatoshis, ctx.lockingScript);
244
+ const sighash = Hash.sha256(Hash.sha256(preimage));
245
+ const { signature } = await wallet.createSignature({
246
+ protocolID,
247
+ keyID,
248
+ counterparty,
249
+ hashToDirectlySign: Array.from(sighash),
250
+ });
251
+ return new UnlockingScript().writeBin([
252
+ ...Array.from(signature),
253
+ scope & 0xff,
254
+ ]);
255
+ }
256
+ /**
257
+ * Coordinator-side: assembles the full unlocking script from collected
258
+ * portions. Returns the standard ScriptTemplateUnlock shape so it can
259
+ * be plugged into `tx.inputs[i].unlockingScriptTemplate` and run
260
+ * through `tx.sign()` like any other template.
261
+ *
262
+ * `sign(tx, inputIndex)` reads the locking script from the input's
263
+ * sourceTransaction, decodes it, walks the pubkeys in order, and picks
264
+ * the first M portions present in the map. Throws if fewer than M
265
+ * matching portions are available.
266
+ *
267
+ * @param portionsByPubKey - Map keyed by the compressed signing pubkey
268
+ * (hex), each value being an UnlockingScript with a single
269
+ * `<sig+hashtype>` push as produced by {@link unlockSingle} or
270
+ * {@link unlockSingleWithWallet}.
271
+ */
272
+ static unlock(portionsByPubKey) {
273
+ return {
274
+ sign: async (tx, inputIndex) => {
275
+ const ordered = pickPortionsInLockOrder(tx, inputIndex, portionsByPubKey);
276
+ const out = new UnlockingScript().writeOpCode(OP.OP_0);
277
+ for (const portion of ordered) {
278
+ const chunk = portion.chunks[0];
279
+ if (!chunk?.data) {
280
+ throw new Error('P2MS.unlock: portion does not contain a single data push');
281
+ }
282
+ out.writeBin(Array.from(chunk.data));
283
+ }
284
+ return out;
285
+ },
286
+ estimateLength: async (tx, inputIndex) => {
287
+ const ordered = pickPortionsInLockOrder(tx, inputIndex, portionsByPubKey);
288
+ let len = 1; // OP_0
289
+ for (const portion of ordered) {
290
+ len += portion.toBinary().length;
291
+ }
292
+ return len;
293
+ },
294
+ };
295
+ }
296
+ }
297
+ /**
298
+ * Resolves the locking script on the input, decodes it as P2MS, and picks
299
+ * the first M portions from `portionsByPubKey` in lock pubkey order.
300
+ * Throws if the lock isn't P2MS or fewer than M portions are available.
301
+ */
302
+ function pickPortionsInLockOrder(tx, inputIndex, portionsByPubKey) {
303
+ const input = tx.inputs[inputIndex];
304
+ const lock = input.sourceTransaction?.outputs[input.sourceOutputIndex].lockingScript;
305
+ if (!lock) {
306
+ throw new Error('P2MS.unlock: input sourceTransaction is required to resolve the locking script');
307
+ }
308
+ const decoded = P2MS.decode(lock);
309
+ if (!decoded) {
310
+ throw new Error('P2MS.unlock: input locking script is not a P2MS pattern');
311
+ }
312
+ const ordered = [];
313
+ for (const pk of decoded.pubKeys) {
314
+ const portion = portionsByPubKey.get(pk);
315
+ if (portion)
316
+ ordered.push(portion);
317
+ if (ordered.length === decoded.threshold)
318
+ break;
319
+ }
320
+ if (ordered.length < decoded.threshold) {
321
+ throw new Error(`P2MS.unlock: insufficient portions (have ${ordered.length}, need ${decoded.threshold})`);
322
+ }
323
+ return ordered;
324
+ }
325
+ //# sourceMappingURL=multisig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multisig.js","sourceRoot":"","sources":["../../src/multisig/multisig.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,IAAI,EACJ,aAAa,EACb,EAAE,EAIF,oBAAoB,EACpB,eAAe,EACf,KAAK,GAGL,MAAM,UAAU,CAAA;AAcjB;;;;;GAKG;AACH,MAAM,WAAW,GAAG,EAAE,CAAA;AAEtB,4EAA4E;AAC5E,SAAS,MAAM,CAAC,CAAS;IACxB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,WAAW,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,oBAAoB,WAAW,QAAQ,CAAC,CAAA;IAC3E,CAAC;IACD,OAAO,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;AACzB,CAAC;AAED,oEAAoE;AACpE,SAAS,MAAM,CAAC,EAAsB;IACrC,IAAI,EAAE,KAAK,SAAS;QAAE,OAAO,IAAI,CAAA;IACjC,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC;QACrC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,CAAA;IACxB,CAAC;IACD,OAAO,IAAI,CAAA;AACZ,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAC5B,EAAe,EACf,UAAkB,EAClB,cAAkC,EAClC,aAAiC;IAEjC,MAAM,KAAK,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;IACnC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,iBAAiB,EAAE,EAAE,CAAC,KAAK,CAAC,CAAA;IACzE,IAAI,CA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,MAAM,IAAI,KAAK,CACd,gFAAgF,CAChF,CAAA;IACF,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACjC,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;IAC3E,CAAC;IACD,MAAM,OAAO,GAAsB,EAAE,CAAA;IACrC,KAAK,MAAM,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACxC,IAAI,OAAO;YAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClC,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,CAAC,SAAS;YAAE,MAAK;IAChD,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACd,4CAA4C,OAAO,CAAC,MAAM,UAAU,OAAO,CAAC,SAAS,GAAG,CACxF,CAAA;IACF,CAAC;IACD,OAAO,OAAO,CAAA;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/templates",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Bitcoin script templates for 1Sat Ordinals SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",