@fogo/sessions-sdk 0.0.13 → 0.0.15
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/cjs/index.d.ts +473 -5
- package/cjs/index.js +67 -5
- package/esm/index.d.ts +473 -5
- package/esm/index.js +67 -5
- package/package.json +3 -2
package/cjs/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type EstablishSessionOptions = {
|
|
|
9
9
|
walletPublicKey: PublicKey;
|
|
10
10
|
signMessage: (message: Uint8Array) => Promise<Uint8Array>;
|
|
11
11
|
expires: Date;
|
|
12
|
-
extra?: string | undefined;
|
|
12
|
+
extra?: Record<string, string> | undefined;
|
|
13
13
|
createUnsafeExtractableSessionKey?: boolean | undefined;
|
|
14
14
|
} & ({
|
|
15
15
|
limits?: Map<PublicKey, bigint>;
|
|
@@ -23,7 +23,7 @@ export declare const replaceSession: (options: {
|
|
|
23
23
|
session: Session;
|
|
24
24
|
signMessage: (message: Uint8Array) => Promise<Uint8Array>;
|
|
25
25
|
expires: Date;
|
|
26
|
-
extra?: string | undefined;
|
|
26
|
+
extra?: Record<string, string> | undefined;
|
|
27
27
|
} & ({
|
|
28
28
|
limits?: Map<PublicKey, bigint>;
|
|
29
29
|
unlimited?: false;
|
|
@@ -49,7 +49,7 @@ export declare const getSessionAccount: (connection: Connection, sessionPublicKe
|
|
|
49
49
|
expiration: Date;
|
|
50
50
|
extra: unknown;
|
|
51
51
|
major: number;
|
|
52
|
-
minor: 1 | 2;
|
|
52
|
+
minor: 1 | 2 | 3;
|
|
53
53
|
user: PublicKey;
|
|
54
54
|
sponsor: PublicKey;
|
|
55
55
|
} | undefined>;
|
|
@@ -602,6 +602,375 @@ declare const sessionInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
602
602
|
};
|
|
603
603
|
};
|
|
604
604
|
};
|
|
605
|
+
}>, z.ZodObject<{
|
|
606
|
+
V3: z.ZodObject<{
|
|
607
|
+
"0": z.ZodUnion<[z.ZodObject<{
|
|
608
|
+
Revoked: z.ZodType<BN, z.ZodTypeDef, BN>;
|
|
609
|
+
}, "strip", z.ZodTypeAny, {
|
|
610
|
+
Revoked: BN;
|
|
611
|
+
}, {
|
|
612
|
+
Revoked: BN;
|
|
613
|
+
}>, z.ZodObject<{
|
|
614
|
+
Active: z.ZodObject<{
|
|
615
|
+
"0": z.ZodObject<{
|
|
616
|
+
authorized_programs: z.ZodUnion<[z.ZodObject<{
|
|
617
|
+
Specific: z.ZodObject<{
|
|
618
|
+
0: z.ZodArray<z.ZodObject<{
|
|
619
|
+
program_id: z.ZodType<PublicKey, z.ZodTypeDef, PublicKey>;
|
|
620
|
+
signer_pda: z.ZodType<PublicKey, z.ZodTypeDef, PublicKey>;
|
|
621
|
+
}, "strip", z.ZodTypeAny, {
|
|
622
|
+
program_id: PublicKey;
|
|
623
|
+
signer_pda: PublicKey;
|
|
624
|
+
}, {
|
|
625
|
+
program_id: PublicKey;
|
|
626
|
+
signer_pda: PublicKey;
|
|
627
|
+
}>, "many">;
|
|
628
|
+
}, "strip", z.ZodTypeAny, {
|
|
629
|
+
0: {
|
|
630
|
+
program_id: PublicKey;
|
|
631
|
+
signer_pda: PublicKey;
|
|
632
|
+
}[];
|
|
633
|
+
}, {
|
|
634
|
+
0: {
|
|
635
|
+
program_id: PublicKey;
|
|
636
|
+
signer_pda: PublicKey;
|
|
637
|
+
}[];
|
|
638
|
+
}>;
|
|
639
|
+
}, "strip", z.ZodTypeAny, {
|
|
640
|
+
Specific: {
|
|
641
|
+
0: {
|
|
642
|
+
program_id: PublicKey;
|
|
643
|
+
signer_pda: PublicKey;
|
|
644
|
+
}[];
|
|
645
|
+
};
|
|
646
|
+
}, {
|
|
647
|
+
Specific: {
|
|
648
|
+
0: {
|
|
649
|
+
program_id: PublicKey;
|
|
650
|
+
signer_pda: PublicKey;
|
|
651
|
+
}[];
|
|
652
|
+
};
|
|
653
|
+
}>, z.ZodObject<{
|
|
654
|
+
All: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
655
|
+
}, "strip", z.ZodTypeAny, {
|
|
656
|
+
All: {};
|
|
657
|
+
}, {
|
|
658
|
+
All: {};
|
|
659
|
+
}>]>;
|
|
660
|
+
authorized_tokens: z.ZodUnion<[z.ZodObject<{
|
|
661
|
+
Specific: z.ZodObject<{
|
|
662
|
+
"0": z.ZodArray<z.ZodType<PublicKey, z.ZodTypeDef, PublicKey>, "many">;
|
|
663
|
+
}, "strip", z.ZodTypeAny, {
|
|
664
|
+
"0": PublicKey[];
|
|
665
|
+
}, {
|
|
666
|
+
"0": PublicKey[];
|
|
667
|
+
}>;
|
|
668
|
+
}, "strip", z.ZodTypeAny, {
|
|
669
|
+
Specific: {
|
|
670
|
+
"0": PublicKey[];
|
|
671
|
+
};
|
|
672
|
+
}, {
|
|
673
|
+
Specific: {
|
|
674
|
+
"0": PublicKey[];
|
|
675
|
+
};
|
|
676
|
+
}>, z.ZodObject<{
|
|
677
|
+
All: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
678
|
+
}, "strip", z.ZodTypeAny, {
|
|
679
|
+
All: {};
|
|
680
|
+
}, {
|
|
681
|
+
All: {};
|
|
682
|
+
}>]>;
|
|
683
|
+
expiration: z.ZodType<BN, z.ZodTypeDef, BN>;
|
|
684
|
+
extra: z.ZodObject<{
|
|
685
|
+
0: z.ZodUnknown;
|
|
686
|
+
}, "strip", z.ZodTypeAny, {
|
|
687
|
+
0?: unknown;
|
|
688
|
+
}, {
|
|
689
|
+
0?: unknown;
|
|
690
|
+
}>;
|
|
691
|
+
user: z.ZodType<PublicKey, z.ZodTypeDef, PublicKey>;
|
|
692
|
+
}, "strip", z.ZodTypeAny, {
|
|
693
|
+
authorized_programs: {
|
|
694
|
+
Specific: {
|
|
695
|
+
0: {
|
|
696
|
+
program_id: PublicKey;
|
|
697
|
+
signer_pda: PublicKey;
|
|
698
|
+
}[];
|
|
699
|
+
};
|
|
700
|
+
} | {
|
|
701
|
+
All: {};
|
|
702
|
+
};
|
|
703
|
+
authorized_tokens: {
|
|
704
|
+
Specific: {
|
|
705
|
+
"0": PublicKey[];
|
|
706
|
+
};
|
|
707
|
+
} | {
|
|
708
|
+
All: {};
|
|
709
|
+
};
|
|
710
|
+
expiration: BN;
|
|
711
|
+
extra: {
|
|
712
|
+
0?: unknown;
|
|
713
|
+
};
|
|
714
|
+
user: PublicKey;
|
|
715
|
+
}, {
|
|
716
|
+
authorized_programs: {
|
|
717
|
+
Specific: {
|
|
718
|
+
0: {
|
|
719
|
+
program_id: PublicKey;
|
|
720
|
+
signer_pda: PublicKey;
|
|
721
|
+
}[];
|
|
722
|
+
};
|
|
723
|
+
} | {
|
|
724
|
+
All: {};
|
|
725
|
+
};
|
|
726
|
+
authorized_tokens: {
|
|
727
|
+
Specific: {
|
|
728
|
+
"0": PublicKey[];
|
|
729
|
+
};
|
|
730
|
+
} | {
|
|
731
|
+
All: {};
|
|
732
|
+
};
|
|
733
|
+
expiration: BN;
|
|
734
|
+
extra: {
|
|
735
|
+
0?: unknown;
|
|
736
|
+
};
|
|
737
|
+
user: PublicKey;
|
|
738
|
+
}>;
|
|
739
|
+
}, "strip", z.ZodTypeAny, {
|
|
740
|
+
"0": {
|
|
741
|
+
authorized_programs: {
|
|
742
|
+
Specific: {
|
|
743
|
+
0: {
|
|
744
|
+
program_id: PublicKey;
|
|
745
|
+
signer_pda: PublicKey;
|
|
746
|
+
}[];
|
|
747
|
+
};
|
|
748
|
+
} | {
|
|
749
|
+
All: {};
|
|
750
|
+
};
|
|
751
|
+
authorized_tokens: {
|
|
752
|
+
Specific: {
|
|
753
|
+
"0": PublicKey[];
|
|
754
|
+
};
|
|
755
|
+
} | {
|
|
756
|
+
All: {};
|
|
757
|
+
};
|
|
758
|
+
expiration: BN;
|
|
759
|
+
extra: {
|
|
760
|
+
0?: unknown;
|
|
761
|
+
};
|
|
762
|
+
user: PublicKey;
|
|
763
|
+
};
|
|
764
|
+
}, {
|
|
765
|
+
"0": {
|
|
766
|
+
authorized_programs: {
|
|
767
|
+
Specific: {
|
|
768
|
+
0: {
|
|
769
|
+
program_id: PublicKey;
|
|
770
|
+
signer_pda: PublicKey;
|
|
771
|
+
}[];
|
|
772
|
+
};
|
|
773
|
+
} | {
|
|
774
|
+
All: {};
|
|
775
|
+
};
|
|
776
|
+
authorized_tokens: {
|
|
777
|
+
Specific: {
|
|
778
|
+
"0": PublicKey[];
|
|
779
|
+
};
|
|
780
|
+
} | {
|
|
781
|
+
All: {};
|
|
782
|
+
};
|
|
783
|
+
expiration: BN;
|
|
784
|
+
extra: {
|
|
785
|
+
0?: unknown;
|
|
786
|
+
};
|
|
787
|
+
user: PublicKey;
|
|
788
|
+
};
|
|
789
|
+
}>;
|
|
790
|
+
}, "strip", z.ZodTypeAny, {
|
|
791
|
+
Active: {
|
|
792
|
+
"0": {
|
|
793
|
+
authorized_programs: {
|
|
794
|
+
Specific: {
|
|
795
|
+
0: {
|
|
796
|
+
program_id: PublicKey;
|
|
797
|
+
signer_pda: PublicKey;
|
|
798
|
+
}[];
|
|
799
|
+
};
|
|
800
|
+
} | {
|
|
801
|
+
All: {};
|
|
802
|
+
};
|
|
803
|
+
authorized_tokens: {
|
|
804
|
+
Specific: {
|
|
805
|
+
"0": PublicKey[];
|
|
806
|
+
};
|
|
807
|
+
} | {
|
|
808
|
+
All: {};
|
|
809
|
+
};
|
|
810
|
+
expiration: BN;
|
|
811
|
+
extra: {
|
|
812
|
+
0?: unknown;
|
|
813
|
+
};
|
|
814
|
+
user: PublicKey;
|
|
815
|
+
};
|
|
816
|
+
};
|
|
817
|
+
}, {
|
|
818
|
+
Active: {
|
|
819
|
+
"0": {
|
|
820
|
+
authorized_programs: {
|
|
821
|
+
Specific: {
|
|
822
|
+
0: {
|
|
823
|
+
program_id: PublicKey;
|
|
824
|
+
signer_pda: PublicKey;
|
|
825
|
+
}[];
|
|
826
|
+
};
|
|
827
|
+
} | {
|
|
828
|
+
All: {};
|
|
829
|
+
};
|
|
830
|
+
authorized_tokens: {
|
|
831
|
+
Specific: {
|
|
832
|
+
"0": PublicKey[];
|
|
833
|
+
};
|
|
834
|
+
} | {
|
|
835
|
+
All: {};
|
|
836
|
+
};
|
|
837
|
+
expiration: BN;
|
|
838
|
+
extra: {
|
|
839
|
+
0?: unknown;
|
|
840
|
+
};
|
|
841
|
+
user: PublicKey;
|
|
842
|
+
};
|
|
843
|
+
};
|
|
844
|
+
}>]>;
|
|
845
|
+
}, "strip", z.ZodTypeAny, {
|
|
846
|
+
"0": {
|
|
847
|
+
Revoked: BN;
|
|
848
|
+
} | {
|
|
849
|
+
Active: {
|
|
850
|
+
"0": {
|
|
851
|
+
authorized_programs: {
|
|
852
|
+
Specific: {
|
|
853
|
+
0: {
|
|
854
|
+
program_id: PublicKey;
|
|
855
|
+
signer_pda: PublicKey;
|
|
856
|
+
}[];
|
|
857
|
+
};
|
|
858
|
+
} | {
|
|
859
|
+
All: {};
|
|
860
|
+
};
|
|
861
|
+
authorized_tokens: {
|
|
862
|
+
Specific: {
|
|
863
|
+
"0": PublicKey[];
|
|
864
|
+
};
|
|
865
|
+
} | {
|
|
866
|
+
All: {};
|
|
867
|
+
};
|
|
868
|
+
expiration: BN;
|
|
869
|
+
extra: {
|
|
870
|
+
0?: unknown;
|
|
871
|
+
};
|
|
872
|
+
user: PublicKey;
|
|
873
|
+
};
|
|
874
|
+
};
|
|
875
|
+
};
|
|
876
|
+
}, {
|
|
877
|
+
"0": {
|
|
878
|
+
Revoked: BN;
|
|
879
|
+
} | {
|
|
880
|
+
Active: {
|
|
881
|
+
"0": {
|
|
882
|
+
authorized_programs: {
|
|
883
|
+
Specific: {
|
|
884
|
+
0: {
|
|
885
|
+
program_id: PublicKey;
|
|
886
|
+
signer_pda: PublicKey;
|
|
887
|
+
}[];
|
|
888
|
+
};
|
|
889
|
+
} | {
|
|
890
|
+
All: {};
|
|
891
|
+
};
|
|
892
|
+
authorized_tokens: {
|
|
893
|
+
Specific: {
|
|
894
|
+
"0": PublicKey[];
|
|
895
|
+
};
|
|
896
|
+
} | {
|
|
897
|
+
All: {};
|
|
898
|
+
};
|
|
899
|
+
expiration: BN;
|
|
900
|
+
extra: {
|
|
901
|
+
0?: unknown;
|
|
902
|
+
};
|
|
903
|
+
user: PublicKey;
|
|
904
|
+
};
|
|
905
|
+
};
|
|
906
|
+
};
|
|
907
|
+
}>;
|
|
908
|
+
}, "strip", z.ZodTypeAny, {
|
|
909
|
+
V3: {
|
|
910
|
+
"0": {
|
|
911
|
+
Revoked: BN;
|
|
912
|
+
} | {
|
|
913
|
+
Active: {
|
|
914
|
+
"0": {
|
|
915
|
+
authorized_programs: {
|
|
916
|
+
Specific: {
|
|
917
|
+
0: {
|
|
918
|
+
program_id: PublicKey;
|
|
919
|
+
signer_pda: PublicKey;
|
|
920
|
+
}[];
|
|
921
|
+
};
|
|
922
|
+
} | {
|
|
923
|
+
All: {};
|
|
924
|
+
};
|
|
925
|
+
authorized_tokens: {
|
|
926
|
+
Specific: {
|
|
927
|
+
"0": PublicKey[];
|
|
928
|
+
};
|
|
929
|
+
} | {
|
|
930
|
+
All: {};
|
|
931
|
+
};
|
|
932
|
+
expiration: BN;
|
|
933
|
+
extra: {
|
|
934
|
+
0?: unknown;
|
|
935
|
+
};
|
|
936
|
+
user: PublicKey;
|
|
937
|
+
};
|
|
938
|
+
};
|
|
939
|
+
};
|
|
940
|
+
};
|
|
941
|
+
}, {
|
|
942
|
+
V3: {
|
|
943
|
+
"0": {
|
|
944
|
+
Revoked: BN;
|
|
945
|
+
} | {
|
|
946
|
+
Active: {
|
|
947
|
+
"0": {
|
|
948
|
+
authorized_programs: {
|
|
949
|
+
Specific: {
|
|
950
|
+
0: {
|
|
951
|
+
program_id: PublicKey;
|
|
952
|
+
signer_pda: PublicKey;
|
|
953
|
+
}[];
|
|
954
|
+
};
|
|
955
|
+
} | {
|
|
956
|
+
All: {};
|
|
957
|
+
};
|
|
958
|
+
authorized_tokens: {
|
|
959
|
+
Specific: {
|
|
960
|
+
"0": PublicKey[];
|
|
961
|
+
};
|
|
962
|
+
} | {
|
|
963
|
+
All: {};
|
|
964
|
+
};
|
|
965
|
+
expiration: BN;
|
|
966
|
+
extra: {
|
|
967
|
+
0?: unknown;
|
|
968
|
+
};
|
|
969
|
+
user: PublicKey;
|
|
970
|
+
};
|
|
971
|
+
};
|
|
972
|
+
};
|
|
973
|
+
};
|
|
605
974
|
}>]>;
|
|
606
975
|
major: z.ZodNumber;
|
|
607
976
|
sponsor: z.ZodType<PublicKey, z.ZodTypeDef, PublicKey>;
|
|
@@ -663,6 +1032,39 @@ declare const sessionInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
663
1032
|
};
|
|
664
1033
|
};
|
|
665
1034
|
};
|
|
1035
|
+
} | {
|
|
1036
|
+
V3: {
|
|
1037
|
+
"0": {
|
|
1038
|
+
Revoked: BN;
|
|
1039
|
+
} | {
|
|
1040
|
+
Active: {
|
|
1041
|
+
"0": {
|
|
1042
|
+
authorized_programs: {
|
|
1043
|
+
Specific: {
|
|
1044
|
+
0: {
|
|
1045
|
+
program_id: PublicKey;
|
|
1046
|
+
signer_pda: PublicKey;
|
|
1047
|
+
}[];
|
|
1048
|
+
};
|
|
1049
|
+
} | {
|
|
1050
|
+
All: {};
|
|
1051
|
+
};
|
|
1052
|
+
authorized_tokens: {
|
|
1053
|
+
Specific: {
|
|
1054
|
+
"0": PublicKey[];
|
|
1055
|
+
};
|
|
1056
|
+
} | {
|
|
1057
|
+
All: {};
|
|
1058
|
+
};
|
|
1059
|
+
expiration: BN;
|
|
1060
|
+
extra: {
|
|
1061
|
+
0?: unknown;
|
|
1062
|
+
};
|
|
1063
|
+
user: PublicKey;
|
|
1064
|
+
};
|
|
1065
|
+
};
|
|
1066
|
+
};
|
|
1067
|
+
};
|
|
666
1068
|
};
|
|
667
1069
|
major: number;
|
|
668
1070
|
}, {
|
|
@@ -723,6 +1125,39 @@ declare const sessionInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
723
1125
|
};
|
|
724
1126
|
};
|
|
725
1127
|
};
|
|
1128
|
+
} | {
|
|
1129
|
+
V3: {
|
|
1130
|
+
"0": {
|
|
1131
|
+
Revoked: BN;
|
|
1132
|
+
} | {
|
|
1133
|
+
Active: {
|
|
1134
|
+
"0": {
|
|
1135
|
+
authorized_programs: {
|
|
1136
|
+
Specific: {
|
|
1137
|
+
0: {
|
|
1138
|
+
program_id: PublicKey;
|
|
1139
|
+
signer_pda: PublicKey;
|
|
1140
|
+
}[];
|
|
1141
|
+
};
|
|
1142
|
+
} | {
|
|
1143
|
+
All: {};
|
|
1144
|
+
};
|
|
1145
|
+
authorized_tokens: {
|
|
1146
|
+
Specific: {
|
|
1147
|
+
"0": PublicKey[];
|
|
1148
|
+
};
|
|
1149
|
+
} | {
|
|
1150
|
+
All: {};
|
|
1151
|
+
};
|
|
1152
|
+
expiration: BN;
|
|
1153
|
+
extra: {
|
|
1154
|
+
0?: unknown;
|
|
1155
|
+
};
|
|
1156
|
+
user: PublicKey;
|
|
1157
|
+
};
|
|
1158
|
+
};
|
|
1159
|
+
};
|
|
1160
|
+
};
|
|
726
1161
|
};
|
|
727
1162
|
major: number;
|
|
728
1163
|
}>, {
|
|
@@ -739,7 +1174,7 @@ declare const sessionInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
739
1174
|
expiration: Date;
|
|
740
1175
|
extra: unknown;
|
|
741
1176
|
major: number;
|
|
742
|
-
minor: 1 | 2;
|
|
1177
|
+
minor: 1 | 2 | 3;
|
|
743
1178
|
user: PublicKey;
|
|
744
1179
|
sponsor: PublicKey;
|
|
745
1180
|
} | undefined, {
|
|
@@ -800,6 +1235,39 @@ declare const sessionInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
800
1235
|
};
|
|
801
1236
|
};
|
|
802
1237
|
};
|
|
1238
|
+
} | {
|
|
1239
|
+
V3: {
|
|
1240
|
+
"0": {
|
|
1241
|
+
Revoked: BN;
|
|
1242
|
+
} | {
|
|
1243
|
+
Active: {
|
|
1244
|
+
"0": {
|
|
1245
|
+
authorized_programs: {
|
|
1246
|
+
Specific: {
|
|
1247
|
+
0: {
|
|
1248
|
+
program_id: PublicKey;
|
|
1249
|
+
signer_pda: PublicKey;
|
|
1250
|
+
}[];
|
|
1251
|
+
};
|
|
1252
|
+
} | {
|
|
1253
|
+
All: {};
|
|
1254
|
+
};
|
|
1255
|
+
authorized_tokens: {
|
|
1256
|
+
Specific: {
|
|
1257
|
+
"0": PublicKey[];
|
|
1258
|
+
};
|
|
1259
|
+
} | {
|
|
1260
|
+
All: {};
|
|
1261
|
+
};
|
|
1262
|
+
expiration: BN;
|
|
1263
|
+
extra: {
|
|
1264
|
+
0?: unknown;
|
|
1265
|
+
};
|
|
1266
|
+
user: PublicKey;
|
|
1267
|
+
};
|
|
1268
|
+
};
|
|
1269
|
+
};
|
|
1270
|
+
};
|
|
803
1271
|
};
|
|
804
1272
|
major: number;
|
|
805
1273
|
}>;
|
|
@@ -872,7 +1340,7 @@ export declare const verifyLogInToken: (token: string, connection: Connection) =
|
|
|
872
1340
|
expiration: Date;
|
|
873
1341
|
extra: unknown;
|
|
874
1342
|
major: number;
|
|
875
|
-
minor: 1 | 2;
|
|
1343
|
+
minor: 1 | 2 | 3;
|
|
876
1344
|
user: PublicKey;
|
|
877
1345
|
sponsor: PublicKey;
|
|
878
1346
|
} | undefined>;
|
package/cjs/index.js
CHANGED
|
@@ -28,7 +28,7 @@ Signing this intent will allow this app to interact with your on-chain balances.
|
|
|
28
28
|
const UNLIMITED_TOKEN_PERMISSIONS_VALUE = "this app may spend any amount of any token";
|
|
29
29
|
const TOKENLESS_PERMISSIONS_VALUE = "this app may not spend any tokens";
|
|
30
30
|
const CURRENT_MAJOR = "0";
|
|
31
|
-
const CURRENT_MINOR = "
|
|
31
|
+
const CURRENT_MINOR = "3";
|
|
32
32
|
const CURRENT_INTENT_TRANSFER_MAJOR = "0";
|
|
33
33
|
const CURRENT_INTENT_TRANSFER_MINOR = "1";
|
|
34
34
|
const establishSession = async (options) => {
|
|
@@ -98,7 +98,7 @@ exports.revokeSession = revokeSession;
|
|
|
98
98
|
const reestablishSession = async (adapter, walletPublicKey, sessionKey) => createSession(adapter, walletPublicKey, sessionKey);
|
|
99
99
|
exports.reestablishSession = reestablishSession;
|
|
100
100
|
const getSessionAccount = async (connection, sessionPublicKey) => {
|
|
101
|
-
const result = await connection.getAccountInfo(sessionPublicKey);
|
|
101
|
+
const result = await connection.getAccountInfo(sessionPublicKey, "confirmed");
|
|
102
102
|
return result === null
|
|
103
103
|
? undefined
|
|
104
104
|
: sessionInfoSchema.parse(new anchor_1.BorshAccountsCoder(sessions_idls_1.SessionManagerIdl).decode("Session", result.data));
|
|
@@ -186,6 +186,47 @@ const sessionInfoSchema = zod_1.z
|
|
|
186
186
|
]),
|
|
187
187
|
}),
|
|
188
188
|
}),
|
|
189
|
+
zod_1.z.object({
|
|
190
|
+
V3: zod_1.z.object({
|
|
191
|
+
"0": zod_1.z.union([
|
|
192
|
+
zod_1.z.object({
|
|
193
|
+
Revoked: zod_1.z.instanceof(bn_js_1.default),
|
|
194
|
+
}),
|
|
195
|
+
zod_1.z.object({
|
|
196
|
+
Active: zod_1.z.object({
|
|
197
|
+
"0": zod_1.z.object({
|
|
198
|
+
authorized_programs: zod_1.z.union([
|
|
199
|
+
zod_1.z.object({
|
|
200
|
+
Specific: zod_1.z.object({
|
|
201
|
+
0: zod_1.z.array(zod_1.z.object({
|
|
202
|
+
program_id: zod_1.z.instanceof(web3_js_1.PublicKey),
|
|
203
|
+
signer_pda: zod_1.z.instanceof(web3_js_1.PublicKey),
|
|
204
|
+
})),
|
|
205
|
+
}),
|
|
206
|
+
}),
|
|
207
|
+
zod_1.z.object({
|
|
208
|
+
All: zod_1.z.object({}),
|
|
209
|
+
}),
|
|
210
|
+
]),
|
|
211
|
+
authorized_tokens: zod_1.z.union([
|
|
212
|
+
zod_1.z.object({
|
|
213
|
+
Specific: zod_1.z.object({
|
|
214
|
+
"0": zod_1.z.array(zod_1.z.instanceof(web3_js_1.PublicKey)),
|
|
215
|
+
}),
|
|
216
|
+
}),
|
|
217
|
+
zod_1.z.object({ All: zod_1.z.object({}) }),
|
|
218
|
+
]),
|
|
219
|
+
expiration: zod_1.z.instanceof(bn_js_1.default),
|
|
220
|
+
extra: zod_1.z.object({
|
|
221
|
+
0: zod_1.z.unknown(),
|
|
222
|
+
}),
|
|
223
|
+
user: zod_1.z.instanceof(web3_js_1.PublicKey),
|
|
224
|
+
}),
|
|
225
|
+
}),
|
|
226
|
+
}),
|
|
227
|
+
]),
|
|
228
|
+
}),
|
|
229
|
+
}),
|
|
189
230
|
]),
|
|
190
231
|
major: zod_1.z.number(),
|
|
191
232
|
sponsor: zod_1.z.instanceof(web3_js_1.PublicKey),
|
|
@@ -197,10 +238,14 @@ const sessionInfoSchema = zod_1.z
|
|
|
197
238
|
activeSessionInfo = session_info.V1["0"];
|
|
198
239
|
minor = 1;
|
|
199
240
|
}
|
|
200
|
-
else if ("Active" in session_info.V2["0"]) {
|
|
241
|
+
else if ("V2" in session_info && "Active" in session_info.V2["0"]) {
|
|
201
242
|
activeSessionInfo = session_info.V2["0"].Active["0"];
|
|
202
243
|
minor = 2;
|
|
203
244
|
}
|
|
245
|
+
else if ("V3" in session_info && "Active" in session_info.V3["0"]) {
|
|
246
|
+
activeSessionInfo = session_info.V3["0"].Active["0"];
|
|
247
|
+
minor = 3;
|
|
248
|
+
}
|
|
204
249
|
else {
|
|
205
250
|
return;
|
|
206
251
|
}
|
|
@@ -329,9 +374,20 @@ const buildMessage = async (body) => new TextEncoder().encode([
|
|
|
329
374
|
expires: body.expires.toISOString(),
|
|
330
375
|
session_key: await (0, kit_1.getAddressFromPublicKey)(body.sessionKey.publicKey),
|
|
331
376
|
tokens: serializeTokenList(body.tokens),
|
|
332
|
-
...(body.extra && { extra: body.extra }),
|
|
333
377
|
}),
|
|
378
|
+
body.extra && serializeExtra(body.extra),
|
|
334
379
|
].join("\n"));
|
|
380
|
+
const serializeExtra = (extra) => {
|
|
381
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
382
|
+
if (!/^[a-z]+(_[a-z0-9]+)*$/.test(key)) {
|
|
383
|
+
throw new Error(`Extra key must be a snake_case string: ${key}`);
|
|
384
|
+
}
|
|
385
|
+
if (value.includes("\n")) {
|
|
386
|
+
throw new Error(`Extra value must not contain a line break: ${value}`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return serializeKV(extra);
|
|
390
|
+
};
|
|
335
391
|
const serializeKV = (data) => Object.entries(data)
|
|
336
392
|
.map(([key, value]) => [key, ":", value.startsWith("\n") ? "" : " ", value].join(""))
|
|
337
393
|
.join("\n");
|
|
@@ -517,6 +573,12 @@ const verifyLogInToken = async (token, connection) => {
|
|
|
517
573
|
const isValid = await (0, crypto_js_1.verifyMessageWithKey)(sessionCryptoKey, messageStr, signature);
|
|
518
574
|
if (!isValid)
|
|
519
575
|
return;
|
|
520
|
-
|
|
576
|
+
const sessionAccount = await (0, exports.getSessionAccount)(connection, new web3_js_1.PublicKey(payload.sessionPublicKey));
|
|
577
|
+
if (!sessionAccount)
|
|
578
|
+
return;
|
|
579
|
+
if (sessionAccount.expiration.getTime() < Date.now()) {
|
|
580
|
+
throw new Error("The session associated with this login token has expired");
|
|
581
|
+
}
|
|
582
|
+
return sessionAccount;
|
|
521
583
|
};
|
|
522
584
|
exports.verifyLogInToken = verifyLogInToken;
|
package/esm/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type EstablishSessionOptions = {
|
|
|
9
9
|
walletPublicKey: PublicKey;
|
|
10
10
|
signMessage: (message: Uint8Array) => Promise<Uint8Array>;
|
|
11
11
|
expires: Date;
|
|
12
|
-
extra?: string | undefined;
|
|
12
|
+
extra?: Record<string, string> | undefined;
|
|
13
13
|
createUnsafeExtractableSessionKey?: boolean | undefined;
|
|
14
14
|
} & ({
|
|
15
15
|
limits?: Map<PublicKey, bigint>;
|
|
@@ -23,7 +23,7 @@ export declare const replaceSession: (options: {
|
|
|
23
23
|
session: Session;
|
|
24
24
|
signMessage: (message: Uint8Array) => Promise<Uint8Array>;
|
|
25
25
|
expires: Date;
|
|
26
|
-
extra?: string | undefined;
|
|
26
|
+
extra?: Record<string, string> | undefined;
|
|
27
27
|
} & ({
|
|
28
28
|
limits?: Map<PublicKey, bigint>;
|
|
29
29
|
unlimited?: false;
|
|
@@ -49,7 +49,7 @@ export declare const getSessionAccount: (connection: Connection, sessionPublicKe
|
|
|
49
49
|
expiration: Date;
|
|
50
50
|
extra: unknown;
|
|
51
51
|
major: number;
|
|
52
|
-
minor: 1 | 2;
|
|
52
|
+
minor: 1 | 2 | 3;
|
|
53
53
|
user: PublicKey;
|
|
54
54
|
sponsor: PublicKey;
|
|
55
55
|
} | undefined>;
|
|
@@ -602,6 +602,375 @@ declare const sessionInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
602
602
|
};
|
|
603
603
|
};
|
|
604
604
|
};
|
|
605
|
+
}>, z.ZodObject<{
|
|
606
|
+
V3: z.ZodObject<{
|
|
607
|
+
"0": z.ZodUnion<[z.ZodObject<{
|
|
608
|
+
Revoked: z.ZodType<BN, z.ZodTypeDef, BN>;
|
|
609
|
+
}, "strip", z.ZodTypeAny, {
|
|
610
|
+
Revoked: BN;
|
|
611
|
+
}, {
|
|
612
|
+
Revoked: BN;
|
|
613
|
+
}>, z.ZodObject<{
|
|
614
|
+
Active: z.ZodObject<{
|
|
615
|
+
"0": z.ZodObject<{
|
|
616
|
+
authorized_programs: z.ZodUnion<[z.ZodObject<{
|
|
617
|
+
Specific: z.ZodObject<{
|
|
618
|
+
0: z.ZodArray<z.ZodObject<{
|
|
619
|
+
program_id: z.ZodType<PublicKey, z.ZodTypeDef, PublicKey>;
|
|
620
|
+
signer_pda: z.ZodType<PublicKey, z.ZodTypeDef, PublicKey>;
|
|
621
|
+
}, "strip", z.ZodTypeAny, {
|
|
622
|
+
program_id: PublicKey;
|
|
623
|
+
signer_pda: PublicKey;
|
|
624
|
+
}, {
|
|
625
|
+
program_id: PublicKey;
|
|
626
|
+
signer_pda: PublicKey;
|
|
627
|
+
}>, "many">;
|
|
628
|
+
}, "strip", z.ZodTypeAny, {
|
|
629
|
+
0: {
|
|
630
|
+
program_id: PublicKey;
|
|
631
|
+
signer_pda: PublicKey;
|
|
632
|
+
}[];
|
|
633
|
+
}, {
|
|
634
|
+
0: {
|
|
635
|
+
program_id: PublicKey;
|
|
636
|
+
signer_pda: PublicKey;
|
|
637
|
+
}[];
|
|
638
|
+
}>;
|
|
639
|
+
}, "strip", z.ZodTypeAny, {
|
|
640
|
+
Specific: {
|
|
641
|
+
0: {
|
|
642
|
+
program_id: PublicKey;
|
|
643
|
+
signer_pda: PublicKey;
|
|
644
|
+
}[];
|
|
645
|
+
};
|
|
646
|
+
}, {
|
|
647
|
+
Specific: {
|
|
648
|
+
0: {
|
|
649
|
+
program_id: PublicKey;
|
|
650
|
+
signer_pda: PublicKey;
|
|
651
|
+
}[];
|
|
652
|
+
};
|
|
653
|
+
}>, z.ZodObject<{
|
|
654
|
+
All: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
655
|
+
}, "strip", z.ZodTypeAny, {
|
|
656
|
+
All: {};
|
|
657
|
+
}, {
|
|
658
|
+
All: {};
|
|
659
|
+
}>]>;
|
|
660
|
+
authorized_tokens: z.ZodUnion<[z.ZodObject<{
|
|
661
|
+
Specific: z.ZodObject<{
|
|
662
|
+
"0": z.ZodArray<z.ZodType<PublicKey, z.ZodTypeDef, PublicKey>, "many">;
|
|
663
|
+
}, "strip", z.ZodTypeAny, {
|
|
664
|
+
"0": PublicKey[];
|
|
665
|
+
}, {
|
|
666
|
+
"0": PublicKey[];
|
|
667
|
+
}>;
|
|
668
|
+
}, "strip", z.ZodTypeAny, {
|
|
669
|
+
Specific: {
|
|
670
|
+
"0": PublicKey[];
|
|
671
|
+
};
|
|
672
|
+
}, {
|
|
673
|
+
Specific: {
|
|
674
|
+
"0": PublicKey[];
|
|
675
|
+
};
|
|
676
|
+
}>, z.ZodObject<{
|
|
677
|
+
All: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
678
|
+
}, "strip", z.ZodTypeAny, {
|
|
679
|
+
All: {};
|
|
680
|
+
}, {
|
|
681
|
+
All: {};
|
|
682
|
+
}>]>;
|
|
683
|
+
expiration: z.ZodType<BN, z.ZodTypeDef, BN>;
|
|
684
|
+
extra: z.ZodObject<{
|
|
685
|
+
0: z.ZodUnknown;
|
|
686
|
+
}, "strip", z.ZodTypeAny, {
|
|
687
|
+
0?: unknown;
|
|
688
|
+
}, {
|
|
689
|
+
0?: unknown;
|
|
690
|
+
}>;
|
|
691
|
+
user: z.ZodType<PublicKey, z.ZodTypeDef, PublicKey>;
|
|
692
|
+
}, "strip", z.ZodTypeAny, {
|
|
693
|
+
authorized_programs: {
|
|
694
|
+
Specific: {
|
|
695
|
+
0: {
|
|
696
|
+
program_id: PublicKey;
|
|
697
|
+
signer_pda: PublicKey;
|
|
698
|
+
}[];
|
|
699
|
+
};
|
|
700
|
+
} | {
|
|
701
|
+
All: {};
|
|
702
|
+
};
|
|
703
|
+
authorized_tokens: {
|
|
704
|
+
Specific: {
|
|
705
|
+
"0": PublicKey[];
|
|
706
|
+
};
|
|
707
|
+
} | {
|
|
708
|
+
All: {};
|
|
709
|
+
};
|
|
710
|
+
expiration: BN;
|
|
711
|
+
extra: {
|
|
712
|
+
0?: unknown;
|
|
713
|
+
};
|
|
714
|
+
user: PublicKey;
|
|
715
|
+
}, {
|
|
716
|
+
authorized_programs: {
|
|
717
|
+
Specific: {
|
|
718
|
+
0: {
|
|
719
|
+
program_id: PublicKey;
|
|
720
|
+
signer_pda: PublicKey;
|
|
721
|
+
}[];
|
|
722
|
+
};
|
|
723
|
+
} | {
|
|
724
|
+
All: {};
|
|
725
|
+
};
|
|
726
|
+
authorized_tokens: {
|
|
727
|
+
Specific: {
|
|
728
|
+
"0": PublicKey[];
|
|
729
|
+
};
|
|
730
|
+
} | {
|
|
731
|
+
All: {};
|
|
732
|
+
};
|
|
733
|
+
expiration: BN;
|
|
734
|
+
extra: {
|
|
735
|
+
0?: unknown;
|
|
736
|
+
};
|
|
737
|
+
user: PublicKey;
|
|
738
|
+
}>;
|
|
739
|
+
}, "strip", z.ZodTypeAny, {
|
|
740
|
+
"0": {
|
|
741
|
+
authorized_programs: {
|
|
742
|
+
Specific: {
|
|
743
|
+
0: {
|
|
744
|
+
program_id: PublicKey;
|
|
745
|
+
signer_pda: PublicKey;
|
|
746
|
+
}[];
|
|
747
|
+
};
|
|
748
|
+
} | {
|
|
749
|
+
All: {};
|
|
750
|
+
};
|
|
751
|
+
authorized_tokens: {
|
|
752
|
+
Specific: {
|
|
753
|
+
"0": PublicKey[];
|
|
754
|
+
};
|
|
755
|
+
} | {
|
|
756
|
+
All: {};
|
|
757
|
+
};
|
|
758
|
+
expiration: BN;
|
|
759
|
+
extra: {
|
|
760
|
+
0?: unknown;
|
|
761
|
+
};
|
|
762
|
+
user: PublicKey;
|
|
763
|
+
};
|
|
764
|
+
}, {
|
|
765
|
+
"0": {
|
|
766
|
+
authorized_programs: {
|
|
767
|
+
Specific: {
|
|
768
|
+
0: {
|
|
769
|
+
program_id: PublicKey;
|
|
770
|
+
signer_pda: PublicKey;
|
|
771
|
+
}[];
|
|
772
|
+
};
|
|
773
|
+
} | {
|
|
774
|
+
All: {};
|
|
775
|
+
};
|
|
776
|
+
authorized_tokens: {
|
|
777
|
+
Specific: {
|
|
778
|
+
"0": PublicKey[];
|
|
779
|
+
};
|
|
780
|
+
} | {
|
|
781
|
+
All: {};
|
|
782
|
+
};
|
|
783
|
+
expiration: BN;
|
|
784
|
+
extra: {
|
|
785
|
+
0?: unknown;
|
|
786
|
+
};
|
|
787
|
+
user: PublicKey;
|
|
788
|
+
};
|
|
789
|
+
}>;
|
|
790
|
+
}, "strip", z.ZodTypeAny, {
|
|
791
|
+
Active: {
|
|
792
|
+
"0": {
|
|
793
|
+
authorized_programs: {
|
|
794
|
+
Specific: {
|
|
795
|
+
0: {
|
|
796
|
+
program_id: PublicKey;
|
|
797
|
+
signer_pda: PublicKey;
|
|
798
|
+
}[];
|
|
799
|
+
};
|
|
800
|
+
} | {
|
|
801
|
+
All: {};
|
|
802
|
+
};
|
|
803
|
+
authorized_tokens: {
|
|
804
|
+
Specific: {
|
|
805
|
+
"0": PublicKey[];
|
|
806
|
+
};
|
|
807
|
+
} | {
|
|
808
|
+
All: {};
|
|
809
|
+
};
|
|
810
|
+
expiration: BN;
|
|
811
|
+
extra: {
|
|
812
|
+
0?: unknown;
|
|
813
|
+
};
|
|
814
|
+
user: PublicKey;
|
|
815
|
+
};
|
|
816
|
+
};
|
|
817
|
+
}, {
|
|
818
|
+
Active: {
|
|
819
|
+
"0": {
|
|
820
|
+
authorized_programs: {
|
|
821
|
+
Specific: {
|
|
822
|
+
0: {
|
|
823
|
+
program_id: PublicKey;
|
|
824
|
+
signer_pda: PublicKey;
|
|
825
|
+
}[];
|
|
826
|
+
};
|
|
827
|
+
} | {
|
|
828
|
+
All: {};
|
|
829
|
+
};
|
|
830
|
+
authorized_tokens: {
|
|
831
|
+
Specific: {
|
|
832
|
+
"0": PublicKey[];
|
|
833
|
+
};
|
|
834
|
+
} | {
|
|
835
|
+
All: {};
|
|
836
|
+
};
|
|
837
|
+
expiration: BN;
|
|
838
|
+
extra: {
|
|
839
|
+
0?: unknown;
|
|
840
|
+
};
|
|
841
|
+
user: PublicKey;
|
|
842
|
+
};
|
|
843
|
+
};
|
|
844
|
+
}>]>;
|
|
845
|
+
}, "strip", z.ZodTypeAny, {
|
|
846
|
+
"0": {
|
|
847
|
+
Revoked: BN;
|
|
848
|
+
} | {
|
|
849
|
+
Active: {
|
|
850
|
+
"0": {
|
|
851
|
+
authorized_programs: {
|
|
852
|
+
Specific: {
|
|
853
|
+
0: {
|
|
854
|
+
program_id: PublicKey;
|
|
855
|
+
signer_pda: PublicKey;
|
|
856
|
+
}[];
|
|
857
|
+
};
|
|
858
|
+
} | {
|
|
859
|
+
All: {};
|
|
860
|
+
};
|
|
861
|
+
authorized_tokens: {
|
|
862
|
+
Specific: {
|
|
863
|
+
"0": PublicKey[];
|
|
864
|
+
};
|
|
865
|
+
} | {
|
|
866
|
+
All: {};
|
|
867
|
+
};
|
|
868
|
+
expiration: BN;
|
|
869
|
+
extra: {
|
|
870
|
+
0?: unknown;
|
|
871
|
+
};
|
|
872
|
+
user: PublicKey;
|
|
873
|
+
};
|
|
874
|
+
};
|
|
875
|
+
};
|
|
876
|
+
}, {
|
|
877
|
+
"0": {
|
|
878
|
+
Revoked: BN;
|
|
879
|
+
} | {
|
|
880
|
+
Active: {
|
|
881
|
+
"0": {
|
|
882
|
+
authorized_programs: {
|
|
883
|
+
Specific: {
|
|
884
|
+
0: {
|
|
885
|
+
program_id: PublicKey;
|
|
886
|
+
signer_pda: PublicKey;
|
|
887
|
+
}[];
|
|
888
|
+
};
|
|
889
|
+
} | {
|
|
890
|
+
All: {};
|
|
891
|
+
};
|
|
892
|
+
authorized_tokens: {
|
|
893
|
+
Specific: {
|
|
894
|
+
"0": PublicKey[];
|
|
895
|
+
};
|
|
896
|
+
} | {
|
|
897
|
+
All: {};
|
|
898
|
+
};
|
|
899
|
+
expiration: BN;
|
|
900
|
+
extra: {
|
|
901
|
+
0?: unknown;
|
|
902
|
+
};
|
|
903
|
+
user: PublicKey;
|
|
904
|
+
};
|
|
905
|
+
};
|
|
906
|
+
};
|
|
907
|
+
}>;
|
|
908
|
+
}, "strip", z.ZodTypeAny, {
|
|
909
|
+
V3: {
|
|
910
|
+
"0": {
|
|
911
|
+
Revoked: BN;
|
|
912
|
+
} | {
|
|
913
|
+
Active: {
|
|
914
|
+
"0": {
|
|
915
|
+
authorized_programs: {
|
|
916
|
+
Specific: {
|
|
917
|
+
0: {
|
|
918
|
+
program_id: PublicKey;
|
|
919
|
+
signer_pda: PublicKey;
|
|
920
|
+
}[];
|
|
921
|
+
};
|
|
922
|
+
} | {
|
|
923
|
+
All: {};
|
|
924
|
+
};
|
|
925
|
+
authorized_tokens: {
|
|
926
|
+
Specific: {
|
|
927
|
+
"0": PublicKey[];
|
|
928
|
+
};
|
|
929
|
+
} | {
|
|
930
|
+
All: {};
|
|
931
|
+
};
|
|
932
|
+
expiration: BN;
|
|
933
|
+
extra: {
|
|
934
|
+
0?: unknown;
|
|
935
|
+
};
|
|
936
|
+
user: PublicKey;
|
|
937
|
+
};
|
|
938
|
+
};
|
|
939
|
+
};
|
|
940
|
+
};
|
|
941
|
+
}, {
|
|
942
|
+
V3: {
|
|
943
|
+
"0": {
|
|
944
|
+
Revoked: BN;
|
|
945
|
+
} | {
|
|
946
|
+
Active: {
|
|
947
|
+
"0": {
|
|
948
|
+
authorized_programs: {
|
|
949
|
+
Specific: {
|
|
950
|
+
0: {
|
|
951
|
+
program_id: PublicKey;
|
|
952
|
+
signer_pda: PublicKey;
|
|
953
|
+
}[];
|
|
954
|
+
};
|
|
955
|
+
} | {
|
|
956
|
+
All: {};
|
|
957
|
+
};
|
|
958
|
+
authorized_tokens: {
|
|
959
|
+
Specific: {
|
|
960
|
+
"0": PublicKey[];
|
|
961
|
+
};
|
|
962
|
+
} | {
|
|
963
|
+
All: {};
|
|
964
|
+
};
|
|
965
|
+
expiration: BN;
|
|
966
|
+
extra: {
|
|
967
|
+
0?: unknown;
|
|
968
|
+
};
|
|
969
|
+
user: PublicKey;
|
|
970
|
+
};
|
|
971
|
+
};
|
|
972
|
+
};
|
|
973
|
+
};
|
|
605
974
|
}>]>;
|
|
606
975
|
major: z.ZodNumber;
|
|
607
976
|
sponsor: z.ZodType<PublicKey, z.ZodTypeDef, PublicKey>;
|
|
@@ -663,6 +1032,39 @@ declare const sessionInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
663
1032
|
};
|
|
664
1033
|
};
|
|
665
1034
|
};
|
|
1035
|
+
} | {
|
|
1036
|
+
V3: {
|
|
1037
|
+
"0": {
|
|
1038
|
+
Revoked: BN;
|
|
1039
|
+
} | {
|
|
1040
|
+
Active: {
|
|
1041
|
+
"0": {
|
|
1042
|
+
authorized_programs: {
|
|
1043
|
+
Specific: {
|
|
1044
|
+
0: {
|
|
1045
|
+
program_id: PublicKey;
|
|
1046
|
+
signer_pda: PublicKey;
|
|
1047
|
+
}[];
|
|
1048
|
+
};
|
|
1049
|
+
} | {
|
|
1050
|
+
All: {};
|
|
1051
|
+
};
|
|
1052
|
+
authorized_tokens: {
|
|
1053
|
+
Specific: {
|
|
1054
|
+
"0": PublicKey[];
|
|
1055
|
+
};
|
|
1056
|
+
} | {
|
|
1057
|
+
All: {};
|
|
1058
|
+
};
|
|
1059
|
+
expiration: BN;
|
|
1060
|
+
extra: {
|
|
1061
|
+
0?: unknown;
|
|
1062
|
+
};
|
|
1063
|
+
user: PublicKey;
|
|
1064
|
+
};
|
|
1065
|
+
};
|
|
1066
|
+
};
|
|
1067
|
+
};
|
|
666
1068
|
};
|
|
667
1069
|
major: number;
|
|
668
1070
|
}, {
|
|
@@ -723,6 +1125,39 @@ declare const sessionInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
723
1125
|
};
|
|
724
1126
|
};
|
|
725
1127
|
};
|
|
1128
|
+
} | {
|
|
1129
|
+
V3: {
|
|
1130
|
+
"0": {
|
|
1131
|
+
Revoked: BN;
|
|
1132
|
+
} | {
|
|
1133
|
+
Active: {
|
|
1134
|
+
"0": {
|
|
1135
|
+
authorized_programs: {
|
|
1136
|
+
Specific: {
|
|
1137
|
+
0: {
|
|
1138
|
+
program_id: PublicKey;
|
|
1139
|
+
signer_pda: PublicKey;
|
|
1140
|
+
}[];
|
|
1141
|
+
};
|
|
1142
|
+
} | {
|
|
1143
|
+
All: {};
|
|
1144
|
+
};
|
|
1145
|
+
authorized_tokens: {
|
|
1146
|
+
Specific: {
|
|
1147
|
+
"0": PublicKey[];
|
|
1148
|
+
};
|
|
1149
|
+
} | {
|
|
1150
|
+
All: {};
|
|
1151
|
+
};
|
|
1152
|
+
expiration: BN;
|
|
1153
|
+
extra: {
|
|
1154
|
+
0?: unknown;
|
|
1155
|
+
};
|
|
1156
|
+
user: PublicKey;
|
|
1157
|
+
};
|
|
1158
|
+
};
|
|
1159
|
+
};
|
|
1160
|
+
};
|
|
726
1161
|
};
|
|
727
1162
|
major: number;
|
|
728
1163
|
}>, {
|
|
@@ -739,7 +1174,7 @@ declare const sessionInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
739
1174
|
expiration: Date;
|
|
740
1175
|
extra: unknown;
|
|
741
1176
|
major: number;
|
|
742
|
-
minor: 1 | 2;
|
|
1177
|
+
minor: 1 | 2 | 3;
|
|
743
1178
|
user: PublicKey;
|
|
744
1179
|
sponsor: PublicKey;
|
|
745
1180
|
} | undefined, {
|
|
@@ -800,6 +1235,39 @@ declare const sessionInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
800
1235
|
};
|
|
801
1236
|
};
|
|
802
1237
|
};
|
|
1238
|
+
} | {
|
|
1239
|
+
V3: {
|
|
1240
|
+
"0": {
|
|
1241
|
+
Revoked: BN;
|
|
1242
|
+
} | {
|
|
1243
|
+
Active: {
|
|
1244
|
+
"0": {
|
|
1245
|
+
authorized_programs: {
|
|
1246
|
+
Specific: {
|
|
1247
|
+
0: {
|
|
1248
|
+
program_id: PublicKey;
|
|
1249
|
+
signer_pda: PublicKey;
|
|
1250
|
+
}[];
|
|
1251
|
+
};
|
|
1252
|
+
} | {
|
|
1253
|
+
All: {};
|
|
1254
|
+
};
|
|
1255
|
+
authorized_tokens: {
|
|
1256
|
+
Specific: {
|
|
1257
|
+
"0": PublicKey[];
|
|
1258
|
+
};
|
|
1259
|
+
} | {
|
|
1260
|
+
All: {};
|
|
1261
|
+
};
|
|
1262
|
+
expiration: BN;
|
|
1263
|
+
extra: {
|
|
1264
|
+
0?: unknown;
|
|
1265
|
+
};
|
|
1266
|
+
user: PublicKey;
|
|
1267
|
+
};
|
|
1268
|
+
};
|
|
1269
|
+
};
|
|
1270
|
+
};
|
|
803
1271
|
};
|
|
804
1272
|
major: number;
|
|
805
1273
|
}>;
|
|
@@ -872,7 +1340,7 @@ export declare const verifyLogInToken: (token: string, connection: Connection) =
|
|
|
872
1340
|
expiration: Date;
|
|
873
1341
|
extra: unknown;
|
|
874
1342
|
major: number;
|
|
875
|
-
minor: 1 | 2;
|
|
1343
|
+
minor: 1 | 2 | 3;
|
|
876
1344
|
user: PublicKey;
|
|
877
1345
|
sponsor: PublicKey;
|
|
878
1346
|
} | undefined>;
|
package/esm/index.js
CHANGED
|
@@ -20,7 +20,7 @@ Signing this intent will allow this app to interact with your on-chain balances.
|
|
|
20
20
|
const UNLIMITED_TOKEN_PERMISSIONS_VALUE = "this app may spend any amount of any token";
|
|
21
21
|
const TOKENLESS_PERMISSIONS_VALUE = "this app may not spend any tokens";
|
|
22
22
|
const CURRENT_MAJOR = "0";
|
|
23
|
-
const CURRENT_MINOR = "
|
|
23
|
+
const CURRENT_MINOR = "3";
|
|
24
24
|
const CURRENT_INTENT_TRANSFER_MAJOR = "0";
|
|
25
25
|
const CURRENT_INTENT_TRANSFER_MINOR = "1";
|
|
26
26
|
export const establishSession = async (options) => {
|
|
@@ -86,7 +86,7 @@ export const revokeSession = async (options) => {
|
|
|
86
86
|
};
|
|
87
87
|
export const reestablishSession = async (adapter, walletPublicKey, sessionKey) => createSession(adapter, walletPublicKey, sessionKey);
|
|
88
88
|
export const getSessionAccount = async (connection, sessionPublicKey) => {
|
|
89
|
-
const result = await connection.getAccountInfo(sessionPublicKey);
|
|
89
|
+
const result = await connection.getAccountInfo(sessionPublicKey, "confirmed");
|
|
90
90
|
return result === null
|
|
91
91
|
? undefined
|
|
92
92
|
: sessionInfoSchema.parse(new BorshAccountsCoder(SessionManagerIdl).decode("Session", result.data));
|
|
@@ -173,6 +173,47 @@ const sessionInfoSchema = z
|
|
|
173
173
|
]),
|
|
174
174
|
}),
|
|
175
175
|
}),
|
|
176
|
+
z.object({
|
|
177
|
+
V3: z.object({
|
|
178
|
+
"0": z.union([
|
|
179
|
+
z.object({
|
|
180
|
+
Revoked: z.instanceof(BN),
|
|
181
|
+
}),
|
|
182
|
+
z.object({
|
|
183
|
+
Active: z.object({
|
|
184
|
+
"0": z.object({
|
|
185
|
+
authorized_programs: z.union([
|
|
186
|
+
z.object({
|
|
187
|
+
Specific: z.object({
|
|
188
|
+
0: z.array(z.object({
|
|
189
|
+
program_id: z.instanceof(PublicKey),
|
|
190
|
+
signer_pda: z.instanceof(PublicKey),
|
|
191
|
+
})),
|
|
192
|
+
}),
|
|
193
|
+
}),
|
|
194
|
+
z.object({
|
|
195
|
+
All: z.object({}),
|
|
196
|
+
}),
|
|
197
|
+
]),
|
|
198
|
+
authorized_tokens: z.union([
|
|
199
|
+
z.object({
|
|
200
|
+
Specific: z.object({
|
|
201
|
+
"0": z.array(z.instanceof(PublicKey)),
|
|
202
|
+
}),
|
|
203
|
+
}),
|
|
204
|
+
z.object({ All: z.object({}) }),
|
|
205
|
+
]),
|
|
206
|
+
expiration: z.instanceof(BN),
|
|
207
|
+
extra: z.object({
|
|
208
|
+
0: z.unknown(),
|
|
209
|
+
}),
|
|
210
|
+
user: z.instanceof(PublicKey),
|
|
211
|
+
}),
|
|
212
|
+
}),
|
|
213
|
+
}),
|
|
214
|
+
]),
|
|
215
|
+
}),
|
|
216
|
+
}),
|
|
176
217
|
]),
|
|
177
218
|
major: z.number(),
|
|
178
219
|
sponsor: z.instanceof(PublicKey),
|
|
@@ -184,10 +225,14 @@ const sessionInfoSchema = z
|
|
|
184
225
|
activeSessionInfo = session_info.V1["0"];
|
|
185
226
|
minor = 1;
|
|
186
227
|
}
|
|
187
|
-
else if ("Active" in session_info.V2["0"]) {
|
|
228
|
+
else if ("V2" in session_info && "Active" in session_info.V2["0"]) {
|
|
188
229
|
activeSessionInfo = session_info.V2["0"].Active["0"];
|
|
189
230
|
minor = 2;
|
|
190
231
|
}
|
|
232
|
+
else if ("V3" in session_info && "Active" in session_info.V3["0"]) {
|
|
233
|
+
activeSessionInfo = session_info.V3["0"].Active["0"];
|
|
234
|
+
minor = 3;
|
|
235
|
+
}
|
|
191
236
|
else {
|
|
192
237
|
return;
|
|
193
238
|
}
|
|
@@ -316,9 +361,20 @@ const buildMessage = async (body) => new TextEncoder().encode([
|
|
|
316
361
|
expires: body.expires.toISOString(),
|
|
317
362
|
session_key: await getAddressFromPublicKey(body.sessionKey.publicKey),
|
|
318
363
|
tokens: serializeTokenList(body.tokens),
|
|
319
|
-
...(body.extra && { extra: body.extra }),
|
|
320
364
|
}),
|
|
365
|
+
body.extra && serializeExtra(body.extra),
|
|
321
366
|
].join("\n"));
|
|
367
|
+
const serializeExtra = (extra) => {
|
|
368
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
369
|
+
if (!/^[a-z]+(_[a-z0-9]+)*$/.test(key)) {
|
|
370
|
+
throw new Error(`Extra key must be a snake_case string: ${key}`);
|
|
371
|
+
}
|
|
372
|
+
if (value.includes("\n")) {
|
|
373
|
+
throw new Error(`Extra value must not contain a line break: ${value}`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return serializeKV(extra);
|
|
377
|
+
};
|
|
322
378
|
const serializeKV = (data) => Object.entries(data)
|
|
323
379
|
.map(([key, value]) => [key, ":", value.startsWith("\n") ? "" : " ", value].join(""))
|
|
324
380
|
.join("\n");
|
|
@@ -501,5 +557,11 @@ export const verifyLogInToken = async (token, connection) => {
|
|
|
501
557
|
const isValid = await verifyMessageWithKey(sessionCryptoKey, messageStr, signature);
|
|
502
558
|
if (!isValid)
|
|
503
559
|
return;
|
|
504
|
-
|
|
560
|
+
const sessionAccount = await getSessionAccount(connection, new PublicKey(payload.sessionPublicKey));
|
|
561
|
+
if (!sessionAccount)
|
|
562
|
+
return;
|
|
563
|
+
if (sessionAccount.expiration.getTime() < Date.now()) {
|
|
564
|
+
throw new Error("The session associated with this login token has expired");
|
|
565
|
+
}
|
|
566
|
+
return sessionAccount;
|
|
505
567
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fogo/sessions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "A set of utilities for integrating with Fogo sessions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fogo",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@metaplex-foundation/mpl-token-metadata": "^3.4.0",
|
|
32
32
|
"@metaplex-foundation/umi": "^1.2.0",
|
|
33
33
|
"@metaplex-foundation/umi-bundle-defaults": "^1.2.0",
|
|
34
|
+
"@noble/hashes": "^1.8.0",
|
|
34
35
|
"@solana/compat": "^2.1.1",
|
|
35
36
|
"@solana/kit": "^2.1.1",
|
|
36
37
|
"@solana/spl-token": "^0.4.13",
|
|
@@ -38,6 +39,6 @@
|
|
|
38
39
|
"bn.js": "^5.1.2",
|
|
39
40
|
"bs58": "^6.0.0",
|
|
40
41
|
"zod": "^3.25.62",
|
|
41
|
-
"@fogo/sessions-idls": "^0.0.
|
|
42
|
+
"@fogo/sessions-idls": "^0.0.6"
|
|
42
43
|
}
|
|
43
44
|
}
|