@bsv/sdk 1.4.20 → 1.4.23
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/auth/certificates/VerifiableCertificate.js +10 -0
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/cjs/src/script/Spend.js +239 -42
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/src/transaction/Transaction.js +5 -2
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js +10 -0
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/esm/src/script/Spend.js +236 -37
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/src/transaction/Transaction.js +5 -2
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +9 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
- package/dist/types/src/script/Spend.d.ts +7 -1
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/src/transaction/Transaction.d.ts +3 -1
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/auth.md +21 -1
- package/docs/script.md +7 -1
- package/docs/transaction.md +6 -2
- package/package.json +1 -1
- package/src/auth/certificates/VerifiableCertificate.ts +24 -0
- package/src/auth/certificates/__tests/VerifiableCertificate.test.ts +28 -1
- package/src/auth/clients/AuthFetch.ts +2 -0
- package/src/script/Spend.ts +253 -42
- package/src/transaction/Transaction.ts +6 -2
- package/src/transaction/__tests/Transaction.test.ts +125 -1
package/docs/auth.md
CHANGED
|
@@ -1106,11 +1106,12 @@ export class VerifiableCertificate extends Certificate {
|
|
|
1106
1106
|
keyring: Record<CertificateFieldNameUnder50Bytes, string>;
|
|
1107
1107
|
decryptedFields?: Record<CertificateFieldNameUnder50Bytes, Base64String>;
|
|
1108
1108
|
constructor(type: Base64String, serialNumber: Base64String, subject: PubKeyHex, certifier: PubKeyHex, revocationOutpoint: OutpointString, fields: Record<CertificateFieldNameUnder50Bytes, string>, keyring: Record<CertificateFieldNameUnder50Bytes, string>, signature?: HexString, decryptedFields?: Record<CertificateFieldNameUnder50Bytes, Base64String>)
|
|
1109
|
+
static fromCertificate(certificate: WalletCertificate, keyring: Record<CertificateFieldNameUnder50Bytes, string>): VerifiableCertificate
|
|
1109
1110
|
async decryptFields(verifierWallet: ProtoWallet, privileged?: boolean, privilegedReason?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
1110
1111
|
}
|
|
1111
1112
|
```
|
|
1112
1113
|
|
|
1113
|
-
See also: [Base64String](./wallet.md#type-base64string), [Certificate](./auth.md#class-certificate), [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [HexString](./wallet.md#type-hexstring), [OutpointString](./wallet.md#type-outpointstring), [ProtoWallet](./wallet.md#class-protowallet), [PubKeyHex](./wallet.md#type-pubkeyhex)
|
|
1114
|
+
See also: [Base64String](./wallet.md#type-base64string), [Certificate](./auth.md#class-certificate), [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [HexString](./wallet.md#type-hexstring), [OutpointString](./wallet.md#type-outpointstring), [ProtoWallet](./wallet.md#class-protowallet), [PubKeyHex](./wallet.md#type-pubkeyhex), [WalletCertificate](./wallet.md#interface-walletcertificate)
|
|
1114
1115
|
|
|
1115
1116
|
#### Method decryptFields
|
|
1116
1117
|
|
|
@@ -1138,6 +1139,25 @@ Throws
|
|
|
1138
1139
|
|
|
1139
1140
|
Throws an error if any of the decryption operations fail, with a message indicating the failure context.
|
|
1140
1141
|
|
|
1142
|
+
#### Method fromCertificate
|
|
1143
|
+
|
|
1144
|
+
```ts
|
|
1145
|
+
static fromCertificate(certificate: WalletCertificate, keyring: Record<CertificateFieldNameUnder50Bytes, string>): VerifiableCertificate
|
|
1146
|
+
```
|
|
1147
|
+
See also: [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [VerifiableCertificate](./auth.md#class-verifiablecertificate), [WalletCertificate](./wallet.md#interface-walletcertificate)
|
|
1148
|
+
|
|
1149
|
+
Returns
|
|
1150
|
+
|
|
1151
|
+
– A fully-formed instance containing the
|
|
1152
|
+
original certificate data plus the supplied keyring.
|
|
1153
|
+
|
|
1154
|
+
Argument Details
|
|
1155
|
+
|
|
1156
|
+
+ **certificate**
|
|
1157
|
+
+ – The source certificate that was issued and signed by the certifier.
|
|
1158
|
+
+ **keyring**
|
|
1159
|
+
+ – A allows the verifier to decrypt selected certificate fields.
|
|
1160
|
+
|
|
1141
1161
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
1142
1162
|
|
|
1143
1163
|
---
|
package/docs/script.md
CHANGED
|
@@ -756,6 +756,9 @@ export default class Spend {
|
|
|
756
756
|
stack: number[][];
|
|
757
757
|
altStack: number[][];
|
|
758
758
|
ifStack: boolean[];
|
|
759
|
+
memoryLimit: number;
|
|
760
|
+
stackMem: number;
|
|
761
|
+
altStackMem: number;
|
|
759
762
|
constructor(params: {
|
|
760
763
|
sourceTXID: string;
|
|
761
764
|
sourceOutputIndex: number;
|
|
@@ -768,9 +771,10 @@ export default class Spend {
|
|
|
768
771
|
inputSequence: number;
|
|
769
772
|
inputIndex: number;
|
|
770
773
|
lockTime: number;
|
|
774
|
+
memoryLimit?: number;
|
|
771
775
|
})
|
|
772
776
|
reset(): void
|
|
773
|
-
step():
|
|
777
|
+
step(): boolean
|
|
774
778
|
validate(): boolean
|
|
775
779
|
}
|
|
776
780
|
```
|
|
@@ -792,6 +796,7 @@ constructor(params: {
|
|
|
792
796
|
inputSequence: number;
|
|
793
797
|
inputIndex: number;
|
|
794
798
|
lockTime: number;
|
|
799
|
+
memoryLimit?: number;
|
|
795
800
|
})
|
|
796
801
|
```
|
|
797
802
|
See also: [LockingScript](./script.md#class-lockingscript), [TransactionInput](./transaction.md#interface-transactioninput), [TransactionOutput](./transaction.md#interface-transactionoutput), [UnlockingScript](./script.md#class-unlockingscript)
|
|
@@ -837,6 +842,7 @@ const spend = new Spend({
|
|
|
837
842
|
inputIndex: 0, // inputIndex
|
|
838
843
|
unlockingScript: UnlockingScript.fromASM("3045... 02ab..."),
|
|
839
844
|
inputSequence: 0xffffffff // inputSequence
|
|
845
|
+
memoryLimit: 100000 // memoryLimit
|
|
840
846
|
});
|
|
841
847
|
```
|
|
842
848
|
|
package/docs/transaction.md
CHANGED
|
@@ -1491,7 +1491,7 @@ export default class Transaction {
|
|
|
1491
1491
|
id(): number[];
|
|
1492
1492
|
id(enc: "hex"): string;
|
|
1493
1493
|
id(enc?: "hex"): number[] | string
|
|
1494
|
-
async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker(), feeModel?: FeeModel): Promise<boolean>
|
|
1494
|
+
async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker(), feeModel?: FeeModel, memoryLimit?: number): Promise<boolean>
|
|
1495
1495
|
toBEEF(allowPartial?: boolean): number[]
|
|
1496
1496
|
toAtomicBEEF(allowPartial?: boolean): number[]
|
|
1497
1497
|
}
|
|
@@ -1974,7 +1974,7 @@ Argument Details
|
|
|
1974
1974
|
Verifies the legitimacy of the Bitcoin transaction according to the rules of SPV by ensuring all the input transactions link back to valid block headers, the chain of spends for all inputs are valid, and the sum of inputs is not less than the sum of outputs.
|
|
1975
1975
|
|
|
1976
1976
|
```ts
|
|
1977
|
-
async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker(), feeModel?: FeeModel): Promise<boolean>
|
|
1977
|
+
async verify(chainTracker: ChainTracker | "scripts only" = defaultChainTracker(), feeModel?: FeeModel, memoryLimit?: number): Promise<boolean>
|
|
1978
1978
|
```
|
|
1979
1979
|
See also: [ChainTracker](./transaction.md#interface-chaintracker), [FeeModel](./transaction.md#interface-feemodel), [defaultChainTracker](./transaction.md#function-defaultchaintracker)
|
|
1980
1980
|
|
|
@@ -1986,6 +1986,10 @@ Argument Details
|
|
|
1986
1986
|
|
|
1987
1987
|
+ **chainTracker**
|
|
1988
1988
|
+ An instance of ChainTracker, a Bitcoin block header tracker. If the value is set to 'scripts only', headers will not be verified. If not provided then the default chain tracker will be used.
|
|
1989
|
+
+ **feeModel**
|
|
1990
|
+
+ An instance of FeeModel, a fee model to use for fee calculation. If not provided then the default fee model will be used.
|
|
1991
|
+
+ **memoryLimit**
|
|
1992
|
+
+ The maximum memory in bytes usage allowed for script evaluation. If not provided then the default memory limit will be used.
|
|
1989
1993
|
|
|
1990
1994
|
Example
|
|
1991
1995
|
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
CertificateFieldNameUnder50Bytes,
|
|
5
5
|
HexString,
|
|
6
6
|
OutpointString,
|
|
7
|
+
WalletCertificate,
|
|
7
8
|
} from '../../wallet/Wallet.interfaces.js'
|
|
8
9
|
import SymmetricKey from '../../primitives/SymmetricKey.js'
|
|
9
10
|
import * as Utils from '../../primitives/utils.js'
|
|
@@ -50,6 +51,29 @@ export class VerifiableCertificate extends Certificate {
|
|
|
50
51
|
this.decryptedFields = decryptedFields
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {WalletCertificate} certificate – The source certificate that was issued and signed by the certifier.
|
|
57
|
+
* @param {Record<CertificateFieldNameUnder50Bytes, string>} keyring – A allows the verifier to decrypt selected certificate fields.
|
|
58
|
+
* @returns {VerifiableCertificate} – A fully-formed instance containing the
|
|
59
|
+
* original certificate data plus the supplied keyring.
|
|
60
|
+
*/
|
|
61
|
+
static fromCertificate(
|
|
62
|
+
certificate: WalletCertificate,
|
|
63
|
+
keyring: Record<CertificateFieldNameUnder50Bytes, string>
|
|
64
|
+
): VerifiableCertificate {
|
|
65
|
+
return new VerifiableCertificate(
|
|
66
|
+
certificate.type,
|
|
67
|
+
certificate.serialNumber,
|
|
68
|
+
certificate.subject,
|
|
69
|
+
certificate.certifier,
|
|
70
|
+
certificate.revocationOutpoint,
|
|
71
|
+
certificate.fields,
|
|
72
|
+
keyring,
|
|
73
|
+
certificate.signature
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
53
77
|
/**
|
|
54
78
|
* Decrypts selectively revealed certificate fields using the provided keyring and verifier wallet
|
|
55
79
|
* @param {ProtoWallet} verifierWallet - The wallet instance of the certificate's verifier, used to decrypt field keys.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { VerifiableCertificate } from '../../../auth/certificates/VerifiableCertificate'
|
|
2
|
+
import Certificate from '../../../auth/certificates/Certificate'
|
|
2
3
|
import { PrivateKey, Utils } from '../../../../mod'
|
|
3
4
|
import { CompletedProtoWallet } from '../../../auth/certificates/__tests/CompletedProtoWallet'
|
|
4
5
|
import { MasterCertificate } from '../../../auth/certificates/MasterCertificate'
|
|
5
|
-
import { ProtoWallet } from '../../../wallet/index'
|
|
6
|
+
import { ProtoWallet, WalletCertificate } from '../../../wallet/index'
|
|
6
7
|
|
|
7
8
|
describe('VerifiableCertificate', () => {
|
|
8
9
|
const subjectPrivateKey = PrivateKey.fromRandom()
|
|
@@ -149,4 +150,30 @@ describe('VerifiableCertificate', () => {
|
|
|
149
150
|
expect(decrypted).toEqual(plaintextFields)
|
|
150
151
|
})
|
|
151
152
|
})
|
|
153
|
+
|
|
154
|
+
describe('fromCertificate', () => {
|
|
155
|
+
it('should create an equivalent VerifiableCertificate and decrypt correctly', async () => {
|
|
156
|
+
const baseCert = new Certificate(
|
|
157
|
+
verifiableCert.type,
|
|
158
|
+
verifiableCert.serialNumber,
|
|
159
|
+
verifiableCert.subject,
|
|
160
|
+
verifiableCert.certifier,
|
|
161
|
+
verifiableCert.revocationOutpoint,
|
|
162
|
+
verifiableCert.fields,
|
|
163
|
+
verifiableCert.signature
|
|
164
|
+
) as WalletCertificate
|
|
165
|
+
|
|
166
|
+
const verifiable = VerifiableCertificate.fromCertificate(
|
|
167
|
+
baseCert,
|
|
168
|
+
verifiableCert.keyring
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
expect(verifiable).toBeInstanceOf(VerifiableCertificate)
|
|
172
|
+
expect(verifiable.serialNumber).toEqual(sampleSerialNumber)
|
|
173
|
+
expect(verifiable.keyring).toEqual(verifiableCert.keyring)
|
|
174
|
+
|
|
175
|
+
const decrypted = await verifiable.decryptFields(verifierWallet)
|
|
176
|
+
expect(decrypted).toEqual(plaintextFields)
|
|
177
|
+
})
|
|
178
|
+
})
|
|
152
179
|
})
|