@btc-vision/btc-runtime 1.11.0-rc.9 → 1.11.0
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/README.md +7 -7
- package/docs/README.md +39 -39
- package/docs/advanced/bitcoin-scripts.md +17 -17
- package/docs/advanced/{contract-upgrades.md → contract-updates.md} +90 -98
- package/docs/advanced/cross-contract-calls.md +4 -4
- package/docs/advanced/plugins.md +21 -21
- package/docs/advanced/quantum-resistance.md +32 -32
- package/docs/advanced/signature-verification.md +22 -22
- package/docs/api-reference/blockchain.md +14 -14
- package/docs/api-reference/events.md +2 -2
- package/docs/api-reference/op20.md +7 -7
- package/docs/api-reference/op721.md +7 -7
- package/docs/api-reference/storage.md +2 -2
- package/docs/contracts/op-net-base.md +15 -15
- package/docs/contracts/op20-token.md +3 -3
- package/docs/contracts/op20s-signatures.md +2 -2
- package/docs/contracts/op721-nft.md +3 -3
- package/docs/contracts/reentrancy-guard.md +5 -7
- package/docs/contracts/updatable.md +384 -0
- package/docs/core-concepts/blockchain-environment.md +10 -10
- package/docs/core-concepts/decorators.md +5 -5
- package/docs/core-concepts/events.md +6 -6
- package/docs/core-concepts/pointers.md +5 -5
- package/docs/core-concepts/security.md +5 -5
- package/docs/core-concepts/storage-system.md +24 -24
- package/docs/examples/basic-token.md +8 -8
- package/docs/examples/nft-with-reservations.md +9 -9
- package/docs/examples/oracle-integration.md +13 -13
- package/docs/examples/stablecoin.md +10 -10
- package/docs/getting-started/first-contract.md +8 -8
- package/docs/getting-started/installation.md +2 -2
- package/docs/getting-started/project-structure.md +6 -6
- package/docs/storage/memory-maps.md +8 -8
- package/docs/storage/stored-arrays.md +6 -6
- package/docs/storage/stored-maps.md +8 -8
- package/docs/storage/stored-primitives.md +6 -6
- package/docs/types/address.md +13 -13
- package/docs/types/bytes-writer-reader.md +18 -18
- package/docs/types/calldata.md +12 -12
- package/package.json +10 -10
- package/runtime/constants/Exports.ts +0 -30
- package/runtime/contracts/OP20.ts +7 -7
- package/runtime/contracts/OP721.ts +60 -74
- package/runtime/contracts/OP_NET.ts +2 -2
- package/runtime/contracts/ReentrancyGuard.ts +1 -5
- package/runtime/contracts/Updatable.ts +241 -0
- package/runtime/contracts/interfaces/OP721InitParameters.ts +8 -8
- package/runtime/env/BlockchainEnvironment.ts +5 -5
- package/runtime/env/global.ts +7 -6
- package/runtime/events/predefined/{ApprovedEvent.ts → OP20ApprovedEvent.ts} +1 -1
- package/runtime/events/predefined/{BurnedEvent.ts → OP20BurnedEvent.ts} +1 -1
- package/runtime/events/predefined/{MintedEvent.ts → OP20MintedEvent.ts} +1 -1
- package/runtime/events/predefined/{TransferredEvent.ts → OP20TransferredEvent.ts} +1 -1
- package/runtime/events/predefined/OP721ApprovedEvent.ts +17 -0
- package/runtime/events/predefined/{ApprovedForAll.ts → OP721ApprovedForAllEvent.ts} +1 -1
- package/runtime/events/predefined/OP721BurnedEvent.ts +16 -0
- package/runtime/events/predefined/OP721MintedEvent.ts +16 -0
- package/runtime/events/predefined/OP721TransferredEvent.ts +18 -0
- package/runtime/events/predefined/index.ts +5 -5
- package/runtime/events/{upgradeable/UpgradeableEvents.ts → updatable/UpdatableEvents.ts} +9 -9
- package/runtime/hashing/keccak256.ts +1 -1
- package/runtime/index.ts +3 -5
- package/runtime/plugins/UpdatablePlugin.ts +276 -0
- package/runtime/script/Networks.ts +1 -1
- package/runtime/storage/StoredBoolean.ts +23 -12
- package/runtime/types/Address.ts +1 -1
- package/runtime/types/ExtendedAddress.ts +1 -1
- package/docs/contracts/upgradeable.md +0 -396
- package/runtime/contracts/Upgradeable.ts +0 -242
- package/runtime/contracts/interfaces/IOP1155.ts +0 -33
- package/runtime/contracts/interfaces/OP1155InitParameters.ts +0 -11
- package/runtime/plugins/UpgradeablePlugin.ts +0 -279
|
@@ -8,8 +8,6 @@ import { Revert } from '../types/Revert';
|
|
|
8
8
|
import { u256 } from '@btc-vision/as-bignum/assembly';
|
|
9
9
|
import { SafeMath } from '../types/SafeMath';
|
|
10
10
|
import {
|
|
11
|
-
ON_OP1155_BATCH_RECEIVED_MAGIC,
|
|
12
|
-
ON_OP1155_RECEIVED_MAGIC,
|
|
13
11
|
ON_OP20_RECEIVED_SELECTOR,
|
|
14
12
|
ON_OP721_RECEIVED_SELECTOR,
|
|
15
13
|
} from '../constants/Exports';
|
|
@@ -128,9 +126,7 @@ export class ReentrancyGuard extends OP_NET {
|
|
|
128
126
|
protected isSelectorExcluded(selector: Selector): boolean {
|
|
129
127
|
return (
|
|
130
128
|
selector === ON_OP20_RECEIVED_SELECTOR ||
|
|
131
|
-
selector === ON_OP721_RECEIVED_SELECTOR
|
|
132
|
-
selector === ON_OP1155_RECEIVED_MAGIC ||
|
|
133
|
-
selector === ON_OP1155_BATCH_RECEIVED_MAGIC
|
|
129
|
+
selector === ON_OP721_RECEIVED_SELECTOR
|
|
134
130
|
);
|
|
135
131
|
}
|
|
136
132
|
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { u256 } from '@btc-vision/as-bignum/assembly';
|
|
2
|
+
import { Blockchain } from '../env';
|
|
3
|
+
import { OP_NET } from './OP_NET';
|
|
4
|
+
import { StoredAddress } from '../storage/StoredAddress';
|
|
5
|
+
import { StoredU256 } from '../storage/StoredU256';
|
|
6
|
+
import { Address } from '../types/Address';
|
|
7
|
+
import { Revert } from '../types/Revert';
|
|
8
|
+
import { BytesWriter } from '../buffer/BytesWriter';
|
|
9
|
+
import { EMPTY_POINTER } from '../math/bytes';
|
|
10
|
+
import {
|
|
11
|
+
UpdateAppliedEvent,
|
|
12
|
+
UpdateCancelledEvent,
|
|
13
|
+
UpdateSubmittedEvent,
|
|
14
|
+
} from '../events/updatable/UpdatableEvents';
|
|
15
|
+
|
|
16
|
+
const pendingUpdateAddressPointer: u16 = Blockchain.nextPointer;
|
|
17
|
+
const pendingUpdateBlockPointer: u16 = Blockchain.nextPointer;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Updatable - Base contract for updatable contracts with timelock protection.
|
|
21
|
+
*
|
|
22
|
+
* This contract provides a secure update mechanism with a configurable delay period.
|
|
23
|
+
* The pattern prevents instant malicious updates by requiring:
|
|
24
|
+
* 1. submitUpdate() - Submit the source contract address, starts the timelock
|
|
25
|
+
* 2. Wait for the delay period to pass
|
|
26
|
+
* 3. applyUpdate() - Apply the update after the delay
|
|
27
|
+
*
|
|
28
|
+
* Users can monitor for UpdateSubmitted events and exit if they distrust pending changes.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* @final
|
|
33
|
+
* export class MyUpdatableContract extends Updatable {
|
|
34
|
+
* // Set a 24-hour delay (144 blocks at 10 min/block)
|
|
35
|
+
* protected readonly updateDelay: u64 = 144;
|
|
36
|
+
*
|
|
37
|
+
* public override execute(method: Selector, calldata: Calldata): BytesWriter {
|
|
38
|
+
* switch (method) {
|
|
39
|
+
* case encodeSelector('submitUpdate'):
|
|
40
|
+
* return this.submitUpdate(calldata.readAddress());
|
|
41
|
+
* case encodeSelector('applyUpdate'):
|
|
42
|
+
* const sourceAddress = calldata.readAddress();
|
|
43
|
+
* const updateCalldata = calldata.readBytesWithLength();
|
|
44
|
+
* return this.applyUpdate(sourceAddress, updateCalldata);
|
|
45
|
+
* case encodeSelector('cancelUpdate'):
|
|
46
|
+
* return this.cancelUpdate();
|
|
47
|
+
* default:
|
|
48
|
+
* return super.execute(method, calldata);
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export class Updatable extends OP_NET {
|
|
55
|
+
/**
|
|
56
|
+
* The pending update source address.
|
|
57
|
+
* Zero address means no pending update.
|
|
58
|
+
*/
|
|
59
|
+
protected readonly _pendingUpdateAddress: StoredAddress;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The block number when the update was submitted.
|
|
63
|
+
* Stored as u256, used as u64.
|
|
64
|
+
*/
|
|
65
|
+
protected readonly _pendingUpdateBlock: StoredU256;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The number of blocks to wait before an update can be applied.
|
|
69
|
+
* Override this in derived contracts to set the delay.
|
|
70
|
+
*
|
|
71
|
+
* Common values:
|
|
72
|
+
* - 6 blocks = ~1 hour
|
|
73
|
+
* - 144 blocks = ~24 hours
|
|
74
|
+
* - 1008 blocks = ~1 week
|
|
75
|
+
*/
|
|
76
|
+
protected readonly updateDelay: u64 = 144; // ~24 hours default
|
|
77
|
+
|
|
78
|
+
protected constructor() {
|
|
79
|
+
super();
|
|
80
|
+
this._pendingUpdateAddress = new StoredAddress(pendingUpdateAddressPointer);
|
|
81
|
+
this._pendingUpdateBlock = new StoredU256(pendingUpdateBlockPointer, EMPTY_POINTER);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns the pending update source address.
|
|
86
|
+
* Returns zero address if no update is pending.
|
|
87
|
+
*/
|
|
88
|
+
public get pendingUpdateAddress(): Address {
|
|
89
|
+
return this._pendingUpdateAddress.value;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Returns the block number when the pending update was submitted.
|
|
94
|
+
* Returns 0 if no update is pending.
|
|
95
|
+
*/
|
|
96
|
+
public get pendingUpdateBlock(): u64 {
|
|
97
|
+
return this._pendingUpdateBlock.value.lo1;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Returns the block number when the pending update can be applied.
|
|
102
|
+
* Returns 0 if no update is pending.
|
|
103
|
+
*/
|
|
104
|
+
public get updateEffectiveBlock(): u64 {
|
|
105
|
+
const submitBlock = this.pendingUpdateBlock;
|
|
106
|
+
if (submitBlock === 0) return 0;
|
|
107
|
+
return submitBlock + this.updateDelay;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns true if there is a pending update.
|
|
112
|
+
*/
|
|
113
|
+
public get hasPendingUpdate(): bool {
|
|
114
|
+
return this.pendingUpdateBlock !== 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns true if the pending update can be applied (delay has passed).
|
|
119
|
+
*/
|
|
120
|
+
public get canApplyUpdate(): bool {
|
|
121
|
+
if (!this.hasPendingUpdate) return false;
|
|
122
|
+
return Blockchain.block.number >= this.updateEffectiveBlock;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Submits an update for timelock.
|
|
127
|
+
*
|
|
128
|
+
* The source address must be a deployed contract containing the new bytecode.
|
|
129
|
+
* After submission, the update can only be applied after updateDelay blocks.
|
|
130
|
+
*
|
|
131
|
+
* Emits UpdateSubmitted event.
|
|
132
|
+
*
|
|
133
|
+
* @param sourceAddress - The source contract address containing new bytecode
|
|
134
|
+
* @returns Empty response
|
|
135
|
+
* @throws If caller is not deployer
|
|
136
|
+
* @throws If source is not a deployed contract
|
|
137
|
+
* @throws If an update is already pending
|
|
138
|
+
*/
|
|
139
|
+
protected submitUpdate(sourceAddress: Address): BytesWriter {
|
|
140
|
+
this.onlyDeployer(Blockchain.tx.sender);
|
|
141
|
+
|
|
142
|
+
// Check no pending update
|
|
143
|
+
if (this.hasPendingUpdate) {
|
|
144
|
+
throw new Revert('Update already pending. Cancel first.');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Validate source is a deployed contract
|
|
148
|
+
if (!Blockchain.isContract(sourceAddress)) {
|
|
149
|
+
throw new Revert('Source must be a deployed contract');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Store pending update
|
|
153
|
+
const currentBlock = Blockchain.block.number;
|
|
154
|
+
this._pendingUpdateAddress.value = sourceAddress;
|
|
155
|
+
this._pendingUpdateBlock.value = u256.fromU64(currentBlock);
|
|
156
|
+
|
|
157
|
+
// Emit event
|
|
158
|
+
const effectiveBlock = currentBlock + this.updateDelay;
|
|
159
|
+
Blockchain.emit(new UpdateSubmittedEvent(sourceAddress, currentBlock, effectiveBlock));
|
|
160
|
+
|
|
161
|
+
return new BytesWriter(0);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Applies a pending update after the timelock period has passed.
|
|
166
|
+
*
|
|
167
|
+
* The provided address must match the pending update address as an
|
|
168
|
+
* additional security measure against front-running attacks.
|
|
169
|
+
*
|
|
170
|
+
* Emits UpdateApplied event before the update (new bytecode takes effect next block).
|
|
171
|
+
*
|
|
172
|
+
* @param sourceAddress - The source contract address (must match pending)
|
|
173
|
+
* @param calldata - The calldata to pass to onUpdate method of the new contract
|
|
174
|
+
* @returns Empty response
|
|
175
|
+
* @throws If caller is not deployer
|
|
176
|
+
* @throws If no update is pending
|
|
177
|
+
* @throws If delay has not passed
|
|
178
|
+
* @throws If provided address does not match pending
|
|
179
|
+
*/
|
|
180
|
+
protected applyUpdate(sourceAddress: Address, calldata: BytesWriter): BytesWriter {
|
|
181
|
+
this.onlyDeployer(Blockchain.tx.sender);
|
|
182
|
+
|
|
183
|
+
// Check pending update exists
|
|
184
|
+
if (!this.hasPendingUpdate) {
|
|
185
|
+
throw new Revert('No pending update');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Check delay has passed
|
|
189
|
+
if (!this.canApplyUpdate) {
|
|
190
|
+
throw new Revert('Update delay not elapsed');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Verify address matches pending
|
|
194
|
+
if (!sourceAddress.equals(this._pendingUpdateAddress.value)) {
|
|
195
|
+
throw new Revert('Address does not match pending update');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Clear pending state before update
|
|
199
|
+
this._pendingUpdateAddress.value = Address.zero();
|
|
200
|
+
this._pendingUpdateBlock.value = u256.Zero;
|
|
201
|
+
|
|
202
|
+
// Emit event
|
|
203
|
+
Blockchain.emit(new UpdateAppliedEvent(sourceAddress, Blockchain.block.number));
|
|
204
|
+
|
|
205
|
+
// Perform update - new bytecode takes effect next block
|
|
206
|
+
Blockchain.updateContractFromExisting(sourceAddress, calldata);
|
|
207
|
+
|
|
208
|
+
return new BytesWriter(0);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Cancels a pending update.
|
|
213
|
+
*
|
|
214
|
+
* Can only be called by the deployer. Clears the pending update state.
|
|
215
|
+
*
|
|
216
|
+
* Emits UpdateCancelled event.
|
|
217
|
+
*
|
|
218
|
+
* @returns Empty response
|
|
219
|
+
* @throws If caller is not deployer
|
|
220
|
+
* @throws If no update is pending
|
|
221
|
+
*/
|
|
222
|
+
protected cancelUpdate(): BytesWriter {
|
|
223
|
+
this.onlyDeployer(Blockchain.tx.sender);
|
|
224
|
+
|
|
225
|
+
// Check pending update exists
|
|
226
|
+
if (!this.hasPendingUpdate) {
|
|
227
|
+
throw new Revert('No pending update');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const pendingAddress = this._pendingUpdateAddress.value;
|
|
231
|
+
|
|
232
|
+
// Clear pending state
|
|
233
|
+
this._pendingUpdateAddress.value = Address.zero();
|
|
234
|
+
this._pendingUpdateBlock.value = u256.Zero;
|
|
235
|
+
|
|
236
|
+
// Emit event
|
|
237
|
+
Blockchain.emit(new UpdateCancelledEvent(pendingAddress, Blockchain.block.number));
|
|
238
|
+
|
|
239
|
+
return new BytesWriter(0);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -6,10 +6,10 @@ export class OP721InitParameters {
|
|
|
6
6
|
public baseURI: string;
|
|
7
7
|
public maxSupply: u256;
|
|
8
8
|
|
|
9
|
-
public
|
|
10
|
-
public
|
|
11
|
-
public
|
|
12
|
-
public
|
|
9
|
+
public banner: string;
|
|
10
|
+
public icon: string;
|
|
11
|
+
public website: string;
|
|
12
|
+
public description: string;
|
|
13
13
|
|
|
14
14
|
constructor(
|
|
15
15
|
name: string,
|
|
@@ -26,9 +26,9 @@ export class OP721InitParameters {
|
|
|
26
26
|
this.baseURI = baseURI;
|
|
27
27
|
this.maxSupply = maxSupply;
|
|
28
28
|
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
29
|
+
this.banner = collectionBanner;
|
|
30
|
+
this.icon = collectionIcon;
|
|
31
|
+
this.website = collectionWebsite;
|
|
32
|
+
this.description = collectionDescription;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -610,7 +610,7 @@ export class BlockchainEnvironment {
|
|
|
610
610
|
* @example
|
|
611
611
|
* ```typescript
|
|
612
612
|
* // Simple immediate update (not recommended for production)
|
|
613
|
-
* public
|
|
613
|
+
* public update(calldata: Calldata): BytesWriter {
|
|
614
614
|
* this.onlyDeployer(Blockchain.tx.sender);
|
|
615
615
|
* const newBytecodeAddress = calldata.readAddress();
|
|
616
616
|
* Blockchain.updateContractFromExisting(newBytecodeAddress);
|
|
@@ -675,12 +675,12 @@ export class BlockchainEnvironment {
|
|
|
675
675
|
throw new Revert('Source address must be a deployed contract');
|
|
676
676
|
}
|
|
677
677
|
|
|
678
|
-
const
|
|
678
|
+
const calldataBuffer = calldata ? calldata.getBuffer().buffer : new ArrayBuffer(0);
|
|
679
679
|
|
|
680
680
|
const status = updateFromAddress(
|
|
681
681
|
sourceAddress.buffer,
|
|
682
|
-
|
|
683
|
-
|
|
682
|
+
calldataBuffer,
|
|
683
|
+
calldataBuffer.byteLength,
|
|
684
684
|
);
|
|
685
685
|
|
|
686
686
|
if (status !== 0) {
|
|
@@ -903,7 +903,7 @@ export class BlockchainEnvironment {
|
|
|
903
903
|
* The `unsafeSignaturesAllowed()` flag indicates whether the network is still accepting
|
|
904
904
|
* legacy Schnorr signatures. This flag will be `true` during the transition period to
|
|
905
905
|
* maintain backwards compatibility with existing infrastructure. Once the network completes
|
|
906
|
-
* its quantum-resistant
|
|
906
|
+
* its quantum-resistant update, this flag will permanently become `false`, enforcing
|
|
907
907
|
* ML-DSA signatures exclusively.
|
|
908
908
|
*
|
|
909
909
|
* @param address - The address containing the public key(s) to verify against.
|
package/runtime/env/global.ts
CHANGED
|
@@ -244,17 +244,18 @@ export declare function getOutputsSize(): u32;
|
|
|
244
244
|
*
|
|
245
245
|
* The signature algorithm is determined by the public key format:
|
|
246
246
|
* - First byte indicates the signature type:
|
|
247
|
-
* - 0x00:
|
|
248
|
-
* - 0x01:
|
|
247
|
+
* - 0x00: ECDSA signature
|
|
248
|
+
* - 0x01: Schnorr signature (33 bytes total - type byte + 32-byte x-only public key)
|
|
249
|
+
* - 0x02: ML-DSA signature (variable length based on security level)
|
|
249
250
|
*
|
|
250
251
|
* For Schnorr signatures:
|
|
251
|
-
* - Public key format: [
|
|
252
|
+
* - Public key format: [0x01] + [32-byte x-only public key] (33 bytes total)
|
|
252
253
|
* - Signature: 64 bytes
|
|
253
254
|
* - Message: 32 bytes (typically a hash)
|
|
254
255
|
* - Note: Schnorr signatures are only allowed when UNSAFE_QUANTUM_SIGNATURES_ALLOWED consensus flag is set
|
|
255
256
|
*
|
|
256
257
|
* For ML-DSA signatures (quantum-resistant):
|
|
257
|
-
* - Public key format: [
|
|
258
|
+
* - Public key format: [0x02] + [level byte] + [public key data]
|
|
258
259
|
* - Level 0x00: ML-DSA-44 (1313 bytes total - 1 header byte + 1312 key bytes)
|
|
259
260
|
* - Level 0x01: ML-DSA-65 (1955 bytes total - 1 header byte + 1952 key bytes)
|
|
260
261
|
* - Level 0x02: ML-DSA-87 (2593 bytes total - 1 header byte + 2592 key bytes)
|
|
@@ -268,7 +269,7 @@ export declare function getOutputsSize(): u32;
|
|
|
268
269
|
* ```typescript
|
|
269
270
|
* // Schnorr signature verification
|
|
270
271
|
* const writer = new BytesWriter(33);
|
|
271
|
-
* writer.writeU8(
|
|
272
|
+
* writer.writeU8(0x01); // Schnorr type
|
|
272
273
|
* writer.writeBytes(xOnlyPublicKey); // 32-byte x-only public key
|
|
273
274
|
*
|
|
274
275
|
* const publicKey = writer.getBuffer().buffer;
|
|
@@ -282,7 +283,7 @@ export declare function getOutputsSize(): u32;
|
|
|
282
283
|
* ```typescript
|
|
283
284
|
* // ML-DSA-44 signature verification
|
|
284
285
|
* const writer = new BytesWriter(1314);
|
|
285
|
-
* writer.writeU8(
|
|
286
|
+
* writer.writeU8(0x02); // ML-DSA type
|
|
286
287
|
* writer.writeU8(0x00); // ML-DSA-44 level
|
|
287
288
|
* writer.writeBytes(mldsaPublicKey); // 1312-byte public key
|
|
288
289
|
*
|
|
@@ -5,7 +5,7 @@ import { ADDRESS_BYTE_LENGTH, U256_BYTE_LENGTH } from '../../utils';
|
|
|
5
5
|
import { NetEvent } from '../NetEvent';
|
|
6
6
|
|
|
7
7
|
@final
|
|
8
|
-
export class
|
|
8
|
+
export class OP20ApprovedEvent extends NetEvent {
|
|
9
9
|
constructor(owner: Address, spender: Address, amount: u256) {
|
|
10
10
|
const data: BytesWriter = new BytesWriter(ADDRESS_BYTE_LENGTH * 2 + U256_BYTE_LENGTH);
|
|
11
11
|
data.writeAddress(owner);
|
|
@@ -5,7 +5,7 @@ import { NetEvent } from '../NetEvent';
|
|
|
5
5
|
import { Address } from '../../types/Address';
|
|
6
6
|
|
|
7
7
|
@final
|
|
8
|
-
export class
|
|
8
|
+
export class OP20BurnedEvent extends NetEvent {
|
|
9
9
|
constructor(from: Address, amount: u256) {
|
|
10
10
|
const data: BytesWriter = new BytesWriter(ADDRESS_BYTE_LENGTH + U256_BYTE_LENGTH);
|
|
11
11
|
data.writeAddress(from);
|
|
@@ -5,7 +5,7 @@ import { ADDRESS_BYTE_LENGTH, U256_BYTE_LENGTH } from '../../utils';
|
|
|
5
5
|
import { NetEvent } from '../NetEvent';
|
|
6
6
|
|
|
7
7
|
@final
|
|
8
|
-
export class
|
|
8
|
+
export class OP20MintedEvent extends NetEvent {
|
|
9
9
|
constructor(to: Address, amount: u256) {
|
|
10
10
|
const data: BytesWriter = new BytesWriter(ADDRESS_BYTE_LENGTH + U256_BYTE_LENGTH);
|
|
11
11
|
data.writeAddress(to);
|
|
@@ -5,7 +5,7 @@ import { ADDRESS_BYTE_LENGTH, U256_BYTE_LENGTH } from '../../utils';
|
|
|
5
5
|
import { NetEvent } from '../NetEvent';
|
|
6
6
|
|
|
7
7
|
@final
|
|
8
|
-
export class
|
|
8
|
+
export class OP20TransferredEvent extends NetEvent {
|
|
9
9
|
constructor(operator: Address, from: Address, to: Address, amount: u256) {
|
|
10
10
|
const data: BytesWriter = new BytesWriter(ADDRESS_BYTE_LENGTH * 3 + U256_BYTE_LENGTH);
|
|
11
11
|
data.writeAddress(operator);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { u256 } from '@btc-vision/as-bignum/assembly';
|
|
2
|
+
import { BytesWriter } from '../../buffer/BytesWriter';
|
|
3
|
+
import { Address } from '../../types/Address';
|
|
4
|
+
import { ADDRESS_BYTE_LENGTH, U256_BYTE_LENGTH } from '../../utils';
|
|
5
|
+
import { NetEvent } from '../NetEvent';
|
|
6
|
+
|
|
7
|
+
@final
|
|
8
|
+
export class OP721ApprovedEvent extends NetEvent {
|
|
9
|
+
constructor(owner: Address, operator: Address, tokenId: u256) {
|
|
10
|
+
const data: BytesWriter = new BytesWriter(ADDRESS_BYTE_LENGTH * 2 + U256_BYTE_LENGTH);
|
|
11
|
+
data.writeAddress(owner);
|
|
12
|
+
data.writeAddress(operator);
|
|
13
|
+
data.writeU256(tokenId);
|
|
14
|
+
|
|
15
|
+
super('Approved', data);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -4,7 +4,7 @@ import { Address } from '../../types/Address';
|
|
|
4
4
|
import { ADDRESS_BYTE_LENGTH } from '../../utils';
|
|
5
5
|
|
|
6
6
|
@final
|
|
7
|
-
export class
|
|
7
|
+
export class OP721ApprovedForAllEvent extends NetEvent {
|
|
8
8
|
constructor(account: Address, operator: Address, approved: boolean) {
|
|
9
9
|
const writer = new BytesWriter(ADDRESS_BYTE_LENGTH * 2 + 1);
|
|
10
10
|
writer.writeAddress(account);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { u256 } from '@btc-vision/as-bignum/assembly';
|
|
2
|
+
import { BytesWriter } from '../../buffer/BytesWriter';
|
|
3
|
+
import { ADDRESS_BYTE_LENGTH, U256_BYTE_LENGTH } from '../../utils';
|
|
4
|
+
import { NetEvent } from '../NetEvent';
|
|
5
|
+
import { Address } from '../../types/Address';
|
|
6
|
+
|
|
7
|
+
@final
|
|
8
|
+
export class OP721BurnedEvent extends NetEvent {
|
|
9
|
+
constructor(from: Address, amount: u256) {
|
|
10
|
+
const data: BytesWriter = new BytesWriter(ADDRESS_BYTE_LENGTH + U256_BYTE_LENGTH);
|
|
11
|
+
data.writeAddress(from);
|
|
12
|
+
data.writeU256(amount);
|
|
13
|
+
|
|
14
|
+
super('Burned', data);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { u256 } from '@btc-vision/as-bignum/assembly';
|
|
2
|
+
import { BytesWriter } from '../../buffer/BytesWriter';
|
|
3
|
+
import { Address } from '../../types/Address';
|
|
4
|
+
import { ADDRESS_BYTE_LENGTH, U256_BYTE_LENGTH } from '../../utils';
|
|
5
|
+
import { NetEvent } from '../NetEvent';
|
|
6
|
+
|
|
7
|
+
@final
|
|
8
|
+
export class OP721MintedEvent extends NetEvent {
|
|
9
|
+
constructor(to: Address, amount: u256) {
|
|
10
|
+
const data: BytesWriter = new BytesWriter(ADDRESS_BYTE_LENGTH + U256_BYTE_LENGTH);
|
|
11
|
+
data.writeAddress(to);
|
|
12
|
+
data.writeU256(amount);
|
|
13
|
+
|
|
14
|
+
super('Minted', data);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { u256 } from '@btc-vision/as-bignum/assembly';
|
|
2
|
+
import { BytesWriter } from '../../buffer/BytesWriter';
|
|
3
|
+
import { Address } from '../../types/Address';
|
|
4
|
+
import { ADDRESS_BYTE_LENGTH, U256_BYTE_LENGTH } from '../../utils';
|
|
5
|
+
import { NetEvent } from '../NetEvent';
|
|
6
|
+
|
|
7
|
+
@final
|
|
8
|
+
export class OP721TransferredEvent extends NetEvent {
|
|
9
|
+
constructor(operator: Address, from: Address, to: Address, tokenId: u256) {
|
|
10
|
+
const data: BytesWriter = new BytesWriter(ADDRESS_BYTE_LENGTH * 3 + U256_BYTE_LENGTH);
|
|
11
|
+
data.writeAddress(operator);
|
|
12
|
+
data.writeAddress(from);
|
|
13
|
+
data.writeAddress(to);
|
|
14
|
+
data.writeU256(tokenId);
|
|
15
|
+
|
|
16
|
+
super('Transferred', data);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './OP20ApprovedEvent';
|
|
2
|
+
export * from './OP20BurnedEvent';
|
|
3
|
+
export * from './OP20MintedEvent';
|
|
4
|
+
export * from './OP20TransferredEvent';
|
|
5
|
+
export * from './OP721ApprovedForAllEvent';
|
|
6
6
|
export * from './URIEvent';
|
|
7
7
|
export * from './TransferredBatchEvent';
|
|
8
8
|
export * from './TransferredSingleEvent';
|
|
@@ -4,38 +4,38 @@ import { Address } from '../../types/Address';
|
|
|
4
4
|
import { ADDRESS_BYTE_LENGTH } from '../../utils';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Event emitted when an
|
|
7
|
+
* Event emitted when an update is submitted for timelock.
|
|
8
8
|
*/
|
|
9
|
-
export class
|
|
9
|
+
export class UpdateSubmittedEvent extends NetEvent {
|
|
10
10
|
constructor(sourceAddress: Address, submitBlock: u64, effectiveBlock: u64) {
|
|
11
11
|
const data = new BytesWriter(ADDRESS_BYTE_LENGTH + 16);
|
|
12
12
|
data.writeAddress(sourceAddress);
|
|
13
13
|
data.writeU64(submitBlock);
|
|
14
14
|
data.writeU64(effectiveBlock);
|
|
15
|
-
super('
|
|
15
|
+
super('UpdateSubmitted', data);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Event emitted when an
|
|
20
|
+
* Event emitted when an update is applied.
|
|
21
21
|
*/
|
|
22
|
-
export class
|
|
22
|
+
export class UpdateAppliedEvent extends NetEvent {
|
|
23
23
|
constructor(sourceAddress: Address, appliedAtBlock: u64) {
|
|
24
24
|
const data = new BytesWriter(ADDRESS_BYTE_LENGTH + 8);
|
|
25
25
|
data.writeAddress(sourceAddress);
|
|
26
26
|
data.writeU64(appliedAtBlock);
|
|
27
|
-
super('
|
|
27
|
+
super('UpdateApplied', data);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Event emitted when a pending
|
|
32
|
+
* Event emitted when a pending update is cancelled.
|
|
33
33
|
*/
|
|
34
|
-
export class
|
|
34
|
+
export class UpdateCancelledEvent extends NetEvent {
|
|
35
35
|
constructor(sourceAddress: Address, cancelledAtBlock: u64) {
|
|
36
36
|
const data = new BytesWriter(ADDRESS_BYTE_LENGTH + 8);
|
|
37
37
|
data.writeAddress(sourceAddress);
|
|
38
38
|
data.writeU64(cancelledAtBlock);
|
|
39
|
-
super('
|
|
39
|
+
super('UpdateCancelled', data);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Keccak-256 implementation for
|
|
2
|
+
* Keccak-256 implementation for OP_NET (AssemblyScript / btc-runtime compatible)
|
|
3
3
|
*
|
|
4
4
|
* This implements the ORIGINAL Keccak-256 as used by Ethereum (pre-NIST),
|
|
5
5
|
* NOT the NIST SHA-3-256 standard. The difference is the domain separation
|
package/runtime/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ export * from './interfaces/IBTC';
|
|
|
20
20
|
export * from './events/NetEvent';
|
|
21
21
|
export * from './events/predefined';
|
|
22
22
|
export * from './events/op20s/OP20SEvents';
|
|
23
|
-
export * from './events/
|
|
23
|
+
export * from './events/updatable/UpdatableEvents';
|
|
24
24
|
|
|
25
25
|
/** Env */
|
|
26
26
|
export * from './env/classes/UTXO';
|
|
@@ -109,12 +109,10 @@ export * from './script/Segwit';
|
|
|
109
109
|
export * from './constants/Exports';
|
|
110
110
|
export * from './contracts/OP721';
|
|
111
111
|
export * from './contracts/interfaces/IOP721';
|
|
112
|
-
export * from './contracts/interfaces/IOP1155';
|
|
113
112
|
export * from './contracts/interfaces/OP721InitParameters';
|
|
114
113
|
export * from './contracts/ReentrancyGuard';
|
|
115
|
-
export * from './contracts/
|
|
116
|
-
export * from './contracts/interfaces/OP1155InitParameters';
|
|
114
|
+
export * from './contracts/Updatable';
|
|
117
115
|
|
|
118
116
|
/** Plugins */
|
|
119
117
|
export * from './plugins/Plugin';
|
|
120
|
-
export * from './plugins/
|
|
118
|
+
export * from './plugins/UpdatablePlugin';
|