@mysten/sui 2.33.1 → 2.34.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/CHANGELOG.md +24 -0
- package/README.md +8 -4
- package/dist/bcs/index.d.mts +36 -36
- package/dist/faucet/faucet-v3.d.mts +34 -0
- package/dist/faucet/faucet-v3.d.mts.map +1 -0
- package/dist/faucet/faucet-v3.mjs +77 -0
- package/dist/faucet/faucet-v3.mjs.map +1 -0
- package/dist/faucet/index.d.mts +2 -1
- package/dist/faucet/index.mjs +2 -1
- package/dist/faucet/pow.mjs +96 -0
- package/dist/faucet/pow.mjs.map +1 -0
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +4 -2
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +7 -1
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
- package/dist/transactions/Transaction.d.mts +3 -3
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/docs/index.md +47 -7
- package/package.json +4 -4
- package/src/faucet/faucet-v3.ts +133 -0
- package/src/faucet/index.ts +2 -0
- package/src/faucet/pow.ts +172 -0
- package/src/graphql/core.ts +8 -11
- package/src/grpc/core.ts +16 -14
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @mysten/sui.js
|
|
2
2
|
|
|
3
|
+
## 2.34.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 953e584: Add `requestSuiFromFaucetV3` for proof-of-work faucets on devnet, testnet, and localnet.
|
|
8
|
+
The helper fetches and validates a challenge, computes Argon2d proof-of-work, and submits it to
|
|
9
|
+
`/v3/gas`, with cancellation and a configurable timeout. Export `FaucetResponseV3` and
|
|
10
|
+
`FaucetError`, including server error codes and transaction digests.
|
|
11
|
+
|
|
12
|
+
Use Node's asynchronous native Argon2d when available, with Noble as the fallback for Node 22 and
|
|
13
|
+
browsers.
|
|
14
|
+
|
|
15
|
+
Use V3 for devnet/testnet and local PoW faucets. Keep using `requestSuiFromFaucetV2` for local
|
|
16
|
+
no-PoW faucets. V3 pays into address balances and returns `digest` and `amountMist` instead of
|
|
17
|
+
`coins_sent`. Payout submissions are not automatically retried.
|
|
18
|
+
|
|
19
|
+
## 2.33.2
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- d6ba632: `client.core.defaultNameServiceName` now returns `{ data: { name: null } }` for an
|
|
24
|
+
address without a default SuiNS name on the gRPC and GraphQL clients, matching JSON-RPC.
|
|
25
|
+
Previously gRPC threw a `NOT_FOUND` `RpcError` and GraphQL threw `Missing response data`.
|
|
26
|
+
|
|
3
27
|
## 2.33.1
|
|
4
28
|
|
|
5
29
|
## 2.33.0
|
package/README.md
CHANGED
|
@@ -133,18 +133,22 @@ await client.listCoins({
|
|
|
133
133
|
|
|
134
134
|
## Getting coins from the faucet
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
Use `requestSuiFromFaucetV3` on devnet and testnet. It fetches a challenge, computes proof-of-work,
|
|
137
|
+
and submits the proof to `/v3/gas`. The payout credits the recipient's address balance.
|
|
138
138
|
|
|
139
139
|
```typescript
|
|
140
|
-
import { getFaucetHost,
|
|
140
|
+
import { getFaucetHost, requestSuiFromFaucetV3 } from '@mysten/sui/faucet';
|
|
141
141
|
|
|
142
|
-
await
|
|
142
|
+
const result = await requestSuiFromFaucetV3({
|
|
143
143
|
host: getFaucetHost('devnet'),
|
|
144
144
|
recipient: '0xcc2bd176a478baea9a0de7a24cd927661cc6e860d5bacecb9a138ef20dbab231',
|
|
145
145
|
});
|
|
146
|
+
console.log(result.digest, result.amountMist);
|
|
146
147
|
```
|
|
147
148
|
|
|
149
|
+
For localnet, use `requestSuiFromFaucetV2` with `getFaucetHost('localnet')` for a no-PoW faucet
|
|
150
|
+
(`/v2/gas`). Use `requestSuiFromFaucetV3` with the local PoW faucet's host for `/v3/gas`.
|
|
151
|
+
|
|
148
152
|
## Writing APIs
|
|
149
153
|
|
|
150
154
|
For a primer for building transactions, refer to
|
package/dist/bcs/index.d.mts
CHANGED
|
@@ -549,7 +549,7 @@ declare const suiBcs: {
|
|
|
549
549
|
version: string;
|
|
550
550
|
digest: string;
|
|
551
551
|
};
|
|
552
|
-
}, "
|
|
552
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
553
553
|
FundsWithdrawal: {
|
|
554
554
|
reservation: {
|
|
555
555
|
MaxAmountU64: string;
|
|
@@ -568,7 +568,7 @@ declare const suiBcs: {
|
|
|
568
568
|
};
|
|
569
569
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
570
570
|
};
|
|
571
|
-
}, "
|
|
571
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
572
572
|
Pure: {
|
|
573
573
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
574
574
|
};
|
|
@@ -805,7 +805,7 @@ declare const suiBcs: {
|
|
|
805
805
|
TransactionEffects: true;
|
|
806
806
|
CheckpointSummary: true;
|
|
807
807
|
PersonalMessage: true;
|
|
808
|
-
}, "
|
|
808
|
+
}, "TransactionEffects" | "TransactionData" | "CheckpointSummary" | "PersonalMessage">;
|
|
809
809
|
version: {
|
|
810
810
|
V0: true;
|
|
811
811
|
$kind: "V0";
|
|
@@ -839,7 +839,7 @@ declare const suiBcs: {
|
|
|
839
839
|
version: string;
|
|
840
840
|
digest: string;
|
|
841
841
|
};
|
|
842
|
-
}, "
|
|
842
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
843
843
|
FundsWithdrawal: {
|
|
844
844
|
reservation: {
|
|
845
845
|
MaxAmountU64: string;
|
|
@@ -858,7 +858,7 @@ declare const suiBcs: {
|
|
|
858
858
|
};
|
|
859
859
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
860
860
|
};
|
|
861
|
-
}, "
|
|
861
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[];
|
|
862
862
|
commands: _mysten_bcs0.EnumOutputShapeWithKeys<{
|
|
863
863
|
MoveCall: {
|
|
864
864
|
package: string;
|
|
@@ -997,7 +997,7 @@ declare const suiBcs: {
|
|
|
997
997
|
startVersion: string;
|
|
998
998
|
owner: string;
|
|
999
999
|
};
|
|
1000
|
-
}, "AddressOwner" | "
|
|
1000
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">;
|
|
1001
1001
|
};
|
|
1002
1002
|
$kind: "RawObject";
|
|
1003
1003
|
}[];
|
|
@@ -1130,7 +1130,7 @@ declare const suiBcs: {
|
|
|
1130
1130
|
version: string;
|
|
1131
1131
|
digest: string;
|
|
1132
1132
|
};
|
|
1133
|
-
}, "
|
|
1133
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
1134
1134
|
FundsWithdrawal: {
|
|
1135
1135
|
reservation: {
|
|
1136
1136
|
MaxAmountU64: string;
|
|
@@ -1149,7 +1149,7 @@ declare const suiBcs: {
|
|
|
1149
1149
|
};
|
|
1150
1150
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
1151
1151
|
};
|
|
1152
|
-
}, "
|
|
1152
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[];
|
|
1153
1153
|
commands: _mysten_bcs0.EnumOutputShapeWithKeys<{
|
|
1154
1154
|
MoveCall: {
|
|
1155
1155
|
package: string;
|
|
@@ -1231,7 +1231,7 @@ declare const suiBcs: {
|
|
|
1231
1231
|
};
|
|
1232
1232
|
}, "MoveCall" | "TransferObjects" | "SplitCoins" | "MergeCoins" | "Publish" | "MakeMoveVec" | "Upgrade">[];
|
|
1233
1233
|
};
|
|
1234
|
-
}, "
|
|
1234
|
+
}, "EndOfEpochTransaction" | "ProgrammableSystemTransaction" | "ProgrammableTransaction" | "ChangeEpoch" | "Genesis" | "ConsensusCommitPrologue" | "AuthenticatorStateUpdate" | "RandomnessStateUpdate" | "ConsensusCommitPrologueV2" | "ConsensusCommitPrologueV3" | "ConsensusCommitPrologueV4">;
|
|
1235
1235
|
sender: string;
|
|
1236
1236
|
gasData: {
|
|
1237
1237
|
payment: {
|
|
@@ -1266,7 +1266,7 @@ declare const suiBcs: {
|
|
|
1266
1266
|
proposers: number[];
|
|
1267
1267
|
} | null;
|
|
1268
1268
|
};
|
|
1269
|
-
}, "
|
|
1269
|
+
}, "Epoch" | "None" | "ValidDuring" | "Validity">;
|
|
1270
1270
|
};
|
|
1271
1271
|
$kind: "V1";
|
|
1272
1272
|
};
|
|
@@ -1877,7 +1877,7 @@ declare const suiBcs: {
|
|
|
1877
1877
|
version: string;
|
|
1878
1878
|
digest: string;
|
|
1879
1879
|
};
|
|
1880
|
-
}, "
|
|
1880
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
1881
1881
|
FundsWithdrawal: {
|
|
1882
1882
|
reservation: {
|
|
1883
1883
|
MaxAmountU64: string;
|
|
@@ -1896,7 +1896,7 @@ declare const suiBcs: {
|
|
|
1896
1896
|
};
|
|
1897
1897
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
1898
1898
|
};
|
|
1899
|
-
}, "
|
|
1899
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
1900
1900
|
Pure: {
|
|
1901
1901
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
1902
1902
|
};
|
|
@@ -2181,7 +2181,7 @@ declare const suiBcs: {
|
|
|
2181
2181
|
startVersion: string;
|
|
2182
2182
|
owner: string;
|
|
2183
2183
|
};
|
|
2184
|
-
}, "AddressOwner" | "
|
|
2184
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">;
|
|
2185
2185
|
};
|
|
2186
2186
|
$kind: "RawObject";
|
|
2187
2187
|
}[], Iterable<{
|
|
@@ -2459,7 +2459,7 @@ declare const suiBcs: {
|
|
|
2459
2459
|
version: string;
|
|
2460
2460
|
digest: string;
|
|
2461
2461
|
};
|
|
2462
|
-
}, "
|
|
2462
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
2463
2463
|
FundsWithdrawal: {
|
|
2464
2464
|
reservation: {
|
|
2465
2465
|
MaxAmountU64: string;
|
|
@@ -2478,7 +2478,7 @@ declare const suiBcs: {
|
|
|
2478
2478
|
};
|
|
2479
2479
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
2480
2480
|
};
|
|
2481
|
-
}, "
|
|
2481
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
2482
2482
|
Pure: {
|
|
2483
2483
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
2484
2484
|
};
|
|
@@ -2794,7 +2794,7 @@ declare const suiBcs: {
|
|
|
2794
2794
|
version: string;
|
|
2795
2795
|
digest: string;
|
|
2796
2796
|
};
|
|
2797
|
-
}, "
|
|
2797
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
2798
2798
|
FundsWithdrawal: {
|
|
2799
2799
|
reservation: {
|
|
2800
2800
|
MaxAmountU64: string;
|
|
@@ -2813,7 +2813,7 @@ declare const suiBcs: {
|
|
|
2813
2813
|
};
|
|
2814
2814
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
2815
2815
|
};
|
|
2816
|
-
}, "
|
|
2816
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
2817
2817
|
Pure: {
|
|
2818
2818
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
2819
2819
|
};
|
|
@@ -3098,7 +3098,7 @@ declare const suiBcs: {
|
|
|
3098
3098
|
startVersion: string;
|
|
3099
3099
|
owner: string;
|
|
3100
3100
|
};
|
|
3101
|
-
}, "AddressOwner" | "
|
|
3101
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">;
|
|
3102
3102
|
};
|
|
3103
3103
|
$kind: "RawObject";
|
|
3104
3104
|
}[], Iterable<{
|
|
@@ -3376,7 +3376,7 @@ declare const suiBcs: {
|
|
|
3376
3376
|
version: string;
|
|
3377
3377
|
digest: string;
|
|
3378
3378
|
};
|
|
3379
|
-
}, "
|
|
3379
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
3380
3380
|
FundsWithdrawal: {
|
|
3381
3381
|
reservation: {
|
|
3382
3382
|
MaxAmountU64: string;
|
|
@@ -3395,7 +3395,7 @@ declare const suiBcs: {
|
|
|
3395
3395
|
};
|
|
3396
3396
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
3397
3397
|
};
|
|
3398
|
-
}, "
|
|
3398
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
3399
3399
|
Pure: {
|
|
3400
3400
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
3401
3401
|
};
|
|
@@ -3687,7 +3687,7 @@ declare const suiBcs: {
|
|
|
3687
3687
|
version: string;
|
|
3688
3688
|
digest: string;
|
|
3689
3689
|
};
|
|
3690
|
-
}, "
|
|
3690
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
3691
3691
|
FundsWithdrawal: {
|
|
3692
3692
|
reservation: {
|
|
3693
3693
|
MaxAmountU64: string;
|
|
@@ -3706,7 +3706,7 @@ declare const suiBcs: {
|
|
|
3706
3706
|
};
|
|
3707
3707
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
3708
3708
|
};
|
|
3709
|
-
}, "
|
|
3709
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
3710
3710
|
Pure: {
|
|
3711
3711
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
3712
3712
|
};
|
|
@@ -3991,7 +3991,7 @@ declare const suiBcs: {
|
|
|
3991
3991
|
startVersion: string;
|
|
3992
3992
|
owner: string;
|
|
3993
3993
|
};
|
|
3994
|
-
}, "AddressOwner" | "
|
|
3994
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">;
|
|
3995
3995
|
};
|
|
3996
3996
|
$kind: "RawObject";
|
|
3997
3997
|
}[], Iterable<{
|
|
@@ -4269,7 +4269,7 @@ declare const suiBcs: {
|
|
|
4269
4269
|
version: string;
|
|
4270
4270
|
digest: string;
|
|
4271
4271
|
};
|
|
4272
|
-
}, "
|
|
4272
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
4273
4273
|
FundsWithdrawal: {
|
|
4274
4274
|
reservation: {
|
|
4275
4275
|
MaxAmountU64: string;
|
|
@@ -4288,7 +4288,7 @@ declare const suiBcs: {
|
|
|
4288
4288
|
};
|
|
4289
4289
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
4290
4290
|
};
|
|
4291
|
-
}, "
|
|
4291
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
4292
4292
|
Pure: {
|
|
4293
4293
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
4294
4294
|
};
|
|
@@ -4762,7 +4762,7 @@ declare const suiBcs: {
|
|
|
4762
4762
|
startVersion: string;
|
|
4763
4763
|
owner: string;
|
|
4764
4764
|
};
|
|
4765
|
-
}, "AddressOwner" | "
|
|
4765
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">][], Iterable<readonly [{
|
|
4766
4766
|
objectId: string | Uint8Array<ArrayBufferLike>;
|
|
4767
4767
|
version: string | number | bigint;
|
|
4768
4768
|
digest: string;
|
|
@@ -4795,7 +4795,7 @@ declare const suiBcs: {
|
|
|
4795
4795
|
startVersion: string;
|
|
4796
4796
|
owner: string;
|
|
4797
4797
|
};
|
|
4798
|
-
}, "AddressOwner" | "
|
|
4798
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">][], Iterable<readonly [{
|
|
4799
4799
|
objectId: string | Uint8Array<ArrayBufferLike>;
|
|
4800
4800
|
version: string | number | bigint;
|
|
4801
4801
|
digest: string;
|
|
@@ -4828,7 +4828,7 @@ declare const suiBcs: {
|
|
|
4828
4828
|
startVersion: string;
|
|
4829
4829
|
owner: string;
|
|
4830
4830
|
};
|
|
4831
|
-
}, "AddressOwner" | "
|
|
4831
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">][], Iterable<readonly [{
|
|
4832
4832
|
objectId: string | Uint8Array<ArrayBufferLike>;
|
|
4833
4833
|
version: string | number | bigint;
|
|
4834
4834
|
digest: string;
|
|
@@ -5096,7 +5096,7 @@ declare const suiBcs: {
|
|
|
5096
5096
|
startVersion: string;
|
|
5097
5097
|
owner: string;
|
|
5098
5098
|
};
|
|
5099
|
-
}, "AddressOwner" | "
|
|
5099
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">];
|
|
5100
5100
|
}, "NotExist" | "Exist">;
|
|
5101
5101
|
outputState: _mysten_bcs0.EnumOutputShapeWithKeys<{
|
|
5102
5102
|
NotExist: true;
|
|
@@ -5111,7 +5111,7 @@ declare const suiBcs: {
|
|
|
5111
5111
|
startVersion: string;
|
|
5112
5112
|
owner: string;
|
|
5113
5113
|
};
|
|
5114
|
-
}, "AddressOwner" | "
|
|
5114
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">];
|
|
5115
5115
|
PackageWrite: [string, string];
|
|
5116
5116
|
AccumulatorWriteV1: {
|
|
5117
5117
|
address: {
|
|
@@ -5197,7 +5197,7 @@ declare const suiBcs: {
|
|
|
5197
5197
|
ReadConsensusStreamEnded: string;
|
|
5198
5198
|
Cancelled: string;
|
|
5199
5199
|
PerEpochConfig: true;
|
|
5200
|
-
}, "
|
|
5200
|
+
}, "MutateConsensusStreamEnded" | "PerEpochConfig" | "ReadConsensusStreamEnded" | "ReadOnlyRoot" | "Cancelled">][], Iterable<readonly [string | Uint8Array<ArrayBufferLike>, _mysten_bcs0.EnumInputShape<{
|
|
5201
5201
|
ReadOnlyRoot: readonly [string | number | bigint, string];
|
|
5202
5202
|
MutateConsensusStreamEnded: string | number | bigint;
|
|
5203
5203
|
ReadConsensusStreamEnded: string | number | bigint;
|
|
@@ -5258,7 +5258,7 @@ declare const suiBcs: {
|
|
|
5258
5258
|
version: string;
|
|
5259
5259
|
digest: string;
|
|
5260
5260
|
};
|
|
5261
|
-
}, "
|
|
5261
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
5262
5262
|
FundsWithdrawal: {
|
|
5263
5263
|
reservation: {
|
|
5264
5264
|
MaxAmountU64: string;
|
|
@@ -5277,7 +5277,7 @@ declare const suiBcs: {
|
|
|
5277
5277
|
};
|
|
5278
5278
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
5279
5279
|
};
|
|
5280
|
-
}, "
|
|
5280
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
5281
5281
|
Pure: {
|
|
5282
5282
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
5283
5283
|
};
|
|
@@ -5562,7 +5562,7 @@ declare const suiBcs: {
|
|
|
5562
5562
|
startVersion: string;
|
|
5563
5563
|
owner: string;
|
|
5564
5564
|
};
|
|
5565
|
-
}, "AddressOwner" | "
|
|
5565
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">;
|
|
5566
5566
|
};
|
|
5567
5567
|
$kind: "RawObject";
|
|
5568
5568
|
}[], Iterable<{
|
|
@@ -5840,7 +5840,7 @@ declare const suiBcs: {
|
|
|
5840
5840
|
version: string;
|
|
5841
5841
|
digest: string;
|
|
5842
5842
|
};
|
|
5843
|
-
}, "
|
|
5843
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
5844
5844
|
FundsWithdrawal: {
|
|
5845
5845
|
reservation: {
|
|
5846
5846
|
MaxAmountU64: string;
|
|
@@ -5859,7 +5859,7 @@ declare const suiBcs: {
|
|
|
5859
5859
|
};
|
|
5860
5860
|
}, "Sender" | "Sponsor" | "SenderAllowance">;
|
|
5861
5861
|
};
|
|
5862
|
-
}, "
|
|
5862
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
5863
5863
|
Pure: {
|
|
5864
5864
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
5865
5865
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/faucet/faucet-v3.d.ts
|
|
2
|
+
interface FaucetResponseV3 {
|
|
3
|
+
status: 'success';
|
|
4
|
+
digest: string;
|
|
5
|
+
recipient: string;
|
|
6
|
+
amountMist: string;
|
|
7
|
+
difficulty: string;
|
|
8
|
+
}
|
|
9
|
+
/** A faucet HTTP error. Resolve any transaction digest before requesting another payout. */
|
|
10
|
+
declare class FaucetError extends Error {
|
|
11
|
+
readonly status: number;
|
|
12
|
+
readonly code?: string;
|
|
13
|
+
readonly digest?: string;
|
|
14
|
+
constructor(message: string, options: {
|
|
15
|
+
status: number;
|
|
16
|
+
code?: string;
|
|
17
|
+
digest?: string;
|
|
18
|
+
cause?: unknown;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Request SUI from a PoW faucet on devnet, testnet, or localnet.
|
|
23
|
+
* Fetches and solves a challenge, then submits one payout request without retrying it.
|
|
24
|
+
*/
|
|
25
|
+
declare function requestSuiFromFaucetV3(input: {
|
|
26
|
+
host: string;
|
|
27
|
+
recipient: string;
|
|
28
|
+
headers?: HeadersInit;
|
|
29
|
+
signal?: AbortSignal; /** Maximum time for fetching, solving, and submitting, in milliseconds. Defaults to 180000. */
|
|
30
|
+
timeout?: number;
|
|
31
|
+
}): Promise<FaucetResponseV3>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { FaucetError, FaucetResponseV3, requestSuiFromFaucetV3 };
|
|
34
|
+
//# sourceMappingURL=faucet-v3.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faucet-v3.d.mts","names":[],"sources":["../../src/faucet/faucet-v3.ts"],"mappings":";UAgBiB,gBAAA;EAChB,MAAA;EACA,MAAA;EACA,SAAA;EACA,UAAA;EACA,UAAA;AAAA;;cAIY,WAAA,SAAoB,KAAA;EAAA,SACvB,MAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA;cAGR,OAAA,UACA,OAAA;IAAW,MAAA;IAAgB,IAAA;IAAe,MAAA;IAAiB,KAAA;EAAA;AAAA;;;;;iBAsBvC,sBAAA,CAAuB,KAAA;EAC5C,IAAA;EACA,SAAA;EACA,OAAA,GAAU,WAAA;EACV,MAAA,GAAS,WAAA,EA1BoE;EA4B7E,OAAA;AAAA,IACG,OAAA,CAAQ,gBAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { isValidSuiAddress, normalizeSuiAddress } from "../utils/sui-types.mjs";
|
|
2
|
+
import { FaucetRateLimitError } from "./faucet.mjs";
|
|
3
|
+
import { FaucetAddress, FaucetAmount, FaucetChallenge, FaucetDifficulty, FaucetDigest, solveFaucetChallenge } from "./pow.mjs";
|
|
4
|
+
import { literal, object, parse } from "valibot";
|
|
5
|
+
|
|
6
|
+
//#region src/faucet/faucet-v3.ts
|
|
7
|
+
/** A faucet HTTP error. Resolve any transaction digest before requesting another payout. */
|
|
8
|
+
var FaucetError = class extends Error {
|
|
9
|
+
constructor(message, options) {
|
|
10
|
+
super(message, { cause: options.cause });
|
|
11
|
+
this.name = "FaucetError";
|
|
12
|
+
this.status = options.status;
|
|
13
|
+
this.code = options.code;
|
|
14
|
+
this.digest = options.digest;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const FaucetResponse = object({
|
|
18
|
+
status: literal("success"),
|
|
19
|
+
digest: FaucetDigest,
|
|
20
|
+
recipient: FaucetAddress,
|
|
21
|
+
amountMist: FaucetAmount,
|
|
22
|
+
difficulty: FaucetDifficulty
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Request SUI from a PoW faucet on devnet, testnet, or localnet.
|
|
26
|
+
* Fetches and solves a challenge, then submits one payout request without retrying it.
|
|
27
|
+
*/
|
|
28
|
+
async function requestSuiFromFaucetV3(input) {
|
|
29
|
+
if (!input.recipient.replace(/^0x/i, "")) throw new Error("Invalid faucet recipient");
|
|
30
|
+
const recipient = normalizeSuiAddress(input.recipient);
|
|
31
|
+
if (!isValidSuiAddress(recipient)) throw new Error("Invalid faucet recipient");
|
|
32
|
+
const timeout = AbortSignal.timeout(input.timeout ?? 18e4);
|
|
33
|
+
const signal = input.signal ? AbortSignal.any([input.signal, timeout]) : timeout;
|
|
34
|
+
const headers = new Headers(input.headers);
|
|
35
|
+
headers.set("Content-Type", "application/json");
|
|
36
|
+
async function request(path, body) {
|
|
37
|
+
signal.throwIfAborted();
|
|
38
|
+
const response = await fetch(new URL(path, input.host).toString(), {
|
|
39
|
+
method: body ? "POST" : "GET",
|
|
40
|
+
headers,
|
|
41
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
42
|
+
signal
|
|
43
|
+
});
|
|
44
|
+
if (response.status === 429) throw new FaucetRateLimitError("Too many requests to the faucet. Please retry later.");
|
|
45
|
+
let parseError;
|
|
46
|
+
const result = await response.json().catch((cause) => {
|
|
47
|
+
signal.throwIfAborted();
|
|
48
|
+
if (response.ok) throw new Error(`Invalid faucet response (HTTP ${response.status})`, { cause });
|
|
49
|
+
parseError = cause;
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) throw new FaucetError(typeof result?.error === "string" ? result.error : `Faucet request failed (HTTP ${response.status})`, {
|
|
52
|
+
status: response.status,
|
|
53
|
+
cause: parseError,
|
|
54
|
+
code: typeof result?.code === "string" ? result.code : void 0,
|
|
55
|
+
digest: typeof result?.digest === "string" ? result.digest : void 0
|
|
56
|
+
});
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
while (true) {
|
|
60
|
+
const startedAt = Date.now();
|
|
61
|
+
const challenge = parse(FaucetChallenge, await request(`/v3/challenge?${new URLSearchParams({ recipient })}`), { abortPipeEarly: true });
|
|
62
|
+
if (challenge.recipient !== recipient) throw new Error("Faucet challenge recipient mismatch");
|
|
63
|
+
const proof = await solveFaucetChallenge(challenge, startedAt + challenge.windowSeconds * 800, signal);
|
|
64
|
+
if (!proof) continue;
|
|
65
|
+
const result = parse(FaucetResponse, await request("/v3/gas", {
|
|
66
|
+
recipient,
|
|
67
|
+
checkpointSeq: challenge.checkpointSeq,
|
|
68
|
+
...proof
|
|
69
|
+
}), { abortPipeEarly: true });
|
|
70
|
+
if (result.recipient !== recipient) throw new Error("Faucet response recipient mismatch");
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { FaucetError, requestSuiFromFaucetV3 };
|
|
77
|
+
//# sourceMappingURL=faucet-v3.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faucet-v3.mjs","names":[],"sources":["../../src/faucet/faucet-v3.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { literal, object, parse } from 'valibot';\n\nimport { isValidSuiAddress, normalizeSuiAddress } from '../utils/sui-types.js';\nimport { FaucetRateLimitError } from './faucet.js';\nimport {\n\tFaucetAddress,\n\tFaucetAmount,\n\tFaucetChallenge,\n\tFaucetDifficulty,\n\tFaucetDigest,\n\tsolveFaucetChallenge,\n} from './pow.js';\n\nexport interface FaucetResponseV3 {\n\tstatus: 'success';\n\tdigest: string;\n\trecipient: string;\n\tamountMist: string;\n\tdifficulty: string;\n}\n\n/** A faucet HTTP error. Resolve any transaction digest before requesting another payout. */\nexport class FaucetError extends Error {\n\treadonly status: number;\n\treadonly code?: string;\n\treadonly digest?: string;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: { status: number; code?: string; digest?: string; cause?: unknown },\n\t) {\n\t\tsuper(message, { cause: options.cause });\n\t\tthis.name = 'FaucetError';\n\t\tthis.status = options.status;\n\t\tthis.code = options.code;\n\t\tthis.digest = options.digest;\n\t}\n}\n\nconst FaucetResponse = object({\n\tstatus: literal('success'),\n\tdigest: FaucetDigest,\n\trecipient: FaucetAddress,\n\tamountMist: FaucetAmount,\n\tdifficulty: FaucetDifficulty,\n});\n\n/**\n * Request SUI from a PoW faucet on devnet, testnet, or localnet.\n * Fetches and solves a challenge, then submits one payout request without retrying it.\n */\nexport async function requestSuiFromFaucetV3(input: {\n\thost: string;\n\trecipient: string;\n\theaders?: HeadersInit;\n\tsignal?: AbortSignal;\n\t/** Maximum time for fetching, solving, and submitting, in milliseconds. Defaults to 180000. */\n\ttimeout?: number;\n}): Promise<FaucetResponseV3> {\n\tif (!input.recipient.replace(/^0x/i, '')) throw new Error('Invalid faucet recipient');\n\tconst recipient = normalizeSuiAddress(input.recipient);\n\tif (!isValidSuiAddress(recipient)) throw new Error('Invalid faucet recipient');\n\tconst timeout = AbortSignal.timeout(input.timeout ?? 180_000);\n\tconst signal = input.signal ? AbortSignal.any([input.signal, timeout]) : timeout;\n\tconst headers = new Headers(input.headers);\n\theaders.set('Content-Type', 'application/json');\n\n\tasync function request(path: string, body?: object): Promise<unknown> {\n\t\tsignal.throwIfAborted();\n\t\tconst response = await fetch(new URL(path, input.host).toString(), {\n\t\t\tmethod: body ? 'POST' : 'GET',\n\t\t\theaders,\n\t\t\tbody: body ? JSON.stringify(body) : undefined,\n\t\t\tsignal,\n\t\t});\n\t\tif (response.status === 429) {\n\t\t\tthrow new FaucetRateLimitError('Too many requests to the faucet. Please retry later.');\n\t\t}\n\t\tlet parseError: unknown;\n\t\tconst result = await response.json().catch((cause: unknown) => {\n\t\t\tsignal.throwIfAborted();\n\t\t\tif (response.ok) {\n\t\t\t\tthrow new Error(`Invalid faucet response (HTTP ${response.status})`, { cause });\n\t\t\t}\n\t\t\tparseError = cause;\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow new FaucetError(\n\t\t\t\ttypeof result?.error === 'string'\n\t\t\t\t\t? result.error\n\t\t\t\t\t: `Faucet request failed (HTTP ${response.status})`,\n\t\t\t\t{\n\t\t\t\t\tstatus: response.status,\n\t\t\t\t\tcause: parseError,\n\t\t\t\t\tcode: typeof result?.code === 'string' ? result.code : undefined,\n\t\t\t\t\tdigest: typeof result?.digest === 'string' ? result.digest : undefined,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\treturn result;\n\t}\n\n\twhile (true) {\n\t\tconst startedAt = Date.now();\n\t\tconst challenge = parse(\n\t\t\tFaucetChallenge,\n\t\t\tawait request(`/v3/challenge?${new URLSearchParams({ recipient })}`),\n\t\t\t{ abortPipeEarly: true },\n\t\t);\n\t\tif (challenge.recipient !== recipient) throw new Error('Faucet challenge recipient mismatch');\n\t\t// Reserve part of the window for submission; refresh only before a payout has been attempted.\n\t\tconst proof = await solveFaucetChallenge(\n\t\t\tchallenge,\n\t\t\tstartedAt + challenge.windowSeconds * 800,\n\t\t\tsignal,\n\t\t);\n\t\tif (!proof) continue;\n\t\tconst result = parse(\n\t\t\tFaucetResponse,\n\t\t\tawait request('/v3/gas', {\n\t\t\t\trecipient,\n\t\t\t\tcheckpointSeq: challenge.checkpointSeq,\n\t\t\t\t...proof,\n\t\t\t}),\n\t\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;AACvB,OAAI,SAAS,GACZ,OAAM,IAAI,MAAM,iCAAiC,SAAS,OAAO,IAAI,EAAE,OAAO,CAAC;AAEhF,gBAAa;IACZ;AACF,MAAI,CAAC,SAAS,GACb,OAAM,IAAI,YACT,OAAO,QAAQ,UAAU,WACtB,OAAO,QACP,+BAA+B,SAAS,OAAO,IAClD;GACC,QAAQ,SAAS;GACjB,OAAO;GACP,MAAM,OAAO,QAAQ,SAAS,WAAW,OAAO,OAAO;GACvD,QAAQ,OAAO,QAAQ,WAAW,WAAW,OAAO,SAAS;GAC7D,CACD;AAEF,SAAO;;AAGR,QAAO,MAAM;EACZ,MAAM,YAAY,KAAK,KAAK;EAC5B,MAAM,YAAY,MACjB,iBACA,MAAM,QAAQ,iBAAiB,IAAI,gBAAgB,EAAE,WAAW,CAAC,GAAG,EACpE,EAAE,gBAAgB,MAAM,CACxB;AACD,MAAI,UAAU,cAAc,UAAW,OAAM,IAAI,MAAM,sCAAsC;EAE7F,MAAM,QAAQ,MAAM,qBACnB,WACA,YAAY,UAAU,gBAAgB,KACtC,OACA;AACD,MAAI,CAAC,MAAO;EACZ,MAAM,SAAS,MACd,gBACA,MAAM,QAAQ,WAAW;GACxB;GACA,eAAe,UAAU;GACzB,GAAG;GACH,CAAC,EACF,EAAE,gBAAgB,MAAM,CACxB;AACD,MAAI,OAAO,cAAc,UAAW,OAAM,IAAI,MAAM,qCAAqC;AACzF,SAAO"}
|
package/dist/faucet/index.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { FaucetRateLimitError, getFaucetHost, requestSuiFromFaucetV2 } from "./faucet.mjs";
|
|
2
|
-
|
|
2
|
+
import { FaucetError, FaucetResponseV3, requestSuiFromFaucetV3 } from "./faucet-v3.mjs";
|
|
3
|
+
export { FaucetError, FaucetRateLimitError, type FaucetResponseV3, getFaucetHost, requestSuiFromFaucetV2, requestSuiFromFaucetV3 };
|
package/dist/faucet/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { FaucetRateLimitError, getFaucetHost, requestSuiFromFaucetV2 } from "./faucet.mjs";
|
|
2
|
+
import { FaucetError, requestSuiFromFaucetV3 } from "./faucet-v3.mjs";
|
|
2
3
|
|
|
3
|
-
export { FaucetRateLimitError, getFaucetHost, requestSuiFromFaucetV2 };
|
|
4
|
+
export { FaucetError, FaucetRateLimitError, getFaucetHost, requestSuiFromFaucetV2, requestSuiFromFaucetV3 };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { isValidTransactionDigest } from "../utils/sui-types.mjs";
|
|
2
|
+
import { toHex } from "@mysten/bcs";
|
|
3
|
+
import { check, integer, literal, maxLength, minValue, number, object, pipe, regex, string } from "valibot";
|
|
4
|
+
import { argon2dAsync } from "@noble/hashes/argon2.js";
|
|
5
|
+
|
|
6
|
+
//#region src/faucet/pow.ts
|
|
7
|
+
const U64 = 1n << 64n;
|
|
8
|
+
const FaucetU64 = pipe(string(), regex(/^(0|[1-9][0-9]{0,19})$/), check((value) => BigInt(value) < U64));
|
|
9
|
+
const FaucetAmount = pipe(FaucetU64, check((value) => BigInt(value) > 0n));
|
|
10
|
+
const FaucetAddress = pipe(string(), regex(/^0x[0-9a-f]{64}$/));
|
|
11
|
+
const FaucetDigest = pipe(string(), check((value) => value.length <= 44 && isValidTransactionDigest(value)));
|
|
12
|
+
const FaucetDifficulty = pipe(FaucetU64, check((value) => BigInt(value) >= 2n && BigInt(value) <= 1n << 48n));
|
|
13
|
+
const FaucetChallenge = pipe(object({
|
|
14
|
+
version: literal(1),
|
|
15
|
+
domain: literal("sui-faucet-pow/1"),
|
|
16
|
+
algorithm: literal("argon2d"),
|
|
17
|
+
argon2Version: literal(19),
|
|
18
|
+
salt: literal("sui-faucet-pow-1"),
|
|
19
|
+
memorySize: literal(8192),
|
|
20
|
+
iterations: literal(1),
|
|
21
|
+
parallelism: literal(1),
|
|
22
|
+
hashLength: literal(32),
|
|
23
|
+
chainId: FaucetDigest,
|
|
24
|
+
checkpointSeq: FaucetU64,
|
|
25
|
+
checkpointDigest: FaucetDigest,
|
|
26
|
+
randomBytes: pipe(string(), maxLength(1024), regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/)),
|
|
27
|
+
faucetAddress: FaucetAddress,
|
|
28
|
+
recipient: FaucetAddress,
|
|
29
|
+
difficulty: FaucetDifficulty,
|
|
30
|
+
threshold: FaucetU64,
|
|
31
|
+
windowSeconds: pipe(number(), integer(), minValue(1)),
|
|
32
|
+
amountMist: FaucetAmount
|
|
33
|
+
}), check((value) => BigInt(value.threshold) === U64 / BigInt(value.difficulty)));
|
|
34
|
+
function hashFaucetProof(challenge, nonce) {
|
|
35
|
+
const preimage = [
|
|
36
|
+
challenge.domain,
|
|
37
|
+
challenge.chainId,
|
|
38
|
+
challenge.checkpointSeq,
|
|
39
|
+
challenge.checkpointDigest,
|
|
40
|
+
challenge.randomBytes,
|
|
41
|
+
challenge.faucetAddress,
|
|
42
|
+
challenge.recipient,
|
|
43
|
+
nonce.toString()
|
|
44
|
+
].join("\n");
|
|
45
|
+
const nativeArgon2 = globalThis.process?.getBuiltinModule?.("node:crypto")?.argon2;
|
|
46
|
+
if (nativeArgon2) return new Promise((resolve, reject) => {
|
|
47
|
+
nativeArgon2("argon2d", {
|
|
48
|
+
message: preimage,
|
|
49
|
+
nonce: challenge.salt,
|
|
50
|
+
parallelism: 1,
|
|
51
|
+
tagLength: 32,
|
|
52
|
+
memory: 8192,
|
|
53
|
+
passes: 1
|
|
54
|
+
}, (error, hash) => {
|
|
55
|
+
if (error) reject(error);
|
|
56
|
+
else resolve(hash);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
return argon2dAsync(preimage, challenge.salt, {
|
|
60
|
+
version: 19,
|
|
61
|
+
m: 8192,
|
|
62
|
+
t: 1,
|
|
63
|
+
p: 1,
|
|
64
|
+
dkLen: 32
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async function solveFaucetChallenge(challenge, deadline, signal) {
|
|
68
|
+
let nonce = globalThis.crypto.getRandomValues(new BigUint64Array(1))[0];
|
|
69
|
+
const threshold = BigInt(challenge.threshold);
|
|
70
|
+
while (Date.now() < deadline) {
|
|
71
|
+
signal.throwIfAborted();
|
|
72
|
+
let onAbort;
|
|
73
|
+
let hash;
|
|
74
|
+
try {
|
|
75
|
+
hash = await Promise.race([new Promise((_, reject) => {
|
|
76
|
+
onAbort = () => reject(signal.reason);
|
|
77
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
78
|
+
}), hashFaucetProof(challenge, nonce)]);
|
|
79
|
+
} finally {
|
|
80
|
+
signal.removeEventListener("abort", onAbort);
|
|
81
|
+
}
|
|
82
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
83
|
+
signal.throwIfAborted();
|
|
84
|
+
if (Date.now() >= deadline) break;
|
|
85
|
+
if (new DataView(hash.buffer, hash.byteOffset, hash.byteLength).getBigUint64(0) < threshold) return {
|
|
86
|
+
nonce: nonce.toString(),
|
|
87
|
+
hashHex: toHex(hash)
|
|
88
|
+
};
|
|
89
|
+
nonce = (nonce + 1n) % U64;
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
export { FaucetAddress, FaucetAmount, FaucetChallenge, FaucetDifficulty, FaucetDigest, solveFaucetChallenge };
|
|
96
|
+
//# sourceMappingURL=pow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pow.mjs","names":[],"sources":["../../src/faucet/pow.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toHex } from '@mysten/bcs';\nimport { argon2dAsync } from '@noble/hashes/argon2.js';\nimport type { InferOutput } from 'valibot';\nimport {\n\tcheck,\n\tinteger,\n\tliteral,\n\tmaxLength,\n\tminValue,\n\tnumber,\n\tobject,\n\tpipe,\n\tregex,\n\tstring,\n} from 'valibot';\n\nimport { isValidTransactionDigest } from '../utils/sui-types.js';\n\nconst U64 = 1n << 64n;\n\nexport const FaucetU64 = pipe(\n\tstring(),\n\tregex(/^(0|[1-9][0-9]{0,19})$/),\n\tcheck((value) => BigInt(value) < U64),\n);\nexport const FaucetAmount = pipe(\n\tFaucetU64,\n\tcheck((value) => BigInt(value) > 0n),\n);\nexport const FaucetAddress = pipe(string(), regex(/^0x[0-9a-f]{64}$/));\nexport const FaucetDigest = pipe(\n\tstring(),\n\tcheck((value) => value.length <= 44 && isValidTransactionDigest(value)),\n);\nexport const FaucetDifficulty = pipe(\n\tFaucetU64,\n\tcheck((value) => BigInt(value) >= 2n && BigInt(value) <= 1n << 48n),\n);\n\n// PoW version 1 fixes these costs; never let a server choose the client's memory allocation.\nexport const FaucetChallenge = pipe(\n\tobject({\n\t\tversion: literal(1),\n\t\tdomain: literal('sui-faucet-pow/1'),\n\t\talgorithm: literal('argon2d'),\n\t\targon2Version: literal(19),\n\t\tsalt: literal('sui-faucet-pow-1'),\n\t\tmemorySize: literal(8192),\n\t\titerations: literal(1),\n\t\tparallelism: literal(1),\n\t\thashLength: literal(32),\n\t\tchainId: FaucetDigest,\n\t\tcheckpointSeq: FaucetU64,\n\t\tcheckpointDigest: FaucetDigest,\n\t\trandomBytes: pipe(\n\t\t\tstring(),\n\t\t\tmaxLength(1024),\n\t\t\tregex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/),\n\t\t),\n\t\tfaucetAddress: FaucetAddress,\n\t\trecipient: FaucetAddress,\n\t\tdifficulty: FaucetDifficulty,\n\t\tthreshold: FaucetU64,\n\t\twindowSeconds: pipe(number(), integer(), minValue(1)),\n\t\tamountMist: FaucetAmount,\n\t}),\n\tcheck((value) => BigInt(value.threshold) === U64 / BigInt(value.difficulty)),\n);\n\ntype Challenge = InferOutput<typeof FaucetChallenge>;\n\ntype NativeArgon2 = (\n\talgorithm: 'argon2d',\n\tparameters: {\n\t\tmessage: string;\n\t\tnonce: string;\n\t\tparallelism: number;\n\t\ttagLength: number;\n\t\tmemory: number;\n\t\tpasses: number;\n\t},\n\tcallback: (error: Error | null, hash: Uint8Array) => void,\n) => void;\n\ntype NodeRuntime = {\n\tprocess?: {\n\t\tgetBuiltinModule?: (id: 'node:crypto') => { argon2?: NativeArgon2 } | undefined;\n\t};\n};\n\nexport function hashFaucetProof(challenge: Challenge, nonce: bigint): Promise<Uint8Array> {\n\tconst preimage = [\n\t\tchallenge.domain,\n\t\tchallenge.chainId,\n\t\tchallenge.checkpointSeq,\n\t\tchallenge.checkpointDigest,\n\t\tchallenge.randomBytes,\n\t\tchallenge.faucetAddress,\n\t\tchallenge.recipient,\n\t\tnonce.toString(),\n\t].join('\\n');\n\n\t// Avoid Node imports so browser bundles can use the Noble fallback without polyfills.\n\tconst nativeArgon2 = (globalThis as NodeRuntime).process?.getBuiltinModule?.(\n\t\t'node:crypto',\n\t)?.argon2;\n\tif (nativeArgon2) {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tnativeArgon2(\n\t\t\t\t'argon2d',\n\t\t\t\t{\n\t\t\t\t\tmessage: preimage,\n\t\t\t\t\tnonce: challenge.salt,\n\t\t\t\t\tparallelism: 1,\n\t\t\t\t\ttagLength: 32,\n\t\t\t\t\tmemory: 8192,\n\t\t\t\t\tpasses: 1,\n\t\t\t\t},\n\t\t\t\t(error, hash) => {\n\t\t\t\t\tif (error) reject(error);\n\t\t\t\t\telse resolve(hash);\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\treturn argon2dAsync(preimage, challenge.salt, {\n\t\tversion: 19,\n\t\tm: 8192,\n\t\tt: 1,\n\t\tp: 1,\n\t\tdkLen: 32,\n\t});\n}\n\nexport async function solveFaucetChallenge(\n\tchallenge: Challenge,\n\tdeadline: number,\n\tsignal: AbortSignal,\n) {\n\tlet nonce = globalThis.crypto.getRandomValues(new BigUint64Array(1))[0];\n\tconst threshold = BigInt(challenge.threshold);\n\twhile (Date.now() < deadline) {\n\t\tsignal.throwIfAborted();\n\t\tlet onAbort!: () => void;\n\t\tlet hash: Uint8Array;\n\t\ttry {\n\t\t\t// Stop waiting even if native hashing is still queued in the worker pool.\n\t\t\thash = await Promise.race([\n\t\t\t\tnew Promise<never>((_, reject) => {\n\t\t\t\t\tonAbort = () => reject(signal.reason);\n\t\t\t\t\tsignal.addEventListener('abort', onAbort, { once: true });\n\t\t\t\t}),\n\t\t\t\thashFaucetProof(challenge, nonce),\n\t\t\t]);\n\t\t} finally {\n\t\t\tsignal.removeEventListener('abort', onAbort);\n\t\t}\n\t\t// Yield to timers and cancellation, even when the hash implementation only yields microtasks.\n\t\tawait new Promise((resolve) => setTimeout(resolve, 0));\n\t\tsignal.throwIfAborted();\n\t\tif (Date.now() >= deadline) break;\n\t\tif (new DataView(hash.buffer, hash.byteOffset, hash.byteLength).getBigUint64(0) < threshold) {\n\t\t\treturn { nonce: nonce.toString(), hashHex: toHex(hash) };\n\t\t}\n\t\tnonce = (nonce + 1n) % U64;\n\t}\n\treturn null;\n}\n"],"mappings":";;;;;;AAqBA,MAAM,MAAM,MAAM;AAElB,MAAa,YAAY,KACxB,QAAQ,EACR,MAAM,yBAAyB,EAC/B,OAAO,UAAU,OAAO,MAAM,GAAG,IAAI,CACrC;AACD,MAAa,eAAe,KAC3B,WACA,OAAO,UAAU,OAAO,MAAM,GAAG,GAAG,CACpC;AACD,MAAa,gBAAgB,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACtE,MAAa,eAAe,KAC3B,QAAQ,EACR,OAAO,UAAU,MAAM,UAAU,MAAM,yBAAyB,MAAM,CAAC,CACvE;AACD,MAAa,mBAAmB,KAC/B,WACA,OAAO,UAAU,OAAO,MAAM,IAAI,MAAM,OAAO,MAAM,IAAI,MAAM,IAAI,CACnE;AAGD,MAAa,kBAAkB,KAC9B,OAAO;CACN,SAAS,QAAQ,EAAE;CACnB,Q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