@bsv/sdk 1.1.24 → 1.1.26
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/cjs/package.json +1 -1
- package/dist/cjs/src/totp/totp.js +1 -1
- package/dist/cjs/src/totp/totp.js.map +1 -1
- package/dist/cjs/src/transaction/Beef.js +492 -0
- package/dist/cjs/src/transaction/Beef.js.map +1 -0
- package/dist/cjs/src/transaction/BeefParty.js +97 -0
- package/dist/cjs/src/transaction/BeefParty.js.map +1 -0
- package/dist/cjs/src/transaction/BeefTx.js +123 -0
- package/dist/cjs/src/transaction/BeefTx.js.map +1 -0
- package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
- package/dist/cjs/src/transaction/Transaction.js +156 -35
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/src/transaction/index.js +7 -1
- package/dist/cjs/src/transaction/index.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/totp/totp.js +1 -1
- package/dist/esm/src/totp/totp.js.map +1 -1
- package/dist/esm/src/transaction/Beef.js +485 -0
- package/dist/esm/src/transaction/Beef.js.map +1 -0
- package/dist/esm/src/transaction/BeefParty.js +93 -0
- package/dist/esm/src/transaction/BeefParty.js.map +1 -0
- package/dist/esm/src/transaction/BeefTx.js +121 -0
- package/dist/esm/src/transaction/BeefTx.js.map +1 -0
- package/dist/esm/src/transaction/MerklePath.js.map +1 -1
- package/dist/esm/src/transaction/Transaction.js +156 -35
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/src/transaction/index.js +3 -0
- package/dist/esm/src/transaction/index.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/transaction/Beef.d.ts +143 -0
- package/dist/types/src/transaction/Beef.d.ts.map +1 -0
- package/dist/types/src/transaction/BeefParty.d.ts +62 -0
- package/dist/types/src/transaction/BeefParty.d.ts.map +1 -0
- package/dist/types/src/transaction/BeefTx.d.ts +35 -0
- package/dist/types/src/transaction/BeefTx.d.ts.map +1 -0
- package/dist/types/src/transaction/MerklePath.d.ts.map +1 -1
- package/dist/types/src/transaction/Transaction.d.ts +44 -4
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
- package/dist/types/src/transaction/index.d.ts +3 -0
- package/dist/types/src/transaction/index.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/docs/primitives.md +372 -55
- package/docs/transaction.md +531 -5
- package/package.json +1 -1
- package/src/totp/totp.ts +1 -1
- package/src/transaction/Beef.ts +533 -0
- package/src/transaction/BeefParty.ts +100 -0
- package/src/transaction/BeefTx.ts +121 -0
- package/src/transaction/MerklePath.ts +11 -11
- package/src/transaction/Transaction.ts +196 -59
- package/src/transaction/__tests/Beef.test.ts +290 -0
- package/src/transaction/__tests/Transaction.test.ts +222 -3
- package/src/transaction/index.ts +3 -0
package/docs/transaction.md
CHANGED
|
@@ -449,6 +449,9 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
449
449
|
| |
|
|
450
450
|
| --- |
|
|
451
451
|
| [ARC](#class-arc) |
|
|
452
|
+
| [Beef](#class-beef) |
|
|
453
|
+
| [BeefParty](#class-beefparty) |
|
|
454
|
+
| [BeefTx](#class-beeftx) |
|
|
452
455
|
| [FetchHttpClient](#class-fetchhttpclient) |
|
|
453
456
|
| [MerklePath](#class-merklepath) |
|
|
454
457
|
| [NodejsHttpClient](#class-nodejshttpclient) |
|
|
@@ -836,6 +839,319 @@ Argument Details
|
|
|
836
839
|
|
|
837
840
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
838
841
|
|
|
842
|
+
---
|
|
843
|
+
### Class: BeefTx
|
|
844
|
+
|
|
845
|
+
A single bitcoin transaction associated with a `Beef` validity proof set.
|
|
846
|
+
|
|
847
|
+
Simple case is transaction data included directly, either as raw bytes or fully parsed data, or both.
|
|
848
|
+
|
|
849
|
+
Supports 'known' transactions which are represented by just their txid.
|
|
850
|
+
It is assumed that intended consumer of this beef already has validity proof for such a transaction,
|
|
851
|
+
which they can merge if necessary to create a valid beef.
|
|
852
|
+
|
|
853
|
+
```ts
|
|
854
|
+
export default class BeefTx {
|
|
855
|
+
_bumpIndex?: number;
|
|
856
|
+
_tx?: Transaction;
|
|
857
|
+
_rawTx?: number[];
|
|
858
|
+
_txid?: string;
|
|
859
|
+
inputTxids: string[] = [];
|
|
860
|
+
degree: number = 0;
|
|
861
|
+
get bumpIndex(): number | undefined
|
|
862
|
+
set bumpIndex(v: number | undefined)
|
|
863
|
+
get hasProof(): boolean
|
|
864
|
+
get isTxidOnly(): boolean
|
|
865
|
+
get txid()
|
|
866
|
+
get tx()
|
|
867
|
+
get rawTx()
|
|
868
|
+
constructor(tx: Transaction | number[] | string, bumpIndex?: number)
|
|
869
|
+
toWriter(writer: Writer): void
|
|
870
|
+
static fromReader(br: Reader): BeefTx
|
|
871
|
+
}
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
<details>
|
|
875
|
+
|
|
876
|
+
<summary>Class BeefTx Details</summary>
|
|
877
|
+
|
|
878
|
+
#### Constructor
|
|
879
|
+
|
|
880
|
+
```ts
|
|
881
|
+
constructor(tx: Transaction | number[] | string, bumpIndex?: number)
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
Argument Details
|
|
885
|
+
|
|
886
|
+
+ **tx**
|
|
887
|
+
+ If string, must be a valid txid. If `number[]` must be a valid serialized transaction.
|
|
888
|
+
+ **bumpIndex**
|
|
889
|
+
+ If transaction already has a proof in the beef to which it will be added.
|
|
890
|
+
|
|
891
|
+
</details>
|
|
892
|
+
|
|
893
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
894
|
+
|
|
895
|
+
---
|
|
896
|
+
### Class: Beef
|
|
897
|
+
|
|
898
|
+
```ts
|
|
899
|
+
export class Beef {
|
|
900
|
+
bumps: MerklePath[] = [];
|
|
901
|
+
txs: BeefTx[] = [];
|
|
902
|
+
constructor()
|
|
903
|
+
get version(): number
|
|
904
|
+
findTxid(txid: string): BeefTx | undefined
|
|
905
|
+
mergeBump(bump: MerklePath): number
|
|
906
|
+
mergeRawTx(rawTx: number[], bumpIndex?: number): BeefTx
|
|
907
|
+
mergeTransaction(tx: Transaction): BeefTx
|
|
908
|
+
removeExistingTxid(txid: string)
|
|
909
|
+
mergeTxidOnly(txid: string): BeefTx
|
|
910
|
+
mergeBeefTx(btx: BeefTx): BeefTx
|
|
911
|
+
mergeBeef(beef: number[] | Beef)
|
|
912
|
+
isValid(allowTxidOnly?: boolean): boolean
|
|
913
|
+
async verify(chainTracker: ChainTracker, allowTxidOnly?: boolean): Promise<boolean>
|
|
914
|
+
toBinary(): number[]
|
|
915
|
+
toHex(): string
|
|
916
|
+
static fromReader(br: Reader): Beef
|
|
917
|
+
static fromBinary(bin: number[]): Beef
|
|
918
|
+
static fromString(s: string, enc?: "hex" | "utf8" | "base64"): Beef
|
|
919
|
+
sortTxs(): string[]
|
|
920
|
+
clone(): Beef
|
|
921
|
+
trimKnownTxids(knownTxids: string[])
|
|
922
|
+
toLogString(): string
|
|
923
|
+
}
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
<details>
|
|
927
|
+
|
|
928
|
+
<summary>Class Beef Details</summary>
|
|
929
|
+
|
|
930
|
+
#### Method clone
|
|
931
|
+
|
|
932
|
+
```ts
|
|
933
|
+
clone(): Beef
|
|
934
|
+
```
|
|
935
|
+
|
|
936
|
+
Returns
|
|
937
|
+
|
|
938
|
+
a shallow copy of this beef
|
|
939
|
+
|
|
940
|
+
#### Method findTxid
|
|
941
|
+
|
|
942
|
+
```ts
|
|
943
|
+
findTxid(txid: string): BeefTx | undefined
|
|
944
|
+
```
|
|
945
|
+
|
|
946
|
+
Returns
|
|
947
|
+
|
|
948
|
+
`BeefTx` in `txs` with `txid`.
|
|
949
|
+
|
|
950
|
+
Argument Details
|
|
951
|
+
|
|
952
|
+
+ **txid**
|
|
953
|
+
+ of `beefTx` to find
|
|
954
|
+
|
|
955
|
+
#### Method fromBinary
|
|
956
|
+
|
|
957
|
+
Constructs an instance of the Beef class based on the provided binary array
|
|
958
|
+
|
|
959
|
+
```ts
|
|
960
|
+
static fromBinary(bin: number[]): Beef
|
|
961
|
+
```
|
|
962
|
+
|
|
963
|
+
Returns
|
|
964
|
+
|
|
965
|
+
An instance of the Beef class constructed from the binary data
|
|
966
|
+
|
|
967
|
+
Argument Details
|
|
968
|
+
|
|
969
|
+
+ **bin**
|
|
970
|
+
+ The binary array from which to construct BEEF
|
|
971
|
+
|
|
972
|
+
#### Method fromString
|
|
973
|
+
|
|
974
|
+
Constructs an instance of the Beef class based on the provided string
|
|
975
|
+
|
|
976
|
+
```ts
|
|
977
|
+
static fromString(s: string, enc?: "hex" | "utf8" | "base64"): Beef
|
|
978
|
+
```
|
|
979
|
+
|
|
980
|
+
Returns
|
|
981
|
+
|
|
982
|
+
An instance of the Beef class constructed from the string
|
|
983
|
+
|
|
984
|
+
Argument Details
|
|
985
|
+
|
|
986
|
+
+ **s**
|
|
987
|
+
+ The string value from which to construct BEEF
|
|
988
|
+
+ **enc**
|
|
989
|
+
+ The encoding of the string value from which BEEF should be constructed
|
|
990
|
+
|
|
991
|
+
#### Method isValid
|
|
992
|
+
|
|
993
|
+
Sorts `txs` and checks structural validity of beef.
|
|
994
|
+
|
|
995
|
+
Does NOT verify merkle roots.
|
|
996
|
+
|
|
997
|
+
Validity requirements:
|
|
998
|
+
1. No 'known' txids, unless `allowTxidOnly` is true.
|
|
999
|
+
2. All transactions have bumps or their inputs chain back to bumps (or are known).
|
|
1000
|
+
3. Order of transactions satisfies dependencies before dependents.
|
|
1001
|
+
4. No transactions with duplicate txids.
|
|
1002
|
+
|
|
1003
|
+
```ts
|
|
1004
|
+
isValid(allowTxidOnly?: boolean): boolean
|
|
1005
|
+
```
|
|
1006
|
+
|
|
1007
|
+
Argument Details
|
|
1008
|
+
|
|
1009
|
+
+ **allowTxidOnly**
|
|
1010
|
+
+ optional. If true, transaction txid only is assumed valid
|
|
1011
|
+
|
|
1012
|
+
#### Method mergeBump
|
|
1013
|
+
|
|
1014
|
+
Merge a MerklePath that is assumed to be fully valid.
|
|
1015
|
+
|
|
1016
|
+
```ts
|
|
1017
|
+
mergeBump(bump: MerklePath): number
|
|
1018
|
+
```
|
|
1019
|
+
|
|
1020
|
+
Returns
|
|
1021
|
+
|
|
1022
|
+
index of merged bump
|
|
1023
|
+
|
|
1024
|
+
#### Method mergeRawTx
|
|
1025
|
+
|
|
1026
|
+
Merge a serialized transaction.
|
|
1027
|
+
|
|
1028
|
+
Checks that a transaction with the same txid hasn't already been merged.
|
|
1029
|
+
|
|
1030
|
+
Replaces existing transaction with same txid.
|
|
1031
|
+
|
|
1032
|
+
```ts
|
|
1033
|
+
mergeRawTx(rawTx: number[], bumpIndex?: number): BeefTx
|
|
1034
|
+
```
|
|
1035
|
+
|
|
1036
|
+
Returns
|
|
1037
|
+
|
|
1038
|
+
txid of rawTx
|
|
1039
|
+
|
|
1040
|
+
Argument Details
|
|
1041
|
+
|
|
1042
|
+
+ **bumpIndex**
|
|
1043
|
+
+ Optional. If a number, must be valid index into bumps array.
|
|
1044
|
+
|
|
1045
|
+
#### Method mergeTransaction
|
|
1046
|
+
|
|
1047
|
+
Merge a `Transaction` and any referenced `merklePath` and `sourceTransaction`, recursifely.
|
|
1048
|
+
|
|
1049
|
+
Replaces existing transaction with same txid.
|
|
1050
|
+
|
|
1051
|
+
Attempts to match an existing bump to the new transaction.
|
|
1052
|
+
|
|
1053
|
+
```ts
|
|
1054
|
+
mergeTransaction(tx: Transaction): BeefTx
|
|
1055
|
+
```
|
|
1056
|
+
|
|
1057
|
+
Returns
|
|
1058
|
+
|
|
1059
|
+
txid of tx
|
|
1060
|
+
|
|
1061
|
+
#### Method removeExistingTxid
|
|
1062
|
+
|
|
1063
|
+
Removes an existing transaction from the BEEF, given its TXID
|
|
1064
|
+
|
|
1065
|
+
```ts
|
|
1066
|
+
removeExistingTxid(txid: string)
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
Argument Details
|
|
1070
|
+
|
|
1071
|
+
+ **txid**
|
|
1072
|
+
+ TXID of the transaction to remove
|
|
1073
|
+
|
|
1074
|
+
#### Method sortTxs
|
|
1075
|
+
|
|
1076
|
+
Sort the `txs` by input txid dependency order.
|
|
1077
|
+
|
|
1078
|
+
```ts
|
|
1079
|
+
sortTxs(): string[]
|
|
1080
|
+
```
|
|
1081
|
+
|
|
1082
|
+
Returns
|
|
1083
|
+
|
|
1084
|
+
array of input txids of unproven transactions that aren't included in txs.
|
|
1085
|
+
|
|
1086
|
+
#### Method toBinary
|
|
1087
|
+
|
|
1088
|
+
Returns a binary array representing the serialized BEEF
|
|
1089
|
+
|
|
1090
|
+
```ts
|
|
1091
|
+
toBinary(): number[]
|
|
1092
|
+
```
|
|
1093
|
+
|
|
1094
|
+
Returns
|
|
1095
|
+
|
|
1096
|
+
A binary array representing the BEEF
|
|
1097
|
+
|
|
1098
|
+
#### Method toHex
|
|
1099
|
+
|
|
1100
|
+
Returns a hex string representing the serialized BEEF
|
|
1101
|
+
|
|
1102
|
+
```ts
|
|
1103
|
+
toHex(): string
|
|
1104
|
+
```
|
|
1105
|
+
|
|
1106
|
+
Returns
|
|
1107
|
+
|
|
1108
|
+
A hex string representing the BEEF
|
|
1109
|
+
|
|
1110
|
+
#### Method toLogString
|
|
1111
|
+
|
|
1112
|
+
```ts
|
|
1113
|
+
toLogString(): string
|
|
1114
|
+
```
|
|
1115
|
+
|
|
1116
|
+
Returns
|
|
1117
|
+
|
|
1118
|
+
Summary of `Beef` contents as multi-line string.
|
|
1119
|
+
|
|
1120
|
+
#### Method trimKnownTxids
|
|
1121
|
+
|
|
1122
|
+
Ensure that all the txids in `knownTxids` are txidOnly
|
|
1123
|
+
|
|
1124
|
+
```ts
|
|
1125
|
+
trimKnownTxids(knownTxids: string[])
|
|
1126
|
+
```
|
|
1127
|
+
|
|
1128
|
+
#### Method verify
|
|
1129
|
+
|
|
1130
|
+
Sorts `txs` and confirms validity of transaction data contained in beef
|
|
1131
|
+
by validating structure of this beef and confirming computed merkle roots
|
|
1132
|
+
using `chainTracker`.
|
|
1133
|
+
|
|
1134
|
+
Validity requirements:
|
|
1135
|
+
1. No 'known' txids, unless `allowTxidOnly` is true.
|
|
1136
|
+
2. All transactions have bumps or their inputs chain back to bumps (or are known).
|
|
1137
|
+
3. Order of transactions satisfies dependencies before dependents.
|
|
1138
|
+
4. No transactions with duplicate txids.
|
|
1139
|
+
|
|
1140
|
+
```ts
|
|
1141
|
+
async verify(chainTracker: ChainTracker, allowTxidOnly?: boolean): Promise<boolean>
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
Argument Details
|
|
1145
|
+
|
|
1146
|
+
+ **chainTracker**
|
|
1147
|
+
+ Used to verify computed merkle path roots for all bump txids.
|
|
1148
|
+
+ **allowTxidOnly**
|
|
1149
|
+
+ optional. If true, transaction txid is assumed valid
|
|
1150
|
+
|
|
1151
|
+
</details>
|
|
1152
|
+
|
|
1153
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1154
|
+
|
|
839
1155
|
---
|
|
840
1156
|
### Class: Transaction
|
|
841
1157
|
|
|
@@ -863,7 +1179,8 @@ export default class Transaction {
|
|
|
863
1179
|
lockTime: number;
|
|
864
1180
|
metadata: Record<string, any>;
|
|
865
1181
|
merklePath?: MerklePath;
|
|
866
|
-
static fromBEEF(beef: number[]): Transaction
|
|
1182
|
+
static fromBEEF(beef: number[], txid?: string): Transaction
|
|
1183
|
+
static fromAtomicBEEF(beef: number[]): Transaction
|
|
867
1184
|
static fromEF(ef: number[]): Transaction
|
|
868
1185
|
static parseScriptOffsets(bin: number[]): {
|
|
869
1186
|
inputs: Array<{
|
|
@@ -881,7 +1198,7 @@ export default class Transaction {
|
|
|
881
1198
|
static fromBinary(bin: number[]): Transaction
|
|
882
1199
|
static fromHex(hex: string): Transaction
|
|
883
1200
|
static fromHexEF(hex: string): Transaction
|
|
884
|
-
static fromHexBEEF(hex: string): Transaction
|
|
1201
|
+
static fromHexBEEF(hex: string, txid?: string): Transaction
|
|
885
1202
|
constructor(version: number = 1, inputs: TransactionInput[] = [], outputs: TransactionOutput[] = [], lockTime: number = 0, metadata: Record<string, any> = {}, merklePath?: MerklePath)
|
|
886
1203
|
addInput(input: TransactionInput): void
|
|
887
1204
|
addOutput(output: TransactionOutput): void
|
|
@@ -895,12 +1212,14 @@ export default class Transaction {
|
|
|
895
1212
|
toHexEF(): string
|
|
896
1213
|
toHex(): string
|
|
897
1214
|
toHexBEEF(): string
|
|
1215
|
+
toHexAtomicBEEF(): string
|
|
898
1216
|
hash(enc?: "hex"): number[] | string
|
|
899
1217
|
id(): number[];
|
|
900
1218
|
id(enc: "hex"): string;
|
|
901
1219
|
id(enc?: "hex"): number[] | string
|
|
902
1220
|
async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker(), feeModel?: FeeModel): Promise<boolean>
|
|
903
1221
|
toBEEF(): number[]
|
|
1222
|
+
toAtomicBEEF(): number[]
|
|
904
1223
|
}
|
|
905
1224
|
```
|
|
906
1225
|
|
|
@@ -975,12 +1294,35 @@ amongst the change outputs
|
|
|
975
1294
|
|
|
976
1295
|
TODO: Benford's law change distribution.
|
|
977
1296
|
|
|
1297
|
+
#### Method fromAtomicBEEF
|
|
1298
|
+
|
|
1299
|
+
Creates a new transaction from an Atomic BEEF (BRC-95) structure.
|
|
1300
|
+
Extracts the subject transaction and ensures that all transactions within the BEEF data
|
|
1301
|
+
are part of the dependency graph of the subject transaction.
|
|
1302
|
+
Throws errors if the Atomic BEEF data does not strictly adhere to the BRC-95 specification.
|
|
1303
|
+
|
|
1304
|
+
```ts
|
|
1305
|
+
static fromAtomicBEEF(beef: number[]): Transaction
|
|
1306
|
+
```
|
|
1307
|
+
|
|
1308
|
+
Returns
|
|
1309
|
+
|
|
1310
|
+
The subject transaction, linked to its associated inputs populated with merkle paths.
|
|
1311
|
+
|
|
1312
|
+
Argument Details
|
|
1313
|
+
|
|
1314
|
+
+ **beef**
|
|
1315
|
+
+ A binary representation of an Atomic BEEF structure.
|
|
1316
|
+
|
|
978
1317
|
#### Method fromBEEF
|
|
979
1318
|
|
|
980
1319
|
Creates a new transaction, linked to its inputs and their associated merkle paths, from a BEEF (BRC-62) structure.
|
|
1320
|
+
Optionally, you can provide a specific TXID to retrieve a particular transaction from the BEEF data.
|
|
1321
|
+
If the TXID is provided but not found in the BEEF data, an error will be thrown.
|
|
1322
|
+
If no TXID is provided, the last transaction in the BEEF data is returned.
|
|
981
1323
|
|
|
982
1324
|
```ts
|
|
983
|
-
static fromBEEF(beef: number[]): Transaction
|
|
1325
|
+
static fromBEEF(beef: number[], txid?: string): Transaction
|
|
984
1326
|
```
|
|
985
1327
|
|
|
986
1328
|
Returns
|
|
@@ -990,7 +1332,9 @@ An anchored transaction, linked to its associated inputs populated with merkle p
|
|
|
990
1332
|
Argument Details
|
|
991
1333
|
|
|
992
1334
|
+ **beef**
|
|
993
|
-
+ A binary representation of
|
|
1335
|
+
+ A binary representation of transactions in BEEF format.
|
|
1336
|
+
+ **txid**
|
|
1337
|
+
+ Optional TXID of the transaction to retrieve from the BEEF data.
|
|
994
1338
|
|
|
995
1339
|
#### Method fromBinary
|
|
996
1340
|
|
|
@@ -1046,9 +1390,12 @@ Argument Details
|
|
|
1046
1390
|
#### Method fromHexBEEF
|
|
1047
1391
|
|
|
1048
1392
|
Creates a Transaction instance from a hexadecimal string encoded BEEF.
|
|
1393
|
+
Optionally, you can provide a specific TXID to retrieve a particular transaction from the BEEF data.
|
|
1394
|
+
If the TXID is provided but not found in the BEEF data, an error will be thrown.
|
|
1395
|
+
If no TXID is provided, the last transaction in the BEEF data is returned.
|
|
1049
1396
|
|
|
1050
1397
|
```ts
|
|
1051
|
-
static fromHexBEEF(hex: string): Transaction
|
|
1398
|
+
static fromHexBEEF(hex: string, txid?: string): Transaction
|
|
1052
1399
|
```
|
|
1053
1400
|
|
|
1054
1401
|
Returns
|
|
@@ -1059,6 +1406,8 @@ Argument Details
|
|
|
1059
1406
|
|
|
1060
1407
|
+ **hex**
|
|
1061
1408
|
+ The hexadecimal string representation of the transaction BEEF.
|
|
1409
|
+
+ **txid**
|
|
1410
|
+
+ Optional TXID of the transaction to retrieve from the BEEF data.
|
|
1062
1411
|
|
|
1063
1412
|
#### Method fromHexEF
|
|
1064
1413
|
|
|
@@ -1196,6 +1545,21 @@ Signs a transaction, hydrating all its unlocking scripts based on the provided s
|
|
|
1196
1545
|
async sign(): Promise<void>
|
|
1197
1546
|
```
|
|
1198
1547
|
|
|
1548
|
+
#### Method toAtomicBEEF
|
|
1549
|
+
|
|
1550
|
+
Serializes this transaction and its inputs into the Atomic BEEF (BRC-95) format.
|
|
1551
|
+
The Atomic BEEF format starts with a 4-byte prefix `0x01010101`, followed by the TXID of the subject transaction,
|
|
1552
|
+
and then the BEEF data containing only the subject transaction and its dependencies.
|
|
1553
|
+
This format ensures that the BEEF structure is atomic and contains no unrelated transactions.
|
|
1554
|
+
|
|
1555
|
+
```ts
|
|
1556
|
+
toAtomicBEEF(): number[]
|
|
1557
|
+
```
|
|
1558
|
+
|
|
1559
|
+
Returns
|
|
1560
|
+
|
|
1561
|
+
- The serialized Atomic BEEF structure.
|
|
1562
|
+
|
|
1199
1563
|
#### Method toBEEF
|
|
1200
1564
|
|
|
1201
1565
|
Serializes this transaction, together with its inputs and the respective merkle proofs, into the BEEF (BRC-62) format. This enables efficient verification of its compliance with the rules of SPV.
|
|
@@ -1244,6 +1608,18 @@ Returns
|
|
|
1244
1608
|
|
|
1245
1609
|
- The hexadecimal string representation of the transaction.
|
|
1246
1610
|
|
|
1611
|
+
#### Method toHexAtomicBEEF
|
|
1612
|
+
|
|
1613
|
+
Converts the transaction to a hexadecimal string Atomic BEEF.
|
|
1614
|
+
|
|
1615
|
+
```ts
|
|
1616
|
+
toHexAtomicBEEF(): string
|
|
1617
|
+
```
|
|
1618
|
+
|
|
1619
|
+
Returns
|
|
1620
|
+
|
|
1621
|
+
- The hexadecimal string representation of the transaction Atomic BEEF.
|
|
1622
|
+
|
|
1247
1623
|
#### Method toHexBEEF
|
|
1248
1624
|
|
|
1249
1625
|
Converts the transaction to a hexadecimal string BEEF.
|
|
@@ -1308,6 +1684,119 @@ tx.verify(new WhatsOnChain(), new SatoshisPerKilobyte(1))
|
|
|
1308
1684
|
|
|
1309
1685
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1310
1686
|
|
|
1687
|
+
---
|
|
1688
|
+
### Class: BeefParty
|
|
1689
|
+
|
|
1690
|
+
Extends `Beef` that is used to exchange transaction validity data with more than one external party.
|
|
1691
|
+
|
|
1692
|
+
Use `addKnownTxidsForParty` to keep track of who knows what to reduce re-transmission of potentially large transactions.
|
|
1693
|
+
|
|
1694
|
+
Use `getTrimmedBeefForParty` to obtain a `Beef` trimmed of transaction validity data known to a specific party.
|
|
1695
|
+
|
|
1696
|
+
Typical usage scenario:
|
|
1697
|
+
|
|
1698
|
+
1. Query a wallet storage provider for spendable outputs.
|
|
1699
|
+
2. The provider replies with a Beef validating the returned outputs.
|
|
1700
|
+
3. Construct a new transaction using some of the queried outputs as inputs, including Beef validating all the inputs.
|
|
1701
|
+
4. Receive new valid raw transaction after processing and Beef validating change outputs added to original inputs.
|
|
1702
|
+
5. Return to step 1, continuing to build on old and new spendable outputs.
|
|
1703
|
+
|
|
1704
|
+
By default, each Beef is required to be complete and valid: All transactions appear as full serialized bitcoin transactions and
|
|
1705
|
+
each transaction either has a merkle path proof (it has been mined) or all of its input transactions are included.
|
|
1706
|
+
|
|
1707
|
+
The size and redundancy of these Beefs becomes a problem when chained transaction creation out-paces the block mining rate.
|
|
1708
|
+
|
|
1709
|
+
```ts
|
|
1710
|
+
export class BeefParty extends Beef {
|
|
1711
|
+
knownTo: Record<string, Record<string, boolean>> = {};
|
|
1712
|
+
constructor(parties?: string[])
|
|
1713
|
+
isParty(party: string)
|
|
1714
|
+
addParty(party: string)
|
|
1715
|
+
getKnownTxidsForParty(party: string): string[]
|
|
1716
|
+
getTrimmedBeefForParty(party: string): Beef
|
|
1717
|
+
addKnownTxidsForParty(party: string, knownTxids: string[])
|
|
1718
|
+
}
|
|
1719
|
+
```
|
|
1720
|
+
|
|
1721
|
+
<details>
|
|
1722
|
+
|
|
1723
|
+
<summary>Class BeefParty Details</summary>
|
|
1724
|
+
|
|
1725
|
+
#### Constructor
|
|
1726
|
+
|
|
1727
|
+
```ts
|
|
1728
|
+
constructor(parties?: string[])
|
|
1729
|
+
```
|
|
1730
|
+
|
|
1731
|
+
Argument Details
|
|
1732
|
+
|
|
1733
|
+
+ **parties**
|
|
1734
|
+
+ Optional array of initial unique party identifiers.
|
|
1735
|
+
|
|
1736
|
+
#### Property knownTo
|
|
1737
|
+
|
|
1738
|
+
keys are party identifiers.
|
|
1739
|
+
values are records of txids with truthy value for which the party already has validity proof.
|
|
1740
|
+
|
|
1741
|
+
```ts
|
|
1742
|
+
knownTo: Record<string, Record<string, boolean>> = {}
|
|
1743
|
+
```
|
|
1744
|
+
|
|
1745
|
+
#### Method addKnownTxidsForParty
|
|
1746
|
+
|
|
1747
|
+
Make note of additional txids "known" to `party`.
|
|
1748
|
+
|
|
1749
|
+
```ts
|
|
1750
|
+
addKnownTxidsForParty(party: string, knownTxids: string[])
|
|
1751
|
+
```
|
|
1752
|
+
|
|
1753
|
+
Argument Details
|
|
1754
|
+
|
|
1755
|
+
+ **party**
|
|
1756
|
+
+ unique identifier, added if new.
|
|
1757
|
+
|
|
1758
|
+
#### Method addParty
|
|
1759
|
+
|
|
1760
|
+
Adds a new unique party identifier to this `BeefParty`.
|
|
1761
|
+
|
|
1762
|
+
```ts
|
|
1763
|
+
addParty(party: string)
|
|
1764
|
+
```
|
|
1765
|
+
|
|
1766
|
+
#### Method getKnownTxidsForParty
|
|
1767
|
+
|
|
1768
|
+
```ts
|
|
1769
|
+
getKnownTxidsForParty(party: string): string[]
|
|
1770
|
+
```
|
|
1771
|
+
|
|
1772
|
+
Returns
|
|
1773
|
+
|
|
1774
|
+
Array of txids "known" to `party`.
|
|
1775
|
+
|
|
1776
|
+
#### Method getTrimmedBeefForParty
|
|
1777
|
+
|
|
1778
|
+
```ts
|
|
1779
|
+
getTrimmedBeefForParty(party: string): Beef
|
|
1780
|
+
```
|
|
1781
|
+
|
|
1782
|
+
Returns
|
|
1783
|
+
|
|
1784
|
+
trimmed beef of unknown transactions and proofs for `party`
|
|
1785
|
+
|
|
1786
|
+
#### Method isParty
|
|
1787
|
+
|
|
1788
|
+
```ts
|
|
1789
|
+
isParty(party: string)
|
|
1790
|
+
```
|
|
1791
|
+
|
|
1792
|
+
Returns
|
|
1793
|
+
|
|
1794
|
+
`true` if `party` has already beed added to this `BeefParty`.
|
|
1795
|
+
|
|
1796
|
+
</details>
|
|
1797
|
+
|
|
1798
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1799
|
+
|
|
1311
1800
|
---
|
|
1312
1801
|
## Functions
|
|
1313
1802
|
|
|
@@ -1423,3 +1912,40 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
1423
1912
|
---
|
|
1424
1913
|
## Variables
|
|
1425
1914
|
|
|
1915
|
+
| |
|
|
1916
|
+
| --- |
|
|
1917
|
+
| [BEEF_MAGIC](#variable-beef_magic) |
|
|
1918
|
+
| [BEEF_MAGIC_TXID_ONLY_EXTENSION](#variable-beef_magic_txid_only_extension) |
|
|
1919
|
+
| [BEEF_MAGIC_V2](#variable-beef_magic_v2) |
|
|
1920
|
+
|
|
1921
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1922
|
+
|
|
1923
|
+
---
|
|
1924
|
+
|
|
1925
|
+
### Variable: BEEF_MAGIC
|
|
1926
|
+
|
|
1927
|
+
```ts
|
|
1928
|
+
BEEF_MAGIC = 4022206465
|
|
1929
|
+
```
|
|
1930
|
+
|
|
1931
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1932
|
+
|
|
1933
|
+
---
|
|
1934
|
+
### Variable: BEEF_MAGIC_V2
|
|
1935
|
+
|
|
1936
|
+
```ts
|
|
1937
|
+
BEEF_MAGIC_V2 = 4022206466
|
|
1938
|
+
```
|
|
1939
|
+
|
|
1940
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1941
|
+
|
|
1942
|
+
---
|
|
1943
|
+
### Variable: BEEF_MAGIC_TXID_ONLY_EXTENSION
|
|
1944
|
+
|
|
1945
|
+
```ts
|
|
1946
|
+
BEEF_MAGIC_TXID_ONLY_EXTENSION = 4022206465
|
|
1947
|
+
```
|
|
1948
|
+
|
|
1949
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1950
|
+
|
|
1951
|
+
---
|
package/package.json
CHANGED
package/src/totp/totp.ts
CHANGED
|
@@ -106,7 +106,7 @@ function generateHOTP (
|
|
|
106
106
|
options: Required<TOTPOptions>
|
|
107
107
|
): string {
|
|
108
108
|
const timePad = new BigNumber(counter).toArray('be', 8)
|
|
109
|
-
console.log({ timePad })
|
|
109
|
+
//console.log({ timePad })
|
|
110
110
|
const hmac = calcHMAC(secret, timePad, options.algorithm)
|
|
111
111
|
const signature = hmac.digest()
|
|
112
112
|
|