@mysten/sui 2.19.0 → 2.20.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 +16 -0
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/bcs/index.d.mts +20 -20
- package/dist/cryptography/signature.d.mts +6 -6
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- 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/subscription_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_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/dist/zklogin/bcs.d.mts +14 -14
- package/dist/zklogin/bcs.d.mts.map +1 -1
- package/dist/zklogin/index.d.mts +2 -1
- package/dist/zklogin/index.mjs +2 -1
- package/dist/zklogin/publickey.d.mts +4 -0
- package/dist/zklogin/publickey.d.mts.map +1 -1
- package/dist/zklogin/publickey.mjs +6 -0
- package/dist/zklogin/publickey.mjs.map +1 -1
- package/dist/zklogin/signer.d.mts +55 -0
- package/dist/zklogin/signer.d.mts.map +1 -0
- package/dist/zklogin/signer.mjs +68 -0
- package/dist/zklogin/signer.mjs.map +1 -0
- package/package.json +1 -1
- package/src/version.ts +1 -1
- package/src/zklogin/index.ts +2 -0
- package/src/zklogin/publickey.ts +7 -0
- package/src/zklogin/signer.ts +121 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @mysten/sui.js
|
|
2
2
|
|
|
3
|
+
## 2.20.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7452835: Add `ZkLoginSigner`, a transport- and provider-agnostic zkLogin signer. It wraps any
|
|
8
|
+
ephemeral `Signer` and transforms its signatures into zkLogin signatures using the supplied proof
|
|
9
|
+
`inputs` and `maxEpoch`:
|
|
10
|
+
`new ZkLoginSigner({ ephemeralSigner, maxEpoch, inputs, legacyAddress })`. The address is derived
|
|
11
|
+
from the proof; `legacyAddress` is a required boolean (consistent with `jwtToAddress`,
|
|
12
|
+
`toZkLoginPublicIdentifier`, and the other zkLogin address APIs). Optionally pass `address` to
|
|
13
|
+
validate the derived address (throws on mismatch) and `client` to make the derived public key able
|
|
14
|
+
to verify signatures. Like other composite signers (e.g. `MultiSigSigner`), calling `sign()`
|
|
15
|
+
directly throws — use `signTransaction` / `signPersonalMessage`.
|
|
16
|
+
|
|
17
|
+
Also adds a read-only `legacyAddress` getter to `ZkLoginPublicIdentifier`.
|
|
18
|
+
|
|
3
19
|
## 2.19.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/dist/bcs/bcs.d.mts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { TypeTag as TypeTag$1 } from "./types.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _mysten_bcs810 from "@mysten/bcs";
|
|
3
3
|
import { BcsType } from "@mysten/bcs";
|
|
4
4
|
|
|
5
5
|
//#region src/bcs/bcs.d.ts
|
|
6
6
|
declare const TypeTag: BcsType<string, string | TypeTag$1, string>;
|
|
7
|
-
declare function IntentMessage<T extends BcsType<any>>(T: T):
|
|
8
|
-
intent:
|
|
9
|
-
scope:
|
|
7
|
+
declare function IntentMessage<T extends BcsType<any>>(T: T): _mysten_bcs810.BcsStruct<{
|
|
8
|
+
intent: _mysten_bcs810.BcsStruct<{
|
|
9
|
+
scope: _mysten_bcs810.BcsEnum<{
|
|
10
10
|
TransactionData: null;
|
|
11
11
|
TransactionEffects: null;
|
|
12
12
|
CheckpointSummary: null;
|
|
13
13
|
PersonalMessage: null;
|
|
14
14
|
}, "IntentScope">;
|
|
15
|
-
version:
|
|
15
|
+
version: _mysten_bcs810.BcsEnum<{
|
|
16
16
|
V0: null;
|
|
17
17
|
}, "IntentVersion">;
|
|
18
|
-
appId:
|
|
18
|
+
appId: _mysten_bcs810.BcsEnum<{
|
|
19
19
|
Sui: null;
|
|
20
20
|
}, "AppId">;
|
|
21
21
|
}, string>;
|
package/dist/bcs/index.d.mts
CHANGED
|
@@ -545,7 +545,7 @@ declare const suiBcs: {
|
|
|
545
545
|
version: string;
|
|
546
546
|
digest: string;
|
|
547
547
|
};
|
|
548
|
-
}, "
|
|
548
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
549
549
|
FundsWithdrawal: {
|
|
550
550
|
reservation: {
|
|
551
551
|
MaxAmountU64: string;
|
|
@@ -560,7 +560,7 @@ declare const suiBcs: {
|
|
|
560
560
|
Sponsor: true;
|
|
561
561
|
}, "Sender" | "Sponsor">;
|
|
562
562
|
};
|
|
563
|
-
}, "
|
|
563
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
564
564
|
Pure: {
|
|
565
565
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
566
566
|
};
|
|
@@ -793,7 +793,7 @@ declare const suiBcs: {
|
|
|
793
793
|
TransactionEffects: true;
|
|
794
794
|
CheckpointSummary: true;
|
|
795
795
|
PersonalMessage: true;
|
|
796
|
-
}, "
|
|
796
|
+
}, "TransactionEffects" | "TransactionData" | "CheckpointSummary" | "PersonalMessage">;
|
|
797
797
|
version: {
|
|
798
798
|
V0: true;
|
|
799
799
|
$kind: "V0";
|
|
@@ -827,7 +827,7 @@ declare const suiBcs: {
|
|
|
827
827
|
version: string;
|
|
828
828
|
digest: string;
|
|
829
829
|
};
|
|
830
|
-
}, "
|
|
830
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
831
831
|
FundsWithdrawal: {
|
|
832
832
|
reservation: {
|
|
833
833
|
MaxAmountU64: string;
|
|
@@ -842,7 +842,7 @@ declare const suiBcs: {
|
|
|
842
842
|
Sponsor: true;
|
|
843
843
|
}, "Sender" | "Sponsor">;
|
|
844
844
|
};
|
|
845
|
-
}, "
|
|
845
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[];
|
|
846
846
|
commands: _mysten_bcs0.EnumOutputShapeWithKeys<{
|
|
847
847
|
MoveCall: {
|
|
848
848
|
package: string;
|
|
@@ -950,7 +950,7 @@ declare const suiBcs: {
|
|
|
950
950
|
chain: string;
|
|
951
951
|
nonce: number;
|
|
952
952
|
};
|
|
953
|
-
}, "
|
|
953
|
+
}, "Epoch" | "None" | "ValidDuring">;
|
|
954
954
|
};
|
|
955
955
|
$kind: "V1";
|
|
956
956
|
};
|
|
@@ -1193,7 +1193,7 @@ declare const suiBcs: {
|
|
|
1193
1193
|
version: string;
|
|
1194
1194
|
digest: string;
|
|
1195
1195
|
};
|
|
1196
|
-
}, "
|
|
1196
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
1197
1197
|
FundsWithdrawal: {
|
|
1198
1198
|
reservation: {
|
|
1199
1199
|
MaxAmountU64: string;
|
|
@@ -1208,7 +1208,7 @@ declare const suiBcs: {
|
|
|
1208
1208
|
Sponsor: true;
|
|
1209
1209
|
}, "Sender" | "Sponsor">;
|
|
1210
1210
|
};
|
|
1211
|
-
}, "
|
|
1211
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
1212
1212
|
Pure: {
|
|
1213
1213
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
1214
1214
|
};
|
|
@@ -1508,7 +1508,7 @@ declare const suiBcs: {
|
|
|
1508
1508
|
version: string;
|
|
1509
1509
|
digest: string;
|
|
1510
1510
|
};
|
|
1511
|
-
}, "
|
|
1511
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
1512
1512
|
FundsWithdrawal: {
|
|
1513
1513
|
reservation: {
|
|
1514
1514
|
MaxAmountU64: string;
|
|
@@ -1523,7 +1523,7 @@ declare const suiBcs: {
|
|
|
1523
1523
|
Sponsor: true;
|
|
1524
1524
|
}, "Sender" | "Sponsor">;
|
|
1525
1525
|
};
|
|
1526
|
-
}, "
|
|
1526
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
1527
1527
|
Pure: {
|
|
1528
1528
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
1529
1529
|
};
|
|
@@ -1799,7 +1799,7 @@ declare const suiBcs: {
|
|
|
1799
1799
|
version: string;
|
|
1800
1800
|
digest: string;
|
|
1801
1801
|
};
|
|
1802
|
-
}, "
|
|
1802
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
1803
1803
|
FundsWithdrawal: {
|
|
1804
1804
|
reservation: {
|
|
1805
1805
|
MaxAmountU64: string;
|
|
@@ -1814,7 +1814,7 @@ declare const suiBcs: {
|
|
|
1814
1814
|
Sponsor: true;
|
|
1815
1815
|
}, "Sender" | "Sponsor">;
|
|
1816
1816
|
};
|
|
1817
|
-
}, "
|
|
1817
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
1818
1818
|
Pure: {
|
|
1819
1819
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
1820
1820
|
};
|
|
@@ -2271,7 +2271,7 @@ declare const suiBcs: {
|
|
|
2271
2271
|
startVersion: string;
|
|
2272
2272
|
owner: string;
|
|
2273
2273
|
};
|
|
2274
|
-
}, "AddressOwner" | "
|
|
2274
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">][], Iterable<readonly [{
|
|
2275
2275
|
objectId: string | Uint8Array<ArrayBufferLike>;
|
|
2276
2276
|
version: string | number | bigint;
|
|
2277
2277
|
digest: string;
|
|
@@ -2304,7 +2304,7 @@ declare const suiBcs: {
|
|
|
2304
2304
|
startVersion: string;
|
|
2305
2305
|
owner: string;
|
|
2306
2306
|
};
|
|
2307
|
-
}, "AddressOwner" | "
|
|
2307
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">][], Iterable<readonly [{
|
|
2308
2308
|
objectId: string | Uint8Array<ArrayBufferLike>;
|
|
2309
2309
|
version: string | number | bigint;
|
|
2310
2310
|
digest: string;
|
|
@@ -2337,7 +2337,7 @@ declare const suiBcs: {
|
|
|
2337
2337
|
startVersion: string;
|
|
2338
2338
|
owner: string;
|
|
2339
2339
|
};
|
|
2340
|
-
}, "AddressOwner" | "
|
|
2340
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">][], Iterable<readonly [{
|
|
2341
2341
|
objectId: string | Uint8Array<ArrayBufferLike>;
|
|
2342
2342
|
version: string | number | bigint;
|
|
2343
2343
|
digest: string;
|
|
@@ -2604,7 +2604,7 @@ declare const suiBcs: {
|
|
|
2604
2604
|
startVersion: string;
|
|
2605
2605
|
owner: string;
|
|
2606
2606
|
};
|
|
2607
|
-
}, "AddressOwner" | "
|
|
2607
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">];
|
|
2608
2608
|
}, "NotExist" | "Exist">;
|
|
2609
2609
|
outputState: _mysten_bcs0.EnumOutputShapeWithKeys<{
|
|
2610
2610
|
NotExist: true;
|
|
@@ -2619,7 +2619,7 @@ declare const suiBcs: {
|
|
|
2619
2619
|
startVersion: string;
|
|
2620
2620
|
owner: string;
|
|
2621
2621
|
};
|
|
2622
|
-
}, "AddressOwner" | "
|
|
2622
|
+
}, "AddressOwner" | "ConsensusAddressOwner" | "Immutable" | "ObjectOwner" | "Shared">];
|
|
2623
2623
|
PackageWrite: [string, string];
|
|
2624
2624
|
AccumulatorWriteV1: {
|
|
2625
2625
|
address: {
|
|
@@ -2705,7 +2705,7 @@ declare const suiBcs: {
|
|
|
2705
2705
|
ReadConsensusStreamEnded: string;
|
|
2706
2706
|
Cancelled: string;
|
|
2707
2707
|
PerEpochConfig: true;
|
|
2708
|
-
}, "
|
|
2708
|
+
}, "MutateConsensusStreamEnded" | "PerEpochConfig" | "ReadConsensusStreamEnded" | "ReadOnlyRoot" | "Cancelled">][], Iterable<readonly [string | Uint8Array<ArrayBufferLike>, _mysten_bcs0.EnumInputShape<{
|
|
2709
2709
|
ReadOnlyRoot: readonly [string | number | bigint, string];
|
|
2710
2710
|
MutateConsensusStreamEnded: string | number | bigint;
|
|
2711
2711
|
ReadConsensusStreamEnded: string | number | bigint;
|
|
@@ -2751,7 +2751,7 @@ declare const suiBcs: {
|
|
|
2751
2751
|
version: string;
|
|
2752
2752
|
digest: string;
|
|
2753
2753
|
};
|
|
2754
|
-
}, "
|
|
2754
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
2755
2755
|
FundsWithdrawal: {
|
|
2756
2756
|
reservation: {
|
|
2757
2757
|
MaxAmountU64: string;
|
|
@@ -2766,7 +2766,7 @@ declare const suiBcs: {
|
|
|
2766
2766
|
Sponsor: true;
|
|
2767
2767
|
}, "Sender" | "Sponsor">;
|
|
2768
2768
|
};
|
|
2769
|
-
}, "
|
|
2769
|
+
}, "Object" | "Pure" | "FundsWithdrawal">[], Iterable<_mysten_bcs0.EnumInputShape<{
|
|
2770
2770
|
Pure: {
|
|
2771
2771
|
bytes: string | Uint8Array<ArrayBufferLike>;
|
|
2772
2772
|
};
|
|
@@ -30,12 +30,6 @@ declare function parseSerializedSignature(serializedSignature: string): {
|
|
|
30
30
|
clientDataJson: string;
|
|
31
31
|
userSignature: Uint8Array<ArrayBuffer>;
|
|
32
32
|
publicKey: Uint8Array<ArrayBuffer>;
|
|
33
|
-
} | {
|
|
34
|
-
serializedSignature: string;
|
|
35
|
-
signatureScheme: "ED25519" | "Secp256k1" | "Secp256r1";
|
|
36
|
-
signature: Uint8Array<ArrayBuffer>;
|
|
37
|
-
publicKey: Uint8Array<ArrayBuffer>;
|
|
38
|
-
bytes: Uint8Array<ArrayBuffer>;
|
|
39
33
|
} | {
|
|
40
34
|
serializedSignature: string;
|
|
41
35
|
signatureScheme: "ZkLogin";
|
|
@@ -60,6 +54,12 @@ declare function parseSerializedSignature(serializedSignature: string): {
|
|
|
60
54
|
};
|
|
61
55
|
signature: Uint8Array<ArrayBufferLike>;
|
|
62
56
|
publicKey: Uint8Array<ArrayBuffer>;
|
|
57
|
+
} | {
|
|
58
|
+
serializedSignature: string;
|
|
59
|
+
signatureScheme: "ED25519" | "Secp256k1" | "Secp256r1";
|
|
60
|
+
signature: Uint8Array<ArrayBuffer>;
|
|
61
|
+
publicKey: Uint8Array<ArrayBuffer>;
|
|
62
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
63
63
|
} | {
|
|
64
64
|
serializedSignature: string;
|
|
65
65
|
signatureScheme: "MultiSig";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BatchGetObjectsRequest, BatchGetObjectsResponse, BatchGetTransactionsRequest, BatchGetTransactionsResponse, GetCheckpointRequest, GetCheckpointResponse, GetEpochRequest, GetEpochResponse, GetObjectRequest, GetObjectResponse, GetServiceInfoRequest, GetServiceInfoResponse, GetTransactionRequest, GetTransactionResponse } from "./ledger_service.mjs";
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as _protobuf_ts_runtime3 from "@protobuf-ts/runtime";
|
|
3
|
+
import * as _protobuf_ts_runtime_rpc3 from "@protobuf-ts/runtime-rpc";
|
|
4
4
|
import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
|
|
5
5
|
|
|
6
6
|
//#region src/grpc/proto/sui/rpc/v2/ledger_service.client.d.ts
|
|
@@ -45,9 +45,9 @@ interface ILedgerServiceClient {
|
|
|
45
45
|
declare class LedgerServiceClient implements ILedgerServiceClient, ServiceInfo {
|
|
46
46
|
private readonly _transport;
|
|
47
47
|
typeName: string;
|
|
48
|
-
methods:
|
|
48
|
+
methods: _protobuf_ts_runtime_rpc3.MethodInfo<any, any>[];
|
|
49
49
|
options: {
|
|
50
|
-
[extensionName: string]:
|
|
50
|
+
[extensionName: string]: _protobuf_ts_runtime3.JsonValue;
|
|
51
51
|
};
|
|
52
52
|
constructor(_transport: RpcTransport);
|
|
53
53
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GetDatatypeRequest, GetDatatypeResponse, GetFunctionRequest, GetFunctionResponse, GetPackageRequest, GetPackageResponse, ListPackageVersionsRequest, ListPackageVersionsResponse } from "./move_package_service.mjs";
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as _protobuf_ts_runtime0 from "@protobuf-ts/runtime";
|
|
3
|
+
import * as _protobuf_ts_runtime_rpc0 from "@protobuf-ts/runtime-rpc";
|
|
4
4
|
import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
|
|
5
5
|
|
|
6
6
|
//#region src/grpc/proto/sui/rpc/v2/move_package_service.client.d.ts
|
|
@@ -31,9 +31,9 @@ interface IMovePackageServiceClient {
|
|
|
31
31
|
declare class MovePackageServiceClient implements IMovePackageServiceClient, ServiceInfo {
|
|
32
32
|
private readonly _transport;
|
|
33
33
|
typeName: string;
|
|
34
|
-
methods:
|
|
34
|
+
methods: _protobuf_ts_runtime_rpc0.MethodInfo<any, any>[];
|
|
35
35
|
options: {
|
|
36
|
-
[extensionName: string]:
|
|
36
|
+
[extensionName: string]: _protobuf_ts_runtime0.JsonValue;
|
|
37
37
|
};
|
|
38
38
|
constructor(_transport: RpcTransport);
|
|
39
39
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LookupNameRequest, LookupNameResponse, ReverseLookupNameRequest, ReverseLookupNameResponse } from "./name_service.mjs";
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as _protobuf_ts_runtime5 from "@protobuf-ts/runtime";
|
|
3
|
+
import * as _protobuf_ts_runtime_rpc5 from "@protobuf-ts/runtime-rpc";
|
|
4
4
|
import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
|
|
5
5
|
|
|
6
6
|
//#region src/grpc/proto/sui/rpc/v2/name_service.client.d.ts
|
|
@@ -23,9 +23,9 @@ interface INameServiceClient {
|
|
|
23
23
|
declare class NameServiceClient implements INameServiceClient, ServiceInfo {
|
|
24
24
|
private readonly _transport;
|
|
25
25
|
typeName: string;
|
|
26
|
-
methods:
|
|
26
|
+
methods: _protobuf_ts_runtime_rpc5.MethodInfo<any, any>[];
|
|
27
27
|
options: {
|
|
28
|
-
[extensionName: string]:
|
|
28
|
+
[extensionName: string]: _protobuf_ts_runtime5.JsonValue;
|
|
29
29
|
};
|
|
30
30
|
constructor(_transport: RpcTransport);
|
|
31
31
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VerifySignatureRequest, VerifySignatureResponse } from "./signature_verification_service.mjs";
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as _protobuf_ts_runtime2 from "@protobuf-ts/runtime";
|
|
3
|
+
import * as _protobuf_ts_runtime_rpc2 from "@protobuf-ts/runtime-rpc";
|
|
4
4
|
import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
|
|
5
5
|
|
|
6
6
|
//#region src/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.ts
|
|
@@ -21,9 +21,9 @@ interface ISignatureVerificationServiceClient {
|
|
|
21
21
|
declare class SignatureVerificationServiceClient implements ISignatureVerificationServiceClient, ServiceInfo {
|
|
22
22
|
private readonly _transport;
|
|
23
23
|
typeName: string;
|
|
24
|
-
methods:
|
|
24
|
+
methods: _protobuf_ts_runtime_rpc2.MethodInfo<any, any>[];
|
|
25
25
|
options: {
|
|
26
|
-
[extensionName: string]:
|
|
26
|
+
[extensionName: string]: _protobuf_ts_runtime2.JsonValue;
|
|
27
27
|
};
|
|
28
28
|
constructor(_transport: RpcTransport);
|
|
29
29
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SubscribeCheckpointsRequest, SubscribeCheckpointsResponse } from "./subscription_service.mjs";
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as _protobuf_ts_runtime6 from "@protobuf-ts/runtime";
|
|
3
|
+
import * as _protobuf_ts_runtime_rpc6 from "@protobuf-ts/runtime-rpc";
|
|
4
4
|
import { RpcOptions, RpcTransport, ServerStreamingCall, ServiceInfo } from "@protobuf-ts/runtime-rpc";
|
|
5
5
|
|
|
6
6
|
//#region src/grpc/proto/sui/rpc/v2/subscription_service.client.d.ts
|
|
@@ -31,9 +31,9 @@ interface ISubscriptionServiceClient {
|
|
|
31
31
|
declare class SubscriptionServiceClient implements ISubscriptionServiceClient, ServiceInfo {
|
|
32
32
|
private readonly _transport;
|
|
33
33
|
typeName: string;
|
|
34
|
-
methods:
|
|
34
|
+
methods: _protobuf_ts_runtime_rpc6.MethodInfo<any, any>[];
|
|
35
35
|
options: {
|
|
36
|
-
[extensionName: string]:
|
|
36
|
+
[extensionName: string]: _protobuf_ts_runtime6.JsonValue;
|
|
37
37
|
};
|
|
38
38
|
constructor(_transport: RpcTransport);
|
|
39
39
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExecuteTransactionRequest, ExecuteTransactionResponse, SimulateTransactionRequest, SimulateTransactionResponse } from "./transaction_execution_service.mjs";
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as _protobuf_ts_runtime1 from "@protobuf-ts/runtime";
|
|
3
|
+
import * as _protobuf_ts_runtime_rpc1 from "@protobuf-ts/runtime-rpc";
|
|
4
4
|
import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
|
|
5
5
|
|
|
6
6
|
//#region src/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.ts
|
|
@@ -23,9 +23,9 @@ interface ITransactionExecutionServiceClient {
|
|
|
23
23
|
declare class TransactionExecutionServiceClient implements ITransactionExecutionServiceClient, ServiceInfo {
|
|
24
24
|
private readonly _transport;
|
|
25
25
|
typeName: string;
|
|
26
|
-
methods:
|
|
26
|
+
methods: _protobuf_ts_runtime_rpc1.MethodInfo<any, any>[];
|
|
27
27
|
options: {
|
|
28
|
-
[extensionName: string]:
|
|
28
|
+
[extensionName: string]: _protobuf_ts_runtime1.JsonValue;
|
|
29
29
|
};
|
|
30
30
|
constructor(_transport: RpcTransport);
|
|
31
31
|
/**
|
|
@@ -102,7 +102,7 @@ declare class Transaction {
|
|
|
102
102
|
chain: string;
|
|
103
103
|
nonce: number;
|
|
104
104
|
};
|
|
105
|
-
}, "
|
|
105
|
+
}, "Epoch" | "None" | "ValidDuring"> | null | undefined;
|
|
106
106
|
gasData: {
|
|
107
107
|
budget: string | number | null;
|
|
108
108
|
price: string | number | null;
|
|
@@ -130,7 +130,7 @@ declare class Transaction {
|
|
|
130
130
|
version: string | number;
|
|
131
131
|
digest: string;
|
|
132
132
|
};
|
|
133
|
-
}, "
|
|
133
|
+
}, "Receiving" | "ImmOrOwnedObject" | "SharedObject">;
|
|
134
134
|
Pure: {
|
|
135
135
|
bytes: string;
|
|
136
136
|
};
|
|
@@ -158,7 +158,7 @@ declare class Transaction {
|
|
|
158
158
|
Sponsor: true;
|
|
159
159
|
}, "Sender" | "Sponsor">;
|
|
160
160
|
};
|
|
161
|
-
}, "
|
|
161
|
+
}, "Object" | "Pure" | "FundsWithdrawal" | "UnresolvedPure" | "UnresolvedObject">[];
|
|
162
162
|
commands: _mysten_bcs1124.EnumOutputShapeWithKeys<{
|
|
163
163
|
MoveCall: {
|
|
164
164
|
package: string;
|
package/dist/version.mjs
CHANGED
package/dist/version.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '2.
|
|
1
|
+
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '2.20.0';\n"],"mappings":";AAKA,MAAa,kBAAkB"}
|
package/dist/zklogin/bcs.d.mts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _mysten_bcs1111 from "@mysten/bcs";
|
|
2
2
|
import { InferBcsInput } from "@mysten/bcs";
|
|
3
3
|
|
|
4
4
|
//#region src/zklogin/bcs.d.ts
|
|
5
|
-
declare const zkLoginSignature:
|
|
6
|
-
inputs:
|
|
7
|
-
proofPoints:
|
|
8
|
-
a:
|
|
5
|
+
declare const zkLoginSignature: _mysten_bcs1111.BcsStruct<{
|
|
6
|
+
inputs: _mysten_bcs1111.BcsStruct<{
|
|
7
|
+
proofPoints: _mysten_bcs1111.BcsStruct<{
|
|
8
|
+
a: _mysten_bcs1111.BcsType<string[], Iterable<string> & {
|
|
9
9
|
length: number;
|
|
10
10
|
}, string>;
|
|
11
|
-
b:
|
|
11
|
+
b: _mysten_bcs1111.BcsType<string[][], Iterable<Iterable<string> & {
|
|
12
12
|
length: number;
|
|
13
13
|
}> & {
|
|
14
14
|
length: number;
|
|
15
15
|
}, string>;
|
|
16
|
-
c:
|
|
16
|
+
c: _mysten_bcs1111.BcsType<string[], Iterable<string> & {
|
|
17
17
|
length: number;
|
|
18
18
|
}, string>;
|
|
19
19
|
}, string>;
|
|
20
|
-
issBase64Details:
|
|
21
|
-
value:
|
|
22
|
-
indexMod4:
|
|
20
|
+
issBase64Details: _mysten_bcs1111.BcsStruct<{
|
|
21
|
+
value: _mysten_bcs1111.BcsType<string, string, "string">;
|
|
22
|
+
indexMod4: _mysten_bcs1111.BcsType<number, number, "u8">;
|
|
23
23
|
}, string>;
|
|
24
|
-
headerBase64:
|
|
25
|
-
addressSeed:
|
|
24
|
+
headerBase64: _mysten_bcs1111.BcsType<string, string, "string">;
|
|
25
|
+
addressSeed: _mysten_bcs1111.BcsType<string, string, "string">;
|
|
26
26
|
}, string>;
|
|
27
|
-
maxEpoch:
|
|
28
|
-
userSignature:
|
|
27
|
+
maxEpoch: _mysten_bcs1111.BcsType<string, string | number | bigint, "u64">;
|
|
28
|
+
userSignature: _mysten_bcs1111.BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
|
|
29
29
|
}, string>;
|
|
30
30
|
type ZkLoginSignature = InferBcsInput<typeof zkLoginSignature>;
|
|
31
31
|
type ZkLoginSignatureInputs = ZkLoginSignature['inputs'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bcs.d.mts","names":[],"sources":["../../src/zklogin/bcs.ts"],"mappings":";;;;cAMa,gBAAA,
|
|
1
|
+
{"version":3,"file":"bcs.d.mts","names":[],"sources":["../../src/zklogin/bcs.ts"],"mappings":";;;;cAMa,gBAAA,kBAAgB,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;KAkBjB,gBAAA,GAAmB,aAAA,QAAqB,gBAAA;AAAA,KACxC,sBAAA,GAAyB,gBAAA"}
|
package/dist/zklogin/index.d.mts
CHANGED
|
@@ -3,7 +3,8 @@ import { getZkLoginSignature, parseZkLoginSignature } from "./signature.mjs";
|
|
|
3
3
|
import { genAddressSeed, getExtendedEphemeralPublicKey, hashASCIIStrToField, toBigEndianBytes, toPaddedBigEndianBytes } from "./utils.mjs";
|
|
4
4
|
import { ComputeZkLoginAddressOptions, computeZkLoginAddress, computeZkLoginAddressFromSeed, jwtToAddress } from "./address.mjs";
|
|
5
5
|
import { ZkLoginPublicIdentifier, toZkLoginPublicIdentifier } from "./publickey.mjs";
|
|
6
|
+
import { ZkLoginSigner, ZkLoginSignerOptions } from "./signer.mjs";
|
|
6
7
|
import { poseidonHash } from "./poseidon.mjs";
|
|
7
8
|
import { generateNonce, generateRandomness } from "./nonce.mjs";
|
|
8
9
|
import { decodeJwt } from "./jwt-utils.mjs";
|
|
9
|
-
export { type ComputeZkLoginAddressOptions, ZkLoginPublicIdentifier, type ZkLoginSignatureInputs, computeZkLoginAddress, computeZkLoginAddressFromSeed, decodeJwt, genAddressSeed, generateNonce, generateRandomness, getExtendedEphemeralPublicKey, getZkLoginSignature, hashASCIIStrToField, jwtToAddress, parseZkLoginSignature, poseidonHash, toBigEndianBytes, toPaddedBigEndianBytes, toZkLoginPublicIdentifier };
|
|
10
|
+
export { type ComputeZkLoginAddressOptions, ZkLoginPublicIdentifier, type ZkLoginSignatureInputs, ZkLoginSigner, type ZkLoginSignerOptions, computeZkLoginAddress, computeZkLoginAddressFromSeed, decodeJwt, genAddressSeed, generateNonce, generateRandomness, getExtendedEphemeralPublicKey, getZkLoginSignature, hashASCIIStrToField, jwtToAddress, parseZkLoginSignature, poseidonHash, toBigEndianBytes, toPaddedBigEndianBytes, toZkLoginPublicIdentifier };
|
package/dist/zklogin/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { decodeJwt } from "./jwt-utils.mjs";
|
|
|
4
4
|
import { getZkLoginSignature, parseZkLoginSignature } from "./signature.mjs";
|
|
5
5
|
import { ZkLoginPublicIdentifier, toZkLoginPublicIdentifier } from "./publickey.mjs";
|
|
6
6
|
import { computeZkLoginAddress, computeZkLoginAddressFromSeed, jwtToAddress } from "./address.mjs";
|
|
7
|
+
import { ZkLoginSigner } from "./signer.mjs";
|
|
7
8
|
import { generateNonce, generateRandomness } from "./nonce.mjs";
|
|
8
9
|
|
|
9
|
-
export { ZkLoginPublicIdentifier, computeZkLoginAddress, computeZkLoginAddressFromSeed, decodeJwt, genAddressSeed, generateNonce, generateRandomness, getExtendedEphemeralPublicKey, getZkLoginSignature, hashASCIIStrToField, jwtToAddress, parseZkLoginSignature, poseidonHash, toBigEndianBytes, toPaddedBigEndianBytes, toZkLoginPublicIdentifier };
|
|
10
|
+
export { ZkLoginPublicIdentifier, ZkLoginSigner, computeZkLoginAddress, computeZkLoginAddressFromSeed, decodeJwt, genAddressSeed, generateNonce, generateRandomness, getExtendedEphemeralPublicKey, getZkLoginSignature, hashASCIIStrToField, jwtToAddress, parseZkLoginSignature, poseidonHash, toBigEndianBytes, toPaddedBigEndianBytes, toZkLoginPublicIdentifier };
|
|
@@ -17,6 +17,10 @@ declare class ZkLoginPublicIdentifier extends PublicKey {
|
|
|
17
17
|
}?: {
|
|
18
18
|
client?: ClientWithCoreApi;
|
|
19
19
|
});
|
|
20
|
+
/**
|
|
21
|
+
* Whether this identifier resolves to the deprecated legacy address derivation.
|
|
22
|
+
*/
|
|
23
|
+
get legacyAddress(): boolean;
|
|
20
24
|
static fromBytes(bytes: Uint8Array, {
|
|
21
25
|
client,
|
|
22
26
|
address,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../src/zklogin/publickey.ts"],"mappings":";;;;;;AAoBA;;cAAa,uBAAA,SAAgC,SAAA;EAAA;EASJ;;;;cAA5B,KAAA,EAAO,iBAAA;IAAqB;EAAA;IAAY,MAAA,GAAS,iBAAA;EAAA;EAAA,
|
|
1
|
+
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../src/zklogin/publickey.ts"],"mappings":";;;;;;AAoBA;;cAAa,uBAAA,SAAgC,SAAA;EAAA;EASJ;;;;cAA5B,KAAA,EAAO,iBAAA;IAAqB;EAAA;IAAY,MAAA,GAAS,iBAAA;EAAA;EAgCqB;;;EAAA,IAV9E,aAAA,CAAA;EAAA,OAIG,SAAA,CACN,KAAA,EAAO,UAAA;IAEN,MAAA;IACA,OAAA;IACA;EAAA;IACI,MAAA,GAAS,iBAAA;IAAmB,OAAA;IAAkB,aAAA;EAAA,IAA8B,uBAAA;EAAA,OAmC3E,SAAA,CAAU,OAAA,UAAiB,KAAA,EAAO,sBAAA,GAAsB,uBAAA;EAwET;;;EA9C7C,MAAA,CAAO,SAAA,EAAW,uBAAA;EAIlB,YAAA,CAAA;EA1GmC;;;EA+H5C,UAAA,CAAA,GAAc,UAAA,CAAW,WAAA;;;;EAOzB,IAAA,CAAA;EA7HwC;;;EAoIlC,MAAA,CAAO,QAAA,EAAU,UAAA,EAAY,UAAA,EAAY,UAAA,YAAsB,OAAA;EA9GjE;;;EAqHJ,qBAAA,CAAsB,OAAA,EAAS,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;EA9G1E;;;EA8HF,iBAAA,CAAkB,WAAA,EAAa,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;EA5H1E;;;EA2IO,aAAA,CAAc,OAAA;AAAA;AAAA,iBAMR,yBAAA,CACf,WAAA,UACA,GAAA,UACA,OAAA;EAAW,MAAA,GAAS,iBAAA;EAAmB,aAAA;AAAA,IACrC,uBAAA"}
|
|
@@ -29,6 +29,12 @@ var ZkLoginPublicIdentifier = class ZkLoginPublicIdentifier extends PublicKey {
|
|
|
29
29
|
this.#legacyAddress = this.#data.length !== this.#data[0] + 1 + 32;
|
|
30
30
|
if (this.#legacyAddress) this.#data = normalizeZkLoginPublicKeyBytes(this.#data, false);
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether this identifier resolves to the deprecated legacy address derivation.
|
|
34
|
+
*/
|
|
35
|
+
get legacyAddress() {
|
|
36
|
+
return this.#legacyAddress;
|
|
37
|
+
}
|
|
32
38
|
static fromBytes(bytes, { client, address, legacyAddress } = {}) {
|
|
33
39
|
let publicKey;
|
|
34
40
|
if (legacyAddress === true) publicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), { client });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publickey.mjs","names":["#client","#data","#legacyAddress","#toLegacyAddress"],"sources":["../../src/zklogin/publickey.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64, toHex } from '@mysten/bcs';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\nimport { PublicKey } from '../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/signature-scheme.js';\nimport { normalizeSuiAddress, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';\nimport type { ZkLoginSignatureInputs } from './bcs.js';\nimport { extractClaimValue } from './jwt-utils.js';\nimport { parseZkLoginSignature } from './signature.js';\nimport { normalizeZkLoginIssuer, toBigEndianBytes, toPaddedBigEndianBytes } from './utils.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\n/**\n * A zkLogin public identifier\n */\nexport class ZkLoginPublicIdentifier extends PublicKey {\n\t#data: Uint8Array<ArrayBuffer>;\n\t#client?: ClientWithCoreApi;\n\t#legacyAddress: boolean;\n\n\t/**\n\t * Create a new ZkLoginPublicIdentifier object\n\t * @param value zkLogin public identifier as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData, { client }: { client?: ClientWithCoreApi } = {}) {\n\t\tsuper();\n\n\t\tthis.#client = client;\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.#data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.#data = value as Uint8Array<ArrayBuffer>;\n\t\t} else {\n\t\t\tthis.#data = Uint8Array.from(value);\n\t\t}\n\t\tthis.#legacyAddress = this.#data.length !== this.#data[0] + 1 + 32;\n\n\t\tif (this.#legacyAddress) {\n\t\t\tthis.#data = normalizeZkLoginPublicKeyBytes(this.#data, false);\n\t\t}\n\t}\n\n\tstatic fromBytes(\n\t\tbytes: Uint8Array,\n\t\t{\n\t\t\tclient,\n\t\t\taddress,\n\t\t\tlegacyAddress,\n\t\t}: { client?: ClientWithCoreApi; address?: string; legacyAddress?: boolean } = {},\n\t) {\n\t\tlet publicKey: ZkLoginPublicIdentifier;\n\n\t\tif (legacyAddress === true) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (legacyAddress === false) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (address) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\n\t\t\tif (publicKey.toSuiAddress() !== address) {\n\t\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\t\tclient,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(bytes, {\n\t\t\t\tclient,\n\t\t\t});\n\t\t}\n\n\t\tif (address && publicKey.toSuiAddress() !== address) {\n\t\t\tthrow new Error('Public key bytes do not match the provided address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\tstatic fromProof(address: string, proof: ZkLoginSignatureInputs) {\n\t\tconst { issBase64Details, addressSeed } = proof;\n\t\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\n\t\tconst legacyPublicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: true,\n\t\t});\n\n\t\tif (legacyPublicKey.toSuiAddress() === address) {\n\t\t\treturn legacyPublicKey;\n\t\t}\n\n\t\tconst publicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: false,\n\t\t});\n\n\t\tif (publicKey.toSuiAddress() !== address) {\n\t\t\tthrow new Error('Proof does not match address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\t/**\n\t * Checks if two zkLogin public identifiers are equal\n\t */\n\toverride equals(publicKey: ZkLoginPublicIdentifier): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\toverride toSuiAddress(): string {\n\t\tif (this.#legacyAddress) {\n\t\t\treturn this.#toLegacyAddress();\n\t\t}\n\n\t\treturn super.toSuiAddress();\n\t}\n\n\t#toLegacyAddress() {\n\t\tconst legacyBytes = normalizeZkLoginPublicKeyBytes(this.#data, true);\n\t\tconst addressBytes = new Uint8Array(legacyBytes.length + 1);\n\t\taddressBytes[0] = this.flag();\n\t\taddressBytes.set(legacyBytes, 1);\n\t\treturn normalizeSuiAddress(\n\t\t\tbytesToHex(blake2b(addressBytes, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2),\n\t\t);\n\t}\n\n\t/**\n\t * Return the byte array representation of the zkLogin public identifier\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.#data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this ZkLogin public identifier\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['ZkLogin'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(_message: Uint8Array, _signature: Uint8Array | string): Promise<boolean> {\n\t\tthrow Error('does not support');\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided PersonalMessage\n\t */\n\tverifyPersonalMessage(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(message),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'PersonalMessage',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided Transaction\n\t */\n\tverifyTransaction(transaction: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(transaction),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'TransactionData',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the public key is associated with the provided address\n\t */\n\toverride verifyAddress(address: string): boolean {\n\t\treturn address === super.toSuiAddress() || address === this.#toLegacyAddress();\n\t}\n}\n\n// Derive the public identifier for zklogin based on address seed and iss.\nexport function toZkLoginPublicIdentifier(\n\taddressSeed: bigint,\n\tiss: string,\n\toptions: { client?: ClientWithCoreApi; legacyAddress: boolean },\n): ZkLoginPublicIdentifier {\n\tif (options.legacyAddress === undefined) {\n\t\tthrow new Error('legacyAddress parameter must be specified');\n\t}\n\t// Consists of iss_bytes_len || iss_bytes || padded_32_byte_address_seed.\n\tconst addressSeedBytesBigEndian = options.legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\n\tconst issBytes = new TextEncoder().encode(normalizeZkLoginIssuer(iss));\n\tconst tmp = new Uint8Array(1 + issBytes.length + addressSeedBytesBigEndian.length);\n\ttmp.set([issBytes.length], 0);\n\ttmp.set(issBytes, 1);\n\ttmp.set(addressSeedBytesBigEndian, 1 + issBytes.length);\n\treturn new ZkLoginPublicIdentifier(tmp, options);\n}\n\nfunction normalizeZkLoginPublicKeyBytes(bytes: Uint8Array, legacyAddress: boolean) {\n\tconst issByteLength = bytes[0] + 1;\n\tconst addressSeed = BigInt(`0x${toHex(bytes.slice(issByteLength))}`);\n\tconst seedBytes = legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\tconst data = new Uint8Array(issByteLength + seedBytes.length);\n\tdata.set(bytes.slice(0, issByteLength), 0);\n\tdata.set(seedBytes, issByteLength);\n\treturn data;\n}\n\nasync function graphqlVerifyZkLoginSignature({\n\taddress,\n\tbytes,\n\tsignature,\n\tintentScope,\n\tclient,\n}: {\n\taddress: string;\n\tbytes: string;\n\tsignature: string;\n\tintentScope: 'PersonalMessage' | 'TransactionData';\n\tclient?: ClientWithCoreApi;\n}) {\n\tif (!client) {\n\t\tthrow new Error(\n\t\t\t'A Sui Client (GRPC, GraphQL, or JSON RPC) is required to verify zkLogin signatures',\n\t\t);\n\t}\n\tconst resp = await client.core.verifyZkLoginSignature({\n\t\tbytes,\n\t\tsignature,\n\t\tintentScope,\n\t\taddress: address,\n\t});\n\n\treturn resp.success === true && resp.errors.length === 0;\n}\n\nexport function parseSerializedZkLoginSignature(signature: Uint8Array | string) {\n\tconst bytes = typeof signature === 'string' ? fromBase64(signature) : signature;\n\n\tif (bytes[0] !== SIGNATURE_SCHEME_TO_FLAG.ZkLogin) {\n\t\tthrow new Error('Invalid signature scheme');\n\t}\n\n\tconst signatureBytes = bytes.slice(1);\n\tconst { inputs, maxEpoch, userSignature } = parseZkLoginSignature(signatureBytes);\n\tconst { issBase64Details, addressSeed } = inputs;\n\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\tconst publicIdentifier = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\tlegacyAddress: false,\n\t});\n\treturn {\n\t\tserializedSignature: toBase64(bytes),\n\t\tsignatureScheme: 'ZkLogin' as const,\n\t\tzkLogin: {\n\t\t\tinputs,\n\t\t\tmaxEpoch,\n\t\t\tuserSignature,\n\t\t\tiss,\n\t\t\taddressSeed: BigInt(addressSeed),\n\t\t},\n\t\tsignature: bytes,\n\t\tpublicKey: publicIdentifier.toRawBytes(),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,IAAa,0BAAb,MAAa,gCAAgC,UAAU;CACtD;CACA;CACA;;;;;CAMA,YAAY,OAA0B,EAAE,WAA2C,EAAE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B;CAC1C,MAAM,MAAM,kBAA0B,kBAAkB,MAAM;CAC9D,MAAM,mBAAmB,0BAA0B,OAAO,YAAY,EAAE,KAAK,EAC5E,eAAe,OACf,CAAC;AACF,QAAO;EACN,qBAAqB,SAAS,MAAM;EACpC,iBAAiB;EACjB,SAAS;GACR;GACA;GACA;GACA;GACA,aAAa,OAAO,YAAY;GAChC;EACD,WAAW;EACX,WAAW,iBAAiB,YAAY;EACxC"}
|
|
1
|
+
{"version":3,"file":"publickey.mjs","names":["#client","#data","#legacyAddress","#toLegacyAddress"],"sources":["../../src/zklogin/publickey.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64, toHex } from '@mysten/bcs';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\nimport { PublicKey } from '../cryptography/publickey.js';\nimport type { PublicKeyInitData } from '../cryptography/publickey.js';\nimport { SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/signature-scheme.js';\nimport { normalizeSuiAddress, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';\nimport type { ZkLoginSignatureInputs } from './bcs.js';\nimport { extractClaimValue } from './jwt-utils.js';\nimport { parseZkLoginSignature } from './signature.js';\nimport { normalizeZkLoginIssuer, toBigEndianBytes, toPaddedBigEndianBytes } from './utils.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\n/**\n * A zkLogin public identifier\n */\nexport class ZkLoginPublicIdentifier extends PublicKey {\n\t#data: Uint8Array<ArrayBuffer>;\n\t#client?: ClientWithCoreApi;\n\t#legacyAddress: boolean;\n\n\t/**\n\t * Create a new ZkLoginPublicIdentifier object\n\t * @param value zkLogin public identifier as buffer or base-64 encoded string\n\t */\n\tconstructor(value: PublicKeyInitData, { client }: { client?: ClientWithCoreApi } = {}) {\n\t\tsuper();\n\n\t\tthis.#client = client;\n\n\t\tif (typeof value === 'string') {\n\t\t\tthis.#data = fromBase64(value);\n\t\t} else if (value instanceof Uint8Array) {\n\t\t\tthis.#data = value as Uint8Array<ArrayBuffer>;\n\t\t} else {\n\t\t\tthis.#data = Uint8Array.from(value);\n\t\t}\n\t\tthis.#legacyAddress = this.#data.length !== this.#data[0] + 1 + 32;\n\n\t\tif (this.#legacyAddress) {\n\t\t\tthis.#data = normalizeZkLoginPublicKeyBytes(this.#data, false);\n\t\t}\n\t}\n\n\t/**\n\t * Whether this identifier resolves to the deprecated legacy address derivation.\n\t */\n\tget legacyAddress(): boolean {\n\t\treturn this.#legacyAddress;\n\t}\n\n\tstatic fromBytes(\n\t\tbytes: Uint8Array,\n\t\t{\n\t\t\tclient,\n\t\t\taddress,\n\t\t\tlegacyAddress,\n\t\t}: { client?: ClientWithCoreApi; address?: string; legacyAddress?: boolean } = {},\n\t) {\n\t\tlet publicKey: ZkLoginPublicIdentifier;\n\n\t\tif (legacyAddress === true) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (legacyAddress === false) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\t\t} else if (address) {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), {\n\t\t\t\tclient,\n\t\t\t});\n\n\t\t\tif (publicKey.toSuiAddress() !== address) {\n\t\t\t\tpublicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), {\n\t\t\t\t\tclient,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tpublicKey = new ZkLoginPublicIdentifier(bytes, {\n\t\t\t\tclient,\n\t\t\t});\n\t\t}\n\n\t\tif (address && publicKey.toSuiAddress() !== address) {\n\t\t\tthrow new Error('Public key bytes do not match the provided address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\tstatic fromProof(address: string, proof: ZkLoginSignatureInputs) {\n\t\tconst { issBase64Details, addressSeed } = proof;\n\t\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\n\t\tconst legacyPublicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: true,\n\t\t});\n\n\t\tif (legacyPublicKey.toSuiAddress() === address) {\n\t\t\treturn legacyPublicKey;\n\t\t}\n\n\t\tconst publicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\t\tlegacyAddress: false,\n\t\t});\n\n\t\tif (publicKey.toSuiAddress() !== address) {\n\t\t\tthrow new Error('Proof does not match address');\n\t\t}\n\n\t\treturn publicKey;\n\t}\n\n\t/**\n\t * Checks if two zkLogin public identifiers are equal\n\t */\n\toverride equals(publicKey: ZkLoginPublicIdentifier): boolean {\n\t\treturn super.equals(publicKey);\n\t}\n\n\toverride toSuiAddress(): string {\n\t\tif (this.#legacyAddress) {\n\t\t\treturn this.#toLegacyAddress();\n\t\t}\n\n\t\treturn super.toSuiAddress();\n\t}\n\n\t#toLegacyAddress() {\n\t\tconst legacyBytes = normalizeZkLoginPublicKeyBytes(this.#data, true);\n\t\tconst addressBytes = new Uint8Array(legacyBytes.length + 1);\n\t\taddressBytes[0] = this.flag();\n\t\taddressBytes.set(legacyBytes, 1);\n\t\treturn normalizeSuiAddress(\n\t\t\tbytesToHex(blake2b(addressBytes, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2),\n\t\t);\n\t}\n\n\t/**\n\t * Return the byte array representation of the zkLogin public identifier\n\t */\n\ttoRawBytes(): Uint8Array<ArrayBuffer> {\n\t\treturn this.#data;\n\t}\n\n\t/**\n\t * Return the Sui address associated with this ZkLogin public identifier\n\t */\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['ZkLogin'];\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided message\n\t */\n\tasync verify(_message: Uint8Array, _signature: Uint8Array | string): Promise<boolean> {\n\t\tthrow Error('does not support');\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided PersonalMessage\n\t */\n\tverifyPersonalMessage(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(message),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'PersonalMessage',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the signature is valid for for the provided Transaction\n\t */\n\tverifyTransaction(transaction: Uint8Array, signature: Uint8Array | string): Promise<boolean> {\n\t\tconst parsedSignature = parseSerializedZkLoginSignature(signature);\n\t\tconst address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();\n\t\treturn graphqlVerifyZkLoginSignature({\n\t\t\taddress: address,\n\t\t\tbytes: toBase64(transaction),\n\t\t\tsignature: parsedSignature.serializedSignature,\n\t\t\tintentScope: 'TransactionData',\n\t\t\tclient: this.#client,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that the public key is associated with the provided address\n\t */\n\toverride verifyAddress(address: string): boolean {\n\t\treturn address === super.toSuiAddress() || address === this.#toLegacyAddress();\n\t}\n}\n\n// Derive the public identifier for zklogin based on address seed and iss.\nexport function toZkLoginPublicIdentifier(\n\taddressSeed: bigint,\n\tiss: string,\n\toptions: { client?: ClientWithCoreApi; legacyAddress: boolean },\n): ZkLoginPublicIdentifier {\n\tif (options.legacyAddress === undefined) {\n\t\tthrow new Error('legacyAddress parameter must be specified');\n\t}\n\t// Consists of iss_bytes_len || iss_bytes || padded_32_byte_address_seed.\n\tconst addressSeedBytesBigEndian = options.legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\n\tconst issBytes = new TextEncoder().encode(normalizeZkLoginIssuer(iss));\n\tconst tmp = new Uint8Array(1 + issBytes.length + addressSeedBytesBigEndian.length);\n\ttmp.set([issBytes.length], 0);\n\ttmp.set(issBytes, 1);\n\ttmp.set(addressSeedBytesBigEndian, 1 + issBytes.length);\n\treturn new ZkLoginPublicIdentifier(tmp, options);\n}\n\nfunction normalizeZkLoginPublicKeyBytes(bytes: Uint8Array, legacyAddress: boolean) {\n\tconst issByteLength = bytes[0] + 1;\n\tconst addressSeed = BigInt(`0x${toHex(bytes.slice(issByteLength))}`);\n\tconst seedBytes = legacyAddress\n\t\t? toBigEndianBytes(addressSeed, 32)\n\t\t: toPaddedBigEndianBytes(addressSeed, 32);\n\tconst data = new Uint8Array(issByteLength + seedBytes.length);\n\tdata.set(bytes.slice(0, issByteLength), 0);\n\tdata.set(seedBytes, issByteLength);\n\treturn data;\n}\n\nasync function graphqlVerifyZkLoginSignature({\n\taddress,\n\tbytes,\n\tsignature,\n\tintentScope,\n\tclient,\n}: {\n\taddress: string;\n\tbytes: string;\n\tsignature: string;\n\tintentScope: 'PersonalMessage' | 'TransactionData';\n\tclient?: ClientWithCoreApi;\n}) {\n\tif (!client) {\n\t\tthrow new Error(\n\t\t\t'A Sui Client (GRPC, GraphQL, or JSON RPC) is required to verify zkLogin signatures',\n\t\t);\n\t}\n\tconst resp = await client.core.verifyZkLoginSignature({\n\t\tbytes,\n\t\tsignature,\n\t\tintentScope,\n\t\taddress: address,\n\t});\n\n\treturn resp.success === true && resp.errors.length === 0;\n}\n\nexport function parseSerializedZkLoginSignature(signature: Uint8Array | string) {\n\tconst bytes = typeof signature === 'string' ? fromBase64(signature) : signature;\n\n\tif (bytes[0] !== SIGNATURE_SCHEME_TO_FLAG.ZkLogin) {\n\t\tthrow new Error('Invalid signature scheme');\n\t}\n\n\tconst signatureBytes = bytes.slice(1);\n\tconst { inputs, maxEpoch, userSignature } = parseZkLoginSignature(signatureBytes);\n\tconst { issBase64Details, addressSeed } = inputs;\n\tconst iss = extractClaimValue<string>(issBase64Details, 'iss');\n\tconst publicIdentifier = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, {\n\t\tlegacyAddress: false,\n\t});\n\treturn {\n\t\tserializedSignature: toBase64(bytes),\n\t\tsignatureScheme: 'ZkLogin' as const,\n\t\tzkLogin: {\n\t\t\tinputs,\n\t\t\tmaxEpoch,\n\t\t\tuserSignature,\n\t\t\tiss,\n\t\t\taddressSeed: BigInt(addressSeed),\n\t\t},\n\t\tsignature: bytes,\n\t\tpublicKey: publicIdentifier.toRawBytes(),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,IAAa,0BAAb,MAAa,gCAAgC,UAAU;CACtD;CACA;CACA;;;;;CAMA,YAAY,OAA0B,EAAE,WAA2C,EAAE,EAAE;AACtF,SAAO;AAEP,QAAKA,SAAU;AAEf,MAAI,OAAO,UAAU,SACpB,OAAKC,OAAQ,WAAW,MAAM;WACpB,iBAAiB,WAC3B,OAAKA,OAAQ;MAEb,OAAKA,OAAQ,WAAW,KAAK,MAAM;AAEpC,QAAKC,gBAAiB,MAAKD,KAAM,WAAW,MAAKA,KAAM,KAAK,IAAI;AAEhE,MAAI,MAAKC,cACR,OAAKD,OAAQ,+BAA+B,MAAKA,MAAO,MAAM;;;;;CAOhE,IAAI,gBAAyB;AAC5B,SAAO,MAAKC;;CAGb,OAAO,UACN,OACA,EACC,QACA,SACA,kBAC8E,EAAE,EAChF;EACD,IAAI;AAEJ,MAAI,kBAAkB,KACrB,aAAY,IAAI,wBAAwB,+BAA+B,OAAO,KAAK,EAAE,EACpF,QACA,CAAC;WACQ,kBAAkB,MAC5B,aAAY,IAAI,wBAAwB,+BAA+B,OAAO,MAAM,EAAE,EACrF,QACA,CAAC;WACQ,SAAS;AACnB,eAAY,IAAI,wBAAwB,+BAA+B,OAAO,MAAM,EAAE,EACrF,QACA,CAAC;AAEF,OAAI,UAAU,cAAc,KAAK,QAChC,aAAY,IAAI,wBA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,cAAc,EAAE,EAAE;AAC1C,MAAK,IAAI,WAAW,cAAc;AAClC,QAAO;;AAGR,eAAe,8BAA8B,EAC5C,SACA,OACA,WACA,aACA,UAOE;AACF,KAAI,CAAC,OACJ,OAAM,IAAI,MACT,qFACA;CAEF,MAAM,OAAO,MAAM,OAAO,KAAK,uBAAuB;EACrD;EACA;EACA;EACS;EACT,CAAC;AAEF,QAAO,KAAK,YAAY,QAAQ,KAAK,OAAO,WAAW;;AAGxD,SAAgB,gCAAgC,WAAgC;CAC/E,MAAM,QAAQ,OAAO,cAAc,WAAW,WAAW,UAAU,GAAG;AAEtE,KAAI,MAAM,OAAO,yBAAyB,QACzC,OAAM,IAAI,MAAM,2BAA2B;CAI5C,MAAM,EAAE,QAAQ,UAAU,kBAAkB,sBADrB,MAAM,MAAM,EAAE,CAC4C;CACjF,MAAM,EAAE,kBAAkB,gBAAgB;CAC1C,MAAM,MAAM,kBAA0B,kBAAkB,MAAM;CAC9D,MAAM,mBAAmB,0BAA0B,OAAO,YAAY,EAAE,KAAK,EAC5E,eAAe,OACf,CAAC;AACF,QAAO;EACN,qBAAqB,SAAS,MAAM;EACpC,iBAAiB;EACjB,SAAS;GACR;GACA;GACA;GACA;GACA,aAAa,OAAO,YAAY;GAChC;EACD,WAAW;EACX,WAAW,iBAAiB,YAAY;EACxC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IntentScope } from "../cryptography/intent.mjs";
|
|
2
|
+
import { SignatureScheme } from "../cryptography/signature-scheme.mjs";
|
|
3
|
+
import { SignatureWithBytes, Signer } from "../cryptography/keypair.mjs";
|
|
4
|
+
import { ClientWithCoreApi } from "../client/core.mjs";
|
|
5
|
+
import { ZkLoginSignatureInputs } from "./bcs.mjs";
|
|
6
|
+
import { ZkLoginPublicIdentifier } from "./publickey.mjs";
|
|
7
|
+
|
|
8
|
+
//#region src/zklogin/signer.d.ts
|
|
9
|
+
interface ZkLoginSignerOptions {
|
|
10
|
+
/** The ephemeral signer whose signature is wrapped by the zkLogin proof. */
|
|
11
|
+
ephemeralSigner: Signer;
|
|
12
|
+
/** The maxEpoch the proof was generated for. */
|
|
13
|
+
maxEpoch: number;
|
|
14
|
+
/** The zkLogin proof inputs, including the `addressSeed`. */
|
|
15
|
+
inputs: ZkLoginSignatureInputs;
|
|
16
|
+
/**
|
|
17
|
+
* Whether this account uses the deprecated legacy address derivation. The zkLogin address is
|
|
18
|
+
* derived from the proof inputs; this flag disambiguates legacy vs. current derivation, matching
|
|
19
|
+
* the rest of the zkLogin address API (e.g. `jwtToAddress`, `toZkLoginPublicIdentifier`).
|
|
20
|
+
*
|
|
21
|
+
* A wrong flag silently yields a signer for the wrong address; pass `address` to guard against it.
|
|
22
|
+
*/
|
|
23
|
+
legacyAddress: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The expected zkLogin address. When provided, the address derived from `inputs` + `legacyAddress`
|
|
26
|
+
* is validated against it and the constructor throws on mismatch — guarding against a wrong
|
|
27
|
+
* `legacyAddress` flag producing a signer for the wrong address.
|
|
28
|
+
*/
|
|
29
|
+
address?: string;
|
|
30
|
+
/** Optional client, threaded into the derived public key so it can verify signatures. */
|
|
31
|
+
client?: ClientWithCoreApi;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A transport- and provider-agnostic zkLogin signer.
|
|
35
|
+
*
|
|
36
|
+
* It wraps any ephemeral {@link Signer} and, for every signing operation, transforms the ephemeral
|
|
37
|
+
* signature into a zkLogin signature using the supplied proof inputs and `maxEpoch`. Because every
|
|
38
|
+
* signing method on {@link Signer} funnels through `signWithIntent`, overriding that single method is
|
|
39
|
+
* enough to cover `signTransaction`, `signPersonalMessage`, and `signAndExecuteTransaction`.
|
|
40
|
+
*/
|
|
41
|
+
declare class ZkLoginSigner extends Signer {
|
|
42
|
+
#private;
|
|
43
|
+
constructor(options: ZkLoginSignerOptions);
|
|
44
|
+
/**
|
|
45
|
+
* The single extension point: the ephemeral signature is produced with the requested intent and
|
|
46
|
+
* then wrapped in a zkLogin signature.
|
|
47
|
+
*/
|
|
48
|
+
signWithIntent(bytes: Uint8Array, intent: IntentScope): Promise<SignatureWithBytes>;
|
|
49
|
+
sign(_data: Uint8Array): never;
|
|
50
|
+
getKeyScheme(): SignatureScheme;
|
|
51
|
+
getPublicKey(): ZkLoginPublicIdentifier;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { ZkLoginSigner, ZkLoginSignerOptions };
|
|
55
|
+
//# sourceMappingURL=signer.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.mts","names":[],"sources":["../../src/zklogin/signer.ts"],"mappings":";;;;;;;;UAaiB,oBAAA;EAAA;EAEhB,eAAA,EAAiB,MAAA;;EAEjB,QAAA;EAEQ;EAAR,MAAA,EAAQ,sBAAA;EAgBkB;;;;;;;EAR1B,aAAA;EAMA;;;;;EAAA,OAAA;EAa0B;EAX1B,MAAA,GAAS,iBAAA;AAAA;;;;;;;;;cAWG,aAAA,SAAsB,MAAA;EAAA;cAQtB,OAAA,EAAS,oBAAA;;;;;EAoCN,cAAA,CACd,KAAA,EAAO,UAAA,EACP,MAAA,EAAQ,WAAA,GACN,OAAA,CAAQ,kBAAA;EAcX,IAAA,CAAK,KAAA,EAAO,UAAA;EAMZ,YAAA,CAAA,GAAgB,eAAA;EAIhB,YAAA,CAAA,GAAgB,uBAAA;AAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { extractClaimValue } from "./jwt-utils.mjs";
|
|
2
|
+
import { getZkLoginSignature } from "./signature.mjs";
|
|
3
|
+
import { toZkLoginPublicIdentifier } from "./publickey.mjs";
|
|
4
|
+
import { Signer } from "../cryptography/keypair.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/zklogin/signer.ts
|
|
7
|
+
/**
|
|
8
|
+
* A transport- and provider-agnostic zkLogin signer.
|
|
9
|
+
*
|
|
10
|
+
* It wraps any ephemeral {@link Signer} and, for every signing operation, transforms the ephemeral
|
|
11
|
+
* signature into a zkLogin signature using the supplied proof inputs and `maxEpoch`. Because every
|
|
12
|
+
* signing method on {@link Signer} funnels through `signWithIntent`, overriding that single method is
|
|
13
|
+
* enough to cover `signTransaction`, `signPersonalMessage`, and `signAndExecuteTransaction`.
|
|
14
|
+
*/
|
|
15
|
+
var ZkLoginSigner = class extends Signer {
|
|
16
|
+
#ephemeralSigner;
|
|
17
|
+
#maxEpoch;
|
|
18
|
+
#inputs;
|
|
19
|
+
#legacyAddress;
|
|
20
|
+
#client;
|
|
21
|
+
#publicKey;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
super();
|
|
24
|
+
this.#ephemeralSigner = options.ephemeralSigner;
|
|
25
|
+
this.#maxEpoch = options.maxEpoch;
|
|
26
|
+
this.#inputs = options.inputs;
|
|
27
|
+
this.#legacyAddress = options.legacyAddress;
|
|
28
|
+
this.#client = options.client;
|
|
29
|
+
if (options.address !== void 0) {
|
|
30
|
+
const derived = this.#derivePublicKey().toSuiAddress();
|
|
31
|
+
if (derived !== options.address) throw new Error(`zkLogin proof does not match the provided address (derived ${derived}, expected ${options.address}) — check the \`legacyAddress\` flag`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
#derivePublicKey() {
|
|
35
|
+
return this.#publicKey ??= toZkLoginPublicIdentifier(BigInt(this.#inputs.addressSeed), extractClaimValue(this.#inputs.issBase64Details, "iss"), {
|
|
36
|
+
legacyAddress: this.#legacyAddress,
|
|
37
|
+
client: this.#client
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The single extension point: the ephemeral signature is produced with the requested intent and
|
|
42
|
+
* then wrapped in a zkLogin signature.
|
|
43
|
+
*/
|
|
44
|
+
async signWithIntent(bytes, intent) {
|
|
45
|
+
const { bytes: signedBytes, signature: userSignature } = await this.#ephemeralSigner.signWithIntent(bytes, intent);
|
|
46
|
+
return {
|
|
47
|
+
bytes: signedBytes,
|
|
48
|
+
signature: getZkLoginSignature({
|
|
49
|
+
inputs: this.#inputs,
|
|
50
|
+
maxEpoch: this.#maxEpoch,
|
|
51
|
+
userSignature
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
sign(_data) {
|
|
56
|
+
throw new Error("ZkLoginSigner does not support signing directly. Use signTransaction or signPersonalMessage instead");
|
|
57
|
+
}
|
|
58
|
+
getKeyScheme() {
|
|
59
|
+
return "ZkLogin";
|
|
60
|
+
}
|
|
61
|
+
getPublicKey() {
|
|
62
|
+
return this.#derivePublicKey();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { ZkLoginSigner };
|
|
68
|
+
//# sourceMappingURL=signer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.mjs","names":["#ephemeralSigner","#maxEpoch","#inputs","#legacyAddress","#client","#derivePublicKey","#publicKey"],"sources":["../../src/zklogin/signer.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ClientWithCoreApi } from '../client/core.js';\nimport type { IntentScope } from '../cryptography/intent.js';\nimport type { SignatureWithBytes } from '../cryptography/keypair.js';\nimport { Signer } from '../cryptography/keypair.js';\nimport type { SignatureScheme } from '../cryptography/signature-scheme.js';\nimport type { ZkLoginSignatureInputs } from './bcs.js';\nimport { extractClaimValue } from './jwt-utils.js';\nimport { toZkLoginPublicIdentifier, ZkLoginPublicIdentifier } from './publickey.js';\nimport { getZkLoginSignature } from './signature.js';\n\nexport interface ZkLoginSignerOptions {\n\t/** The ephemeral signer whose signature is wrapped by the zkLogin proof. */\n\tephemeralSigner: Signer;\n\t/** The maxEpoch the proof was generated for. */\n\tmaxEpoch: number;\n\t/** The zkLogin proof inputs, including the `addressSeed`. */\n\tinputs: ZkLoginSignatureInputs;\n\t/**\n\t * Whether this account uses the deprecated legacy address derivation. The zkLogin address is\n\t * derived from the proof inputs; this flag disambiguates legacy vs. current derivation, matching\n\t * the rest of the zkLogin address API (e.g. `jwtToAddress`, `toZkLoginPublicIdentifier`).\n\t *\n\t * A wrong flag silently yields a signer for the wrong address; pass `address` to guard against it.\n\t */\n\tlegacyAddress: boolean;\n\t/**\n\t * The expected zkLogin address. When provided, the address derived from `inputs` + `legacyAddress`\n\t * is validated against it and the constructor throws on mismatch — guarding against a wrong\n\t * `legacyAddress` flag producing a signer for the wrong address.\n\t */\n\taddress?: string;\n\t/** Optional client, threaded into the derived public key so it can verify signatures. */\n\tclient?: ClientWithCoreApi;\n}\n\n/**\n * A transport- and provider-agnostic zkLogin signer.\n *\n * It wraps any ephemeral {@link Signer} and, for every signing operation, transforms the ephemeral\n * signature into a zkLogin signature using the supplied proof inputs and `maxEpoch`. Because every\n * signing method on {@link Signer} funnels through `signWithIntent`, overriding that single method is\n * enough to cover `signTransaction`, `signPersonalMessage`, and `signAndExecuteTransaction`.\n */\nexport class ZkLoginSigner extends Signer {\n\t#ephemeralSigner: Signer;\n\t#maxEpoch: number;\n\t#inputs: ZkLoginSignatureInputs;\n\t#legacyAddress: boolean;\n\t#client?: ClientWithCoreApi;\n\t#publicKey?: ZkLoginPublicIdentifier;\n\n\tconstructor(options: ZkLoginSignerOptions) {\n\t\tsuper();\n\t\tthis.#ephemeralSigner = options.ephemeralSigner;\n\t\tthis.#maxEpoch = options.maxEpoch;\n\t\tthis.#inputs = options.inputs;\n\t\tthis.#legacyAddress = options.legacyAddress;\n\t\tthis.#client = options.client;\n\n\t\tif (options.address !== undefined) {\n\t\t\tconst derived = this.#derivePublicKey().toSuiAddress();\n\t\t\tif (derived !== options.address) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`zkLogin proof does not match the provided address (derived ${derived}, expected ` +\n\t\t\t\t\t\t`${options.address}) — check the \\`legacyAddress\\` flag`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Shared derive-and-memoize used by both the constructor's address validation and getPublicKey().\n\t// It is `#private` (non-virtual) on purpose: the constructor must derive the *base* address even\n\t// when a subclass overrides getPublicKey() — calling the overridable getPublicKey() from the\n\t// constructor would dispatch to the subclass before its fields are initialized. Laziness also\n\t// means subclasses that override getPublicKey() (e.g. EnokiKeypair) never pay for this derivation.\n\t#derivePublicKey(): ZkLoginPublicIdentifier {\n\t\treturn (this.#publicKey ??= toZkLoginPublicIdentifier(\n\t\t\tBigInt(this.#inputs.addressSeed),\n\t\t\textractClaimValue<string>(this.#inputs.issBase64Details, 'iss'),\n\t\t\t{ legacyAddress: this.#legacyAddress, client: this.#client },\n\t\t));\n\t}\n\n\t/**\n\t * The single extension point: the ephemeral signature is produced with the requested intent and\n\t * then wrapped in a zkLogin signature.\n\t */\n\toverride async signWithIntent(\n\t\tbytes: Uint8Array,\n\t\tintent: IntentScope,\n\t): Promise<SignatureWithBytes> {\n\t\tconst { bytes: signedBytes, signature: userSignature } =\n\t\t\tawait this.#ephemeralSigner.signWithIntent(bytes, intent);\n\n\t\treturn {\n\t\t\tbytes: signedBytes,\n\t\t\tsignature: getZkLoginSignature({\n\t\t\t\tinputs: this.#inputs,\n\t\t\t\tmaxEpoch: this.#maxEpoch,\n\t\t\t\tuserSignature,\n\t\t\t}),\n\t\t};\n\t}\n\n\tsign(_data: Uint8Array): never {\n\t\tthrow new Error(\n\t\t\t'ZkLoginSigner does not support signing directly. Use signTransaction or signPersonalMessage instead',\n\t\t);\n\t}\n\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'ZkLogin';\n\t}\n\n\tgetPublicKey(): ZkLoginPublicIdentifier {\n\t\treturn this.#derivePublicKey();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AA8CA,IAAa,gBAAb,cAAmC,OAAO;CACzC;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAA+B;AAC1C,SAAO;AACP,QAAKA,kBAAmB,QAAQ;AAChC,QAAKC,WAAY,QAAQ;AACzB,QAAKC,SAAU,QAAQ;AACvB,QAAKC,gBAAiB,QAAQ;AAC9B,QAAKC,SAAU,QAAQ;AAEvB,MAAI,QAAQ,YAAY,QAAW;GAClC,MAAM,UAAU,MAAKC,iBAAkB,CAAC,cAAc;AACtD,OAAI,YAAY,QAAQ,QACvB,OAAM,IAAI,MACT,8DAA8D,QAAQ,aAClE,QAAQ,QAAQ,sCACpB;;;CAUJ,mBAA4C;AAC3C,SAAQ,MAAKC,cAAe,0BAC3B,OAAO,MAAKJ,OAAQ,YAAY,EAChC,kBAA0B,MAAKA,OAAQ,kBAAkB,MAAM,EAC/D;GAAE,eAAe,MAAKC;GAAgB,QAAQ,MAAKC;GAAS,CAC5D;;;;;;CAOF,MAAe,eACd,OACA,QAC8B;EAC9B,MAAM,EAAE,OAAO,aAAa,WAAW,kBACtC,MAAM,MAAKJ,gBAAiB,eAAe,OAAO,OAAO;AAE1D,SAAO;GACN,OAAO;GACP,WAAW,oBAAoB;IAC9B,QAAQ,MAAKE;IACb,UAAU,MAAKD;IACf;IACA,CAAC;GACF;;CAGF,KAAK,OAA0B;AAC9B,QAAM,IAAI,MACT,sGACA;;CAGF,eAAgC;AAC/B,SAAO;;CAGR,eAAwC;AACvC,SAAO,MAAKI,iBAAkB"}
|
package/package.json
CHANGED
package/src/version.ts
CHANGED
package/src/zklogin/index.ts
CHANGED
|
@@ -12,6 +12,8 @@ export {
|
|
|
12
12
|
export { computeZkLoginAddressFromSeed, computeZkLoginAddress, jwtToAddress } from './address.js';
|
|
13
13
|
export type { ComputeZkLoginAddressOptions } from './address.js';
|
|
14
14
|
export { toZkLoginPublicIdentifier, ZkLoginPublicIdentifier } from './publickey.js';
|
|
15
|
+
export { ZkLoginSigner } from './signer.js';
|
|
16
|
+
export type { ZkLoginSignerOptions } from './signer.js';
|
|
15
17
|
export type { ZkLoginSignatureInputs } from './bcs.js';
|
|
16
18
|
export { poseidonHash } from './poseidon.js';
|
|
17
19
|
export { generateNonce, generateRandomness } from './nonce.js';
|
package/src/zklogin/publickey.ts
CHANGED
|
@@ -46,6 +46,13 @@ export class ZkLoginPublicIdentifier extends PublicKey {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Whether this identifier resolves to the deprecated legacy address derivation.
|
|
51
|
+
*/
|
|
52
|
+
get legacyAddress(): boolean {
|
|
53
|
+
return this.#legacyAddress;
|
|
54
|
+
}
|
|
55
|
+
|
|
49
56
|
static fromBytes(
|
|
50
57
|
bytes: Uint8Array,
|
|
51
58
|
{
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { ClientWithCoreApi } from '../client/core.js';
|
|
5
|
+
import type { IntentScope } from '../cryptography/intent.js';
|
|
6
|
+
import type { SignatureWithBytes } from '../cryptography/keypair.js';
|
|
7
|
+
import { Signer } from '../cryptography/keypair.js';
|
|
8
|
+
import type { SignatureScheme } from '../cryptography/signature-scheme.js';
|
|
9
|
+
import type { ZkLoginSignatureInputs } from './bcs.js';
|
|
10
|
+
import { extractClaimValue } from './jwt-utils.js';
|
|
11
|
+
import { toZkLoginPublicIdentifier, ZkLoginPublicIdentifier } from './publickey.js';
|
|
12
|
+
import { getZkLoginSignature } from './signature.js';
|
|
13
|
+
|
|
14
|
+
export interface ZkLoginSignerOptions {
|
|
15
|
+
/** The ephemeral signer whose signature is wrapped by the zkLogin proof. */
|
|
16
|
+
ephemeralSigner: Signer;
|
|
17
|
+
/** The maxEpoch the proof was generated for. */
|
|
18
|
+
maxEpoch: number;
|
|
19
|
+
/** The zkLogin proof inputs, including the `addressSeed`. */
|
|
20
|
+
inputs: ZkLoginSignatureInputs;
|
|
21
|
+
/**
|
|
22
|
+
* Whether this account uses the deprecated legacy address derivation. The zkLogin address is
|
|
23
|
+
* derived from the proof inputs; this flag disambiguates legacy vs. current derivation, matching
|
|
24
|
+
* the rest of the zkLogin address API (e.g. `jwtToAddress`, `toZkLoginPublicIdentifier`).
|
|
25
|
+
*
|
|
26
|
+
* A wrong flag silently yields a signer for the wrong address; pass `address` to guard against it.
|
|
27
|
+
*/
|
|
28
|
+
legacyAddress: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The expected zkLogin address. When provided, the address derived from `inputs` + `legacyAddress`
|
|
31
|
+
* is validated against it and the constructor throws on mismatch — guarding against a wrong
|
|
32
|
+
* `legacyAddress` flag producing a signer for the wrong address.
|
|
33
|
+
*/
|
|
34
|
+
address?: string;
|
|
35
|
+
/** Optional client, threaded into the derived public key so it can verify signatures. */
|
|
36
|
+
client?: ClientWithCoreApi;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A transport- and provider-agnostic zkLogin signer.
|
|
41
|
+
*
|
|
42
|
+
* It wraps any ephemeral {@link Signer} and, for every signing operation, transforms the ephemeral
|
|
43
|
+
* signature into a zkLogin signature using the supplied proof inputs and `maxEpoch`. Because every
|
|
44
|
+
* signing method on {@link Signer} funnels through `signWithIntent`, overriding that single method is
|
|
45
|
+
* enough to cover `signTransaction`, `signPersonalMessage`, and `signAndExecuteTransaction`.
|
|
46
|
+
*/
|
|
47
|
+
export class ZkLoginSigner extends Signer {
|
|
48
|
+
#ephemeralSigner: Signer;
|
|
49
|
+
#maxEpoch: number;
|
|
50
|
+
#inputs: ZkLoginSignatureInputs;
|
|
51
|
+
#legacyAddress: boolean;
|
|
52
|
+
#client?: ClientWithCoreApi;
|
|
53
|
+
#publicKey?: ZkLoginPublicIdentifier;
|
|
54
|
+
|
|
55
|
+
constructor(options: ZkLoginSignerOptions) {
|
|
56
|
+
super();
|
|
57
|
+
this.#ephemeralSigner = options.ephemeralSigner;
|
|
58
|
+
this.#maxEpoch = options.maxEpoch;
|
|
59
|
+
this.#inputs = options.inputs;
|
|
60
|
+
this.#legacyAddress = options.legacyAddress;
|
|
61
|
+
this.#client = options.client;
|
|
62
|
+
|
|
63
|
+
if (options.address !== undefined) {
|
|
64
|
+
const derived = this.#derivePublicKey().toSuiAddress();
|
|
65
|
+
if (derived !== options.address) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`zkLogin proof does not match the provided address (derived ${derived}, expected ` +
|
|
68
|
+
`${options.address}) — check the \`legacyAddress\` flag`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Shared derive-and-memoize used by both the constructor's address validation and getPublicKey().
|
|
75
|
+
// It is `#private` (non-virtual) on purpose: the constructor must derive the *base* address even
|
|
76
|
+
// when a subclass overrides getPublicKey() — calling the overridable getPublicKey() from the
|
|
77
|
+
// constructor would dispatch to the subclass before its fields are initialized. Laziness also
|
|
78
|
+
// means subclasses that override getPublicKey() (e.g. EnokiKeypair) never pay for this derivation.
|
|
79
|
+
#derivePublicKey(): ZkLoginPublicIdentifier {
|
|
80
|
+
return (this.#publicKey ??= toZkLoginPublicIdentifier(
|
|
81
|
+
BigInt(this.#inputs.addressSeed),
|
|
82
|
+
extractClaimValue<string>(this.#inputs.issBase64Details, 'iss'),
|
|
83
|
+
{ legacyAddress: this.#legacyAddress, client: this.#client },
|
|
84
|
+
));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The single extension point: the ephemeral signature is produced with the requested intent and
|
|
89
|
+
* then wrapped in a zkLogin signature.
|
|
90
|
+
*/
|
|
91
|
+
override async signWithIntent(
|
|
92
|
+
bytes: Uint8Array,
|
|
93
|
+
intent: IntentScope,
|
|
94
|
+
): Promise<SignatureWithBytes> {
|
|
95
|
+
const { bytes: signedBytes, signature: userSignature } =
|
|
96
|
+
await this.#ephemeralSigner.signWithIntent(bytes, intent);
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
bytes: signedBytes,
|
|
100
|
+
signature: getZkLoginSignature({
|
|
101
|
+
inputs: this.#inputs,
|
|
102
|
+
maxEpoch: this.#maxEpoch,
|
|
103
|
+
userSignature,
|
|
104
|
+
}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
sign(_data: Uint8Array): never {
|
|
109
|
+
throw new Error(
|
|
110
|
+
'ZkLoginSigner does not support signing directly. Use signTransaction or signPersonalMessage instead',
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getKeyScheme(): SignatureScheme {
|
|
115
|
+
return 'ZkLogin';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
getPublicKey(): ZkLoginPublicIdentifier {
|
|
119
|
+
return this.#derivePublicKey();
|
|
120
|
+
}
|
|
121
|
+
}
|