-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathintent.go
More file actions
1955 lines (1810 loc) · 79.8 KB
/
intent.go
File metadata and controls
1955 lines (1810 loc) · 79.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package privyclient
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"github.com/privy-io/go-sdk/internal/apijson"
"github.com/privy-io/go-sdk/internal/apiquery"
shimjson "github.com/privy-io/go-sdk/internal/encoding/json"
"github.com/privy-io/go-sdk/internal/requestconfig"
"github.com/privy-io/go-sdk/option"
"github.com/privy-io/go-sdk/packages/pagination"
"github.com/privy-io/go-sdk/packages/param"
"github.com/privy-io/go-sdk/packages/respjson"
)
// Operations related to authorization intents for wallet actions
//
// IntentService contains methods and other services that help with interacting
// with the Privy API API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewIntentService] method instead.
type IntentService struct {
Options []option.RequestOption
}
// NewIntentService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewIntentService(opts ...option.RequestOption) (r IntentService) {
r = IntentService{}
r.Options = opts
return
}
// List intents for an app. Returns a paginated list of intents with their current
// status and details.
func (r *IntentService) List(ctx context.Context, query IntentListParams, opts ...option.RequestOption) (res *pagination.Cursor[IntentResponseUnion], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "v1/intents"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List intents for an app. Returns a paginated list of intents with their current
// status and details.
func (r *IntentService) ListAutoPaging(ctx context.Context, query IntentListParams, opts ...option.RequestOption) *pagination.CursorAutoPager[IntentResponseUnion] {
return pagination.NewCursorAutoPager(r.List(ctx, query, opts...))
}
// Create an intent to add a rule to a policy. The intent must be authorized by the
// policy owner before it can be executed.
func (r *IntentService) NewPolicyRule(ctx context.Context, policyID string, params IntentNewPolicyRuleParams, opts ...option.RequestOption) (res *RuleMutateIntentResponse, err error) {
if !param.IsOmitted(params.PrivyRequestExpiry) {
opts = append(opts, option.WithHeader("privy-request-expiry", fmt.Sprintf("%v", params.PrivyRequestExpiry.Value)))
}
opts = slices.Concat(r.Options, opts)
if policyID == "" {
err = errors.New("missing required policy_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/intents/policies/%s/rules", url.PathEscape(policyID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
// Create an intent to delete a rule from a policy. The intent must be authorized
// by the policy owner before it can be executed.
func (r *IntentService) DeletePolicyRule(ctx context.Context, ruleID string, params IntentDeletePolicyRuleParams, opts ...option.RequestOption) (res *RuleDeleteIntentResponse, err error) {
if !param.IsOmitted(params.PrivyRequestExpiry) {
opts = append(opts, option.WithHeader("privy-request-expiry", fmt.Sprintf("%v", params.PrivyRequestExpiry.Value)))
}
opts = slices.Concat(r.Options, opts)
if params.PolicyID == "" {
err = errors.New("missing required policy_id parameter")
return nil, err
}
if ruleID == "" {
err = errors.New("missing required rule_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/intents/policies/%s/rules/%s", url.PathEscape(params.PolicyID), url.PathEscape(ruleID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return res, err
}
// Retrieve an intent by ID. Returns the intent details including its current
// status, authorization details, and execution result if applicable.
func (r *IntentService) Get(ctx context.Context, intentID string, opts ...option.RequestOption) (res *IntentResponseUnion, err error) {
opts = slices.Concat(r.Options, opts)
if intentID == "" {
err = errors.New("missing required intent_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/intents/%s", url.PathEscape(intentID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// Create an intent to execute an RPC method on a wallet. The intent must be
// authorized by either the wallet owner or signers before it can be executed.
func (r *IntentService) Rpc(ctx context.Context, walletID string, params IntentRpcParams, opts ...option.RequestOption) (res *RpcIntentResponse, err error) {
if !param.IsOmitted(params.PrivyRequestExpiry) {
opts = append(opts, option.WithHeader("privy-request-expiry", fmt.Sprintf("%v", params.PrivyRequestExpiry.Value)))
}
opts = slices.Concat(r.Options, opts)
if walletID == "" {
err = errors.New("missing required wallet_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/intents/wallets/%s/rpc", url.PathEscape(walletID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
// Create an intent to execute a token transfer via a wallet. The intent must be
// authorized by either the wallet owner or signers before it can be executed.
func (r *IntentService) Transfer(ctx context.Context, walletID string, params IntentTransferParams, opts ...option.RequestOption) (res *TransferIntentResponse, err error) {
if !param.IsOmitted(params.PrivyRequestExpiry) {
opts = append(opts, option.WithHeader("privy-request-expiry", fmt.Sprintf("%v", params.PrivyRequestExpiry.Value)))
}
opts = slices.Concat(r.Options, opts)
if walletID == "" {
err = errors.New("missing required wallet_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/intents/wallets/%s/transfer", url.PathEscape(walletID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
// Create an intent to update a key quorum. The intent must be authorized by the
// key quorum members before it can be executed.
func (r *IntentService) UpdateKeyQuorum(ctx context.Context, keyQuorumID string, params IntentUpdateKeyQuorumParams, opts ...option.RequestOption) (res *KeyQuorumIntentResponse, err error) {
if !param.IsOmitted(params.PrivyRequestExpiry) {
opts = append(opts, option.WithHeader("privy-request-expiry", fmt.Sprintf("%v", params.PrivyRequestExpiry.Value)))
}
opts = slices.Concat(r.Options, opts)
if keyQuorumID == "" {
err = errors.New("missing required key_quorum_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/intents/key_quorums/%s", url.PathEscape(keyQuorumID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &res, opts...)
return res, err
}
// Create an intent to update a policy. The intent must be authorized by the policy
// owner before it can be executed.
func (r *IntentService) UpdatePolicy(ctx context.Context, policyID string, params IntentUpdatePolicyParams, opts ...option.RequestOption) (res *PolicyIntentResponse, err error) {
if !param.IsOmitted(params.PrivyRequestExpiry) {
opts = append(opts, option.WithHeader("privy-request-expiry", fmt.Sprintf("%v", params.PrivyRequestExpiry.Value)))
}
opts = slices.Concat(r.Options, opts)
if policyID == "" {
err = errors.New("missing required policy_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/intents/policies/%s", url.PathEscape(policyID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &res, opts...)
return res, err
}
// Create an intent to update a rule on a policy. The intent must be authorized by
// the policy owner before it can be executed.
func (r *IntentService) UpdatePolicyRule(ctx context.Context, ruleID string, params IntentUpdatePolicyRuleParams, opts ...option.RequestOption) (res *RuleMutateIntentResponse, err error) {
if !param.IsOmitted(params.PrivyRequestExpiry) {
opts = append(opts, option.WithHeader("privy-request-expiry", fmt.Sprintf("%v", params.PrivyRequestExpiry.Value)))
}
opts = slices.Concat(r.Options, opts)
if params.PolicyID == "" {
err = errors.New("missing required policy_id parameter")
return nil, err
}
if ruleID == "" {
err = errors.New("missing required rule_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/intents/policies/%s/rules/%s", url.PathEscape(params.PolicyID), url.PathEscape(ruleID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &res, opts...)
return res, err
}
// Create an intent to update a wallet. The intent must be authorized by the wallet
// owner before it can be executed.
func (r *IntentService) UpdateWallet(ctx context.Context, walletID string, params IntentUpdateWalletParams, opts ...option.RequestOption) (res *WalletIntentResponse, err error) {
if !param.IsOmitted(params.PrivyRequestExpiry) {
opts = append(opts, option.WithHeader("privy-request-expiry", fmt.Sprintf("%v", params.PrivyRequestExpiry.Value)))
}
opts = slices.Concat(r.Options, opts)
if walletID == "" {
err = errors.New("missing required wallet_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/intents/wallets/%s", url.PathEscape(walletID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &res, opts...)
return res, err
}
// Common fields for intent action execution results.
type BaseActionResult struct {
// Unix timestamp when the action was executed
ExecutedAt float64 `json:"executed_at" api:"required"`
// HTTP status code from the action execution
StatusCode float64 `json:"status_code" api:"required"`
// Display name of the key quorum that authorized execution
AuthorizedByDisplayName string `json:"authorized_by_display_name"`
// ID of the key quorum that authorized execution
AuthorizedByID string `json:"authorized_by_id"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ExecutedAt respjson.Field
StatusCode respjson.Field
AuthorizedByDisplayName respjson.Field
AuthorizedByID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BaseActionResult) RawJSON() string { return r.JSON.raw }
func (r *BaseActionResult) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Common fields shared by all intent response types.
type BaseIntentResponse struct {
// Detailed authorization information including key quorum members, thresholds, and
// signature status
AuthorizationDetails []IntentAuthorization `json:"authorization_details" api:"required"`
// Unix timestamp when the intent was created
CreatedAt float64 `json:"created_at" api:"required"`
// Display name of the user who created the intent
CreatedByDisplayName string `json:"created_by_display_name" api:"required"`
// Whether this intent has a custom expiry time set by the client. If false, the
// intent expires after a default duration.
CustomExpiry bool `json:"custom_expiry" api:"required"`
// Unix timestamp when the intent expires
ExpiresAt float64 `json:"expires_at" api:"required"`
// Unique ID for the intent
IntentID string `json:"intent_id" api:"required"`
// ID of the resource being modified (wallet_id, policy_id, etc)
ResourceID string `json:"resource_id" api:"required"`
// Current status of an intent.
//
// Any of "pending", "processing", "executed", "failed", "expired", "rejected",
// "dismissed".
Status IntentStatus `json:"status" api:"required"`
// ID of the user who created the intent. If undefined, the intent was created
// using the app secret
CreatedByID string `json:"created_by_id"`
// Human-readable reason for dismissal, present when status is 'dismissed'
DismissalReason string `json:"dismissal_reason"`
// Unix timestamp when the intent was dismissed, present when status is 'dismissed'
DismissedAt float64 `json:"dismissed_at"`
// Unix timestamp when the intent was rejected, present when status is 'rejected'
RejectedAt float64 `json:"rejected_at"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
AuthorizationDetails respjson.Field
CreatedAt respjson.Field
CreatedByDisplayName respjson.Field
CustomExpiry respjson.Field
ExpiresAt respjson.Field
IntentID respjson.Field
ResourceID respjson.Field
Status respjson.Field
CreatedByID respjson.Field
DismissalReason respjson.Field
DismissedAt respjson.Field
RejectedAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BaseIntentResponse) RawJSON() string { return r.JSON.raw }
func (r *BaseIntentResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Authorization quorum for an intent
type IntentAuthorization struct {
// Members in this authorization quorum
Members []IntentAuthorizationMemberUnion `json:"members" api:"required"`
// Number of signatures required to satisfy this quorum
Threshold float64 `json:"threshold" api:"required"`
// Display name of the key quorum
DisplayName string `json:"display_name"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Members respjson.Field
Threshold respjson.Field
DisplayName respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r IntentAuthorization) RawJSON() string { return r.JSON.raw }
func (r *IntentAuthorization) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// IntentAuthorizationKeyQuorumMemberUnion contains all possible properties and
// values from [IntentAuthorizationKeyQuorumMemberUserMember],
// [IntentAuthorizationKeyQuorumMemberKeyMember].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type IntentAuthorizationKeyQuorumMemberUnion struct {
SignedAt float64 `json:"signed_at"`
Type string `json:"type"`
// This field is from variant [IntentAuthorizationKeyQuorumMemberUserMember].
UserID string `json:"user_id"`
// This field is from variant [IntentAuthorizationKeyQuorumMemberKeyMember].
PublicKey string `json:"public_key"`
JSON struct {
SignedAt respjson.Field
Type respjson.Field
UserID respjson.Field
PublicKey respjson.Field
raw string
} `json:"-"`
}
func (u IntentAuthorizationKeyQuorumMemberUnion) AsUserMember() (v IntentAuthorizationKeyQuorumMemberUserMember) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u IntentAuthorizationKeyQuorumMemberUnion) AsKeyMember() (v IntentAuthorizationKeyQuorumMemberKeyMember) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u IntentAuthorizationKeyQuorumMemberUnion) RawJSON() string { return u.JSON.raw }
func (r *IntentAuthorizationKeyQuorumMemberUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type IntentAuthorizationKeyQuorumMemberUserMember struct {
// Unix timestamp when this member signed, or null if not yet signed.
SignedAt float64 `json:"signed_at" api:"required"`
// Any of "user".
Type string `json:"type" api:"required"`
// User ID of the key quorum member
UserID string `json:"user_id" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
SignedAt respjson.Field
Type respjson.Field
UserID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r IntentAuthorizationKeyQuorumMemberUserMember) RawJSON() string { return r.JSON.raw }
func (r *IntentAuthorizationKeyQuorumMemberUserMember) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type IntentAuthorizationKeyQuorumMemberKeyMember struct {
// Public key of the key quorum member
PublicKey string `json:"public_key" api:"required"`
// Unix timestamp when this member signed, or null if not yet signed.
SignedAt float64 `json:"signed_at" api:"required"`
// Any of "key".
Type string `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
PublicKey respjson.Field
SignedAt respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r IntentAuthorizationKeyQuorumMemberKeyMember) RawJSON() string { return r.JSON.raw }
func (r *IntentAuthorizationKeyQuorumMemberKeyMember) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// IntentAuthorizationMemberUnion contains all possible properties and values from
// [IntentAuthorizationMemberUserMember], [IntentAuthorizationMemberKeyMember],
// [IntentAuthorizationMemberKeyQuorumMember].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type IntentAuthorizationMemberUnion struct {
SignedAt float64 `json:"signed_at"`
Type string `json:"type"`
// This field is from variant [IntentAuthorizationMemberUserMember].
UserID string `json:"user_id"`
// This field is from variant [IntentAuthorizationMemberKeyMember].
PublicKey string `json:"public_key"`
// This field is from variant [IntentAuthorizationMemberKeyQuorumMember].
KeyQuorumID string `json:"key_quorum_id"`
// This field is from variant [IntentAuthorizationMemberKeyQuorumMember].
Members []IntentAuthorizationKeyQuorumMemberUnion `json:"members"`
// This field is from variant [IntentAuthorizationMemberKeyQuorumMember].
Threshold float64 `json:"threshold"`
// This field is from variant [IntentAuthorizationMemberKeyQuorumMember].
ThresholdMet bool `json:"threshold_met"`
// This field is from variant [IntentAuthorizationMemberKeyQuorumMember].
DisplayName string `json:"display_name"`
JSON struct {
SignedAt respjson.Field
Type respjson.Field
UserID respjson.Field
PublicKey respjson.Field
KeyQuorumID respjson.Field
Members respjson.Field
Threshold respjson.Field
ThresholdMet respjson.Field
DisplayName respjson.Field
raw string
} `json:"-"`
}
func (u IntentAuthorizationMemberUnion) AsUserMember() (v IntentAuthorizationMemberUserMember) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u IntentAuthorizationMemberUnion) AsKeyMember() (v IntentAuthorizationMemberKeyMember) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u IntentAuthorizationMemberUnion) AsKeyQuorumMember() (v IntentAuthorizationMemberKeyQuorumMember) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u IntentAuthorizationMemberUnion) RawJSON() string { return u.JSON.raw }
func (r *IntentAuthorizationMemberUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type IntentAuthorizationMemberUserMember struct {
// Unix timestamp when this member signed, or null if not yet signed.
SignedAt float64 `json:"signed_at" api:"required"`
// Any of "user".
Type string `json:"type" api:"required"`
// User ID of the key quorum member
UserID string `json:"user_id" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
SignedAt respjson.Field
Type respjson.Field
UserID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r IntentAuthorizationMemberUserMember) RawJSON() string { return r.JSON.raw }
func (r *IntentAuthorizationMemberUserMember) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type IntentAuthorizationMemberKeyMember struct {
// Public key of the key quorum member
PublicKey string `json:"public_key" api:"required"`
// Unix timestamp when this member signed, or null if not yet signed.
SignedAt float64 `json:"signed_at" api:"required"`
// Any of "key".
Type string `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
PublicKey respjson.Field
SignedAt respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r IntentAuthorizationMemberKeyMember) RawJSON() string { return r.JSON.raw }
func (r *IntentAuthorizationMemberKeyMember) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type IntentAuthorizationMemberKeyQuorumMember struct {
// ID of the child key quorum member
KeyQuorumID string `json:"key_quorum_id" api:"required"`
// Members of this child quorum
Members []IntentAuthorizationKeyQuorumMemberUnion `json:"members" api:"required"`
// Number of signatures required from this child quorum
Threshold float64 `json:"threshold" api:"required"`
// Whether this child key quorum has met its signature threshold
ThresholdMet bool `json:"threshold_met" api:"required"`
// Any of "key_quorum".
Type string `json:"type" api:"required"`
// Display name for the child key quorum (if any)
DisplayName string `json:"display_name"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
KeyQuorumID respjson.Field
Members respjson.Field
Threshold respjson.Field
ThresholdMet respjson.Field
Type respjson.Field
DisplayName respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r IntentAuthorizationMemberKeyQuorumMember) RawJSON() string { return r.JSON.raw }
func (r *IntentAuthorizationMemberKeyQuorumMember) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// IntentResponseUnion contains all possible properties and values from
// [RpcIntentResponse], [TransferIntentResponse], [WalletIntentResponse],
// [PolicyIntentResponse], [RuleIntentResponse], [KeyQuorumIntentResponse].
//
// Use the [IntentResponseUnion.AsAny] method to switch on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type IntentResponseUnion struct {
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
AuthorizationDetails []IntentAuthorization `json:"authorization_details"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
CreatedAt float64 `json:"created_at"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
CreatedByDisplayName string `json:"created_by_display_name"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
CustomExpiry bool `json:"custom_expiry"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
ExpiresAt float64 `json:"expires_at"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
IntentID string `json:"intent_id"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
ResourceID string `json:"resource_id"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
Status IntentStatus `json:"status"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
CreatedByID string `json:"created_by_id"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
DismissalReason string `json:"dismissal_reason"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
DismissedAt float64 `json:"dismissed_at"`
// This field is from variant [RpcIntentResponse], [TransferIntentResponse],
// [WalletIntentResponse], [PolicyIntentResponse], [RuleIntentResponse],
// [KeyQuorumIntentResponse].
RejectedAt float64 `json:"rejected_at"`
// Any of "RPC", "TRANSFER", "WALLET", "POLICY", "RULE", "KEY_QUORUM".
IntentType string `json:"intent_type"`
// This field is a union of [RpcIntentResponseRequestDetails],
// [TransferIntentResponseRequestDetails], [WalletIntentResponseRequestDetails],
// [PolicyIntentResponseRequestDetails], [RuleIntentRequestDetailsUnion],
// [KeyQuorumIntentResponseRequestDetails]
RequestDetails IntentResponseUnionRequestDetails `json:"request_details"`
// This field is from variant [RpcIntentResponse].
ActionResult BaseActionResult `json:"action_result"`
// This field is a union of [Wallet], [Policy], [PolicyRuleResponse], [KeyQuorum]
CurrentResourceData IntentResponseUnionCurrentResourceData `json:"current_resource_data"`
// This field is from variant [RuleIntentResponse].
Policy Policy `json:"policy"`
JSON struct {
AuthorizationDetails respjson.Field
CreatedAt respjson.Field
CreatedByDisplayName respjson.Field
CustomExpiry respjson.Field
ExpiresAt respjson.Field
IntentID respjson.Field
ResourceID respjson.Field
Status respjson.Field
CreatedByID respjson.Field
DismissalReason respjson.Field
DismissedAt respjson.Field
RejectedAt respjson.Field
IntentType respjson.Field
RequestDetails respjson.Field
ActionResult respjson.Field
CurrentResourceData respjson.Field
Policy respjson.Field
raw string
} `json:"-"`
}
// anyIntentResponse is implemented by each variant of [IntentResponseUnion] to add
// type safety for the return type of [IntentResponseUnion.AsAny]
type anyIntentResponse interface {
implIntentResponseUnion()
}
func (RpcIntentResponse) implIntentResponseUnion() {}
func (TransferIntentResponse) implIntentResponseUnion() {}
func (WalletIntentResponse) implIntentResponseUnion() {}
func (PolicyIntentResponse) implIntentResponseUnion() {}
func (RuleIntentResponse) implIntentResponseUnion() {}
func (KeyQuorumIntentResponse) implIntentResponseUnion() {}
// Use the following switch statement to find the correct variant
//
// switch variant := IntentResponseUnion.AsAny().(type) {
// case privyclient.RpcIntentResponse:
// case privyclient.TransferIntentResponse:
// case privyclient.WalletIntentResponse:
// case privyclient.PolicyIntentResponse:
// case privyclient.RuleIntentResponse:
// case privyclient.KeyQuorumIntentResponse:
// default:
// fmt.Errorf("no variant present")
// }
func (u IntentResponseUnion) AsAny() anyIntentResponse {
switch u.IntentType {
case "RPC":
return u.AsRpc()
case "TRANSFER":
return u.AsTransfer()
case "WALLET":
return u.AsWallet()
case "POLICY":
return u.AsPolicy()
case "RULE":
return u.AsRule()
case "KEY_QUORUM":
return u.AsKeyQuorum()
}
return nil
}
func (u IntentResponseUnion) AsRpc() (v RpcIntentResponse) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u IntentResponseUnion) AsTransfer() (v TransferIntentResponse) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u IntentResponseUnion) AsWallet() (v WalletIntentResponse) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u IntentResponseUnion) AsPolicy() (v PolicyIntentResponse) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u IntentResponseUnion) AsRule() (v RuleIntentResponse) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u IntentResponseUnion) AsKeyQuorum() (v KeyQuorumIntentResponse) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u IntentResponseUnion) RawJSON() string { return u.JSON.raw }
func (r *IntentResponseUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// IntentResponseUnionRequestDetails is an implicit subunion of
// [IntentResponseUnion]. IntentResponseUnionRequestDetails provides convenient
// access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [IntentResponseUnion].
type IntentResponseUnionRequestDetails struct {
// This field is a union of [WalletRpcRequestBodyUnionResp],
// [TransferRequestBodyResp], [WalletIntentResponseRequestDetailsBody],
// [PolicyIntentResponseRequestDetailsBody], [PolicyRuleRequestBodyResp],
// [RuleIntentDeleteRequestDetailsBody], [KeyQuorumUpdateRequestBodyResp]
Body IntentResponseUnionRequestDetailsBody `json:"body"`
Method string `json:"method"`
URL string `json:"url"`
JSON struct {
Body respjson.Field
Method respjson.Field
URL respjson.Field
raw string
} `json:"-"`
}
func (r *IntentResponseUnionRequestDetails) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// IntentResponseUnionRequestDetailsBody is an implicit subunion of
// [IntentResponseUnion]. IntentResponseUnionRequestDetailsBody provides convenient
// access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [IntentResponseUnion].
type IntentResponseUnionRequestDetailsBody struct {
Method string `json:"method"`
// This field is a union of [EthereumSignTransactionRpcInputParamsResp],
// [EthereumSendTransactionRpcInputParamsResp],
// [EthereumPersonalSignRpcInputParamsResp],
// [EthereumSignTypedDataRpcInputParamsResp],
// [EthereumSecp256k1SignRpcInputParamsResp],
// [EthereumSign7702AuthorizationRpcInputParamsResp],
// [EthereumSignUserOperationRpcInputParamsResp],
// [EthereumSendCallsRpcInputParamsResp],
// [SolanaSignTransactionRpcInputParamsResp],
// [SolanaSignAndSendTransactionRpcInputParamsResp],
// [SolanaSignMessageRpcInputParamsResp], [SparkTransferRpcInputParamsResp],
// [SparkTransferTokensRpcInputParamsResp],
// [SparkGetClaimStaticDepositQuoteRpcInputParamsResp],
// [SparkClaimStaticDepositRpcInputParamsResp],
// [SparkCreateLightningInvoiceRpcInputParamsResp],
// [SparkPayLightningInvoiceRpcInputParamsResp],
// [SparkSignMessageWithIdentityKeyRpcInputParamsResp],
// [PrivateKeyExportInputResp], [SeedPhraseExportInputResp]
Params IntentResponseUnionRequestDetailsBodyParams `json:"params"`
Address string `json:"address"`
ChainType string `json:"chain_type"`
WalletID string `json:"wallet_id"`
// This field is from variant [WalletRpcRequestBodyUnionResp].
Caip2 Caip2 `json:"caip2"`
// This field is from variant [WalletRpcRequestBodyUnionResp].
ExperimentalDataSuffix Hex `json:"experimental_data_suffix"`
ReferenceID string `json:"reference_id"`
Sponsor bool `json:"sponsor"`
// This field is from variant [WalletRpcRequestBodyUnionResp].
OptimisticBroadcast bool `json:"optimistic_broadcast"`
// This field is from variant [WalletRpcRequestBodyUnionResp].
Network SparkNetwork `json:"network"`
// This field is from variant [TransferRequestBodyResp].
Destination TokenTransferDestinationResp `json:"destination"`
// This field is from variant [TransferRequestBodyResp].
Source TokenTransferSourceUnionResp `json:"source"`
// This field is from variant [TransferRequestBodyResp].
AmountType AmountType `json:"amount_type"`
// This field is from variant [TransferRequestBodyResp].
FeeConfiguration FeeConfigurationResp `json:"fee_configuration"`
// This field is from variant [TransferRequestBodyResp].
SlippageBps int64 `json:"slippage_bps"`
// This field is from variant [WalletIntentResponseRequestDetailsBody].
AdditionalSigners AdditionalSignerInputResp `json:"additional_signers"`
// This field is from variant [WalletIntentResponseRequestDetailsBody].
AuthorizationKeyIDs []string `json:"authorization_key_ids"`
AuthorizationThreshold float64 `json:"authorization_threshold"`
DisplayName string `json:"display_name"`
// This field is from variant [WalletIntentResponseRequestDetailsBody].
Owner OwnerInputUnionResp `json:"owner"`
// This field is from variant [WalletIntentResponseRequestDetailsBody].
OwnerID OwnerIDInput `json:"owner_id"`
// This field is from variant [WalletIntentResponseRequestDetailsBody].
PolicyIDs PolicyInput `json:"policy_ids"`
Name string `json:"name"`
// This field is from variant [PolicyIntentResponseRequestDetailsBody].
Rules []PolicyRuleRequestBodyResp `json:"rules"`
// This field is from variant [PolicyRuleRequestBodyResp].
Action PolicyAction `json:"action"`
// This field is from variant [PolicyRuleRequestBodyResp].
Conditions []PolicyConditionUnionResp `json:"conditions"`
// This field is from variant [KeyQuorumUpdateRequestBodyResp].
KeyQuorumIDs []string `json:"key_quorum_ids"`
// This field is from variant [KeyQuorumUpdateRequestBodyResp].
PublicKeys []string `json:"public_keys"`
// This field is from variant [KeyQuorumUpdateRequestBodyResp].
UserIDs []string `json:"user_ids"`
JSON struct {
Method respjson.Field
Params respjson.Field
Address respjson.Field
ChainType respjson.Field
WalletID respjson.Field
Caip2 respjson.Field
ExperimentalDataSuffix respjson.Field
ReferenceID respjson.Field
Sponsor respjson.Field
OptimisticBroadcast respjson.Field
Network respjson.Field
Destination respjson.Field
Source respjson.Field
AmountType respjson.Field
FeeConfiguration respjson.Field
SlippageBps respjson.Field
AdditionalSigners respjson.Field
AuthorizationKeyIDs respjson.Field
AuthorizationThreshold respjson.Field
DisplayName respjson.Field
Owner respjson.Field
OwnerID respjson.Field
PolicyIDs respjson.Field
Name respjson.Field
Rules respjson.Field
Action respjson.Field
Conditions respjson.Field
KeyQuorumIDs respjson.Field
PublicKeys respjson.Field
UserIDs respjson.Field
raw string
} `json:"-"`
}
func (r *IntentResponseUnionRequestDetailsBody) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// IntentResponseUnionRequestDetailsBodyParams is an implicit subunion of
// [IntentResponseUnion]. IntentResponseUnionRequestDetailsBodyParams provides
// convenient access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [IntentResponseUnion].
type IntentResponseUnionRequestDetailsBodyParams struct {
// This field is a union of [UnsignedEthereumTransactionUnionResp], [string],
// [string]
Transaction IntentResponseUnionRequestDetailsBodyParamsTransaction `json:"transaction"`
Encoding string `json:"encoding"`
Message string `json:"message"`
// This field is from variant [EthereumSignTypedDataRpcInputParamsResp].
TypedData EthereumTypedDataInputResp `json:"typed_data"`
// This field is from variant [EthereumSecp256k1SignRpcInputParamsResp].
Hash Hex `json:"hash"`
// This field is from variant [EthereumSign7702AuthorizationRpcInputParamsResp].
ChainID QuantityUnionResp `json:"chain_id"`
Contract string `json:"contract"`
// This field is from variant [EthereumSign7702AuthorizationRpcInputParamsResp].
Executor EthereumSign7702AuthorizationRpcInputParamsExecutor `json:"executor"`
// This field is from variant [EthereumSign7702AuthorizationRpcInputParamsResp].
Nonce QuantityUnionResp `json:"nonce"`
// This field is from variant [EthereumSignUserOperationRpcInputParamsResp].
UserOperation UserOperationInputResp `json:"user_operation"`
// This field is from variant [EthereumSendCallsRpcInputParamsResp].
Calls []EthereumSendCallsCallResp `json:"calls"`
AmountSats float64 `json:"amount_sats"`
ReceiverSparkAddress string `json:"receiver_spark_address"`
// This field is from variant [SparkTransferTokensRpcInputParamsResp].
TokenAmount float64 `json:"token_amount"`
// This field is from variant [SparkTransferTokensRpcInputParamsResp].
TokenIdentifier string `json:"token_identifier"`
// This field is from variant [SparkTransferTokensRpcInputParamsResp].
OutputSelectionStrategy SparkOutputSelectionStrategy `json:"output_selection_strategy"`
// This field is from variant [SparkTransferTokensRpcInputParamsResp].
SelectedOutputs []OutputWithPreviousTransactionDataResp `json:"selected_outputs"`
TransactionID string `json:"transaction_id"`
OutputIndex float64 `json:"output_index"`
// This field is from variant [SparkClaimStaticDepositRpcInputParamsResp].
CreditAmountSats float64 `json:"credit_amount_sats"`
// This field is from variant [SparkClaimStaticDepositRpcInputParamsResp].
Signature string `json:"signature"`
// This field is from variant [SparkCreateLightningInvoiceRpcInputParamsResp].
DescriptionHash string `json:"description_hash"`
// This field is from variant [SparkCreateLightningInvoiceRpcInputParamsResp].
ExpirySeconds float64 `json:"expiry_seconds"`
// This field is from variant [SparkCreateLightningInvoiceRpcInputParamsResp].
IncludeSparkAddress bool `json:"include_spark_address"`
// This field is from variant [SparkCreateLightningInvoiceRpcInputParamsResp].
Memo string `json:"memo"`
// This field is from variant [SparkCreateLightningInvoiceRpcInputParamsResp].
ReceiverIdentityPubkey string `json:"receiver_identity_pubkey"`
// This field is from variant [SparkPayLightningInvoiceRpcInputParamsResp].
Invoice string `json:"invoice"`
// This field is from variant [SparkPayLightningInvoiceRpcInputParamsResp].
MaxFeeSats float64 `json:"max_fee_sats"`
// This field is from variant [SparkPayLightningInvoiceRpcInputParamsResp].
AmountSatsToSend float64 `json:"amount_sats_to_send"`
// This field is from variant [SparkPayLightningInvoiceRpcInputParamsResp].
PreferSpark bool `json:"prefer_spark"`
// This field is from variant [SparkSignMessageWithIdentityKeyRpcInputParamsResp].
Compact bool `json:"compact"`
// This field is from variant [PrivateKeyExportInputResp].
EncryptionType HpkeEncryption `json:"encryption_type"`
// This field is from variant [PrivateKeyExportInputResp].
RecipientPublicKey RecipientPublicKey `json:"recipient_public_key"`
ExportSeedPhrase bool `json:"export_seed_phrase"`
// This field is from variant [PrivateKeyExportInputResp].
ExportType ExportType `json:"export_type"`
JSON struct {
Transaction respjson.Field
Encoding respjson.Field
Message respjson.Field
TypedData respjson.Field
Hash respjson.Field
ChainID respjson.Field
Contract respjson.Field
Executor respjson.Field
Nonce respjson.Field
UserOperation respjson.Field
Calls respjson.Field
AmountSats respjson.Field
ReceiverSparkAddress respjson.Field
TokenAmount respjson.Field
TokenIdentifier respjson.Field
OutputSelectionStrategy respjson.Field
SelectedOutputs respjson.Field
TransactionID respjson.Field
OutputIndex respjson.Field
CreditAmountSats respjson.Field
Signature respjson.Field
DescriptionHash respjson.Field
ExpirySeconds respjson.Field
IncludeSparkAddress respjson.Field
Memo respjson.Field
ReceiverIdentityPubkey respjson.Field
Invoice respjson.Field
MaxFeeSats respjson.Field
AmountSatsToSend respjson.Field
PreferSpark respjson.Field
Compact respjson.Field
EncryptionType respjson.Field
RecipientPublicKey respjson.Field
ExportSeedPhrase respjson.Field
ExportType respjson.Field
raw string
} `json:"-"`
}
func (r *IntentResponseUnionRequestDetailsBodyParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// IntentResponseUnionRequestDetailsBodyParamsTransaction is an implicit subunion
// of [IntentResponseUnion]. IntentResponseUnionRequestDetailsBodyParamsTransaction
// provides convenient access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [IntentResponseUnion].
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfString]
type IntentResponseUnionRequestDetailsBodyParamsTransaction struct {
// This field will be present if the value is a [string] instead of an object.
OfString string `json:",inline"`
// This field is from variant [UnsignedEthereumTransactionUnionResp].
AuthorizationList []EthereumSign7702AuthorizationResp `json:"authorization_list"`
// This field is from variant [UnsignedEthereumTransactionUnionResp].
ChainID QuantityUnionResp `json:"chain_id"`
// This field is from variant [UnsignedEthereumTransactionUnionResp].
Data Hex `json:"data"`
From string `json:"from"`
// This field is from variant [UnsignedEthereumTransactionUnionResp].
GasLimit QuantityUnionResp `json:"gas_limit"`
// This field is from variant [UnsignedEthereumTransactionUnionResp].
GasPrice QuantityUnionResp `json:"gas_price"`
// This field is from variant [UnsignedEthereumTransactionUnionResp].
MaxFeePerGas QuantityUnionResp `json:"max_fee_per_gas"`
// This field is from variant [UnsignedEthereumTransactionUnionResp].
MaxPriorityFeePerGas QuantityUnionResp `json:"max_priority_fee_per_gas"`
// This field is from variant [UnsignedEthereumTransactionUnionResp].
Nonce QuantityUnionResp `json:"nonce"`