@privy-io/node 0.6.2 → 0.8.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.
Files changed (134) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/client.d.mts +10 -7
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +10 -7
  5. package/client.d.ts.map +1 -1
  6. package/client.js +3 -0
  7. package/client.js.map +1 -1
  8. package/client.mjs +3 -0
  9. package/client.mjs.map +1 -1
  10. package/index.d.mts +2 -1
  11. package/index.d.mts.map +1 -1
  12. package/index.d.ts +2 -1
  13. package/index.d.ts.map +1 -1
  14. package/index.js +4 -1
  15. package/index.js.map +1 -1
  16. package/index.mjs +2 -1
  17. package/index.mjs.map +1 -1
  18. package/lib/auth.d.mts +30 -2
  19. package/lib/auth.d.mts.map +1 -1
  20. package/lib/auth.d.ts +30 -2
  21. package/lib/auth.d.ts.map +1 -1
  22. package/lib/auth.js +14 -5
  23. package/lib/auth.js.map +1 -1
  24. package/lib/auth.mjs +11 -3
  25. package/lib/auth.mjs.map +1 -1
  26. package/lib/cryptography.d.mts +35 -3
  27. package/lib/cryptography.d.mts.map +1 -1
  28. package/lib/cryptography.d.ts +35 -3
  29. package/lib/cryptography.d.ts.map +1 -1
  30. package/lib/cryptography.js +53 -6
  31. package/lib/cryptography.js.map +1 -1
  32. package/lib/cryptography.mjs +50 -3
  33. package/lib/cryptography.mjs.map +1 -1
  34. package/lib/identity-token.d.mts.map +1 -1
  35. package/lib/identity-token.d.ts.map +1 -1
  36. package/lib/identity-token.js +0 -1
  37. package/lib/identity-token.js.map +1 -1
  38. package/lib/identity-token.mjs +0 -1
  39. package/lib/identity-token.mjs.map +1 -1
  40. package/package.json +13 -1
  41. package/public-api/services/utils/auth.d.mts +10 -1
  42. package/public-api/services/utils/auth.d.mts.map +1 -1
  43. package/public-api/services/utils/auth.d.ts +10 -1
  44. package/public-api/services/utils/auth.d.ts.map +1 -1
  45. package/public-api/services/utils/auth.js +16 -5
  46. package/public-api/services/utils/auth.js.map +1 -1
  47. package/public-api/services/utils/auth.mjs +17 -6
  48. package/public-api/services/utils/auth.mjs.map +1 -1
  49. package/resources/aggregations.d.mts +296 -0
  50. package/resources/aggregations.d.mts.map +1 -0
  51. package/resources/aggregations.d.ts +296 -0
  52. package/resources/aggregations.d.ts.map +1 -0
  53. package/resources/aggregations.js +9 -0
  54. package/resources/aggregations.js.map +1 -0
  55. package/resources/aggregations.mjs +5 -0
  56. package/resources/aggregations.mjs.map +1 -0
  57. package/resources/apps.d.mts +25 -0
  58. package/resources/apps.d.mts.map +1 -1
  59. package/resources/apps.d.ts +25 -0
  60. package/resources/apps.d.ts.map +1 -1
  61. package/resources/index.d.mts +4 -3
  62. package/resources/index.d.mts.map +1 -1
  63. package/resources/index.d.ts +4 -3
  64. package/resources/index.d.ts.map +1 -1
  65. package/resources/index.js +3 -1
  66. package/resources/index.js.map +1 -1
  67. package/resources/index.mjs +1 -0
  68. package/resources/index.mjs.map +1 -1
  69. package/resources/key-quorums.d.mts +4 -1
  70. package/resources/key-quorums.d.mts.map +1 -1
  71. package/resources/key-quorums.d.ts +4 -1
  72. package/resources/key-quorums.d.ts.map +1 -1
  73. package/resources/policies.d.mts +87 -131
  74. package/resources/policies.d.mts.map +1 -1
  75. package/resources/policies.d.ts +87 -131
  76. package/resources/policies.d.ts.map +1 -1
  77. package/resources/policies.js.map +1 -1
  78. package/resources/policies.mjs.map +1 -1
  79. package/resources/users.d.mts +642 -381
  80. package/resources/users.d.mts.map +1 -1
  81. package/resources/users.d.ts +642 -381
  82. package/resources/users.d.ts.map +1 -1
  83. package/resources/wallets/balance.d.mts +3 -3
  84. package/resources/wallets/balance.d.mts.map +1 -1
  85. package/resources/wallets/balance.d.ts +3 -3
  86. package/resources/wallets/balance.d.ts.map +1 -1
  87. package/resources/wallets/index.d.mts +1 -1
  88. package/resources/wallets/index.d.mts.map +1 -1
  89. package/resources/wallets/index.d.ts +1 -1
  90. package/resources/wallets/index.d.ts.map +1 -1
  91. package/resources/wallets/index.js.map +1 -1
  92. package/resources/wallets/index.mjs.map +1 -1
  93. package/resources/wallets/transactions.d.mts +3 -3
  94. package/resources/wallets/transactions.d.mts.map +1 -1
  95. package/resources/wallets/transactions.d.ts +3 -3
  96. package/resources/wallets/transactions.d.ts.map +1 -1
  97. package/resources/wallets/wallets.d.mts +215 -53
  98. package/resources/wallets/wallets.d.mts.map +1 -1
  99. package/resources/wallets/wallets.d.ts +215 -53
  100. package/resources/wallets/wallets.d.ts.map +1 -1
  101. package/resources/wallets/wallets.js +1 -1
  102. package/resources/wallets/wallets.js.map +1 -1
  103. package/resources/wallets/wallets.mjs +1 -1
  104. package/resources/wallets/wallets.mjs.map +1 -1
  105. package/solana-kit.d.mts +53 -0
  106. package/solana-kit.d.mts.map +1 -0
  107. package/solana-kit.d.ts +53 -0
  108. package/solana-kit.d.ts.map +1 -0
  109. package/solana-kit.js +92 -0
  110. package/solana-kit.js.map +1 -0
  111. package/solana-kit.mjs +89 -0
  112. package/solana-kit.mjs.map +1 -0
  113. package/src/client.ts +150 -3
  114. package/src/index.ts +5 -0
  115. package/src/lib/auth.ts +42 -6
  116. package/src/lib/cryptography.ts +72 -3
  117. package/src/lib/identity-token.ts +38 -18
  118. package/src/public-api/services/utils/auth.ts +19 -6
  119. package/src/resources/aggregations.ts +497 -0
  120. package/src/resources/apps.ts +44 -0
  121. package/src/resources/index.ts +74 -2
  122. package/src/resources/key-quorums.ts +4 -1
  123. package/src/resources/policies.ts +124 -207
  124. package/src/resources/users.ts +942 -625
  125. package/src/resources/wallets/balance.ts +11 -3
  126. package/src/resources/wallets/index.ts +6 -0
  127. package/src/resources/wallets/transactions.ts +11 -3
  128. package/src/resources/wallets/wallets.ts +283 -52
  129. package/src/solana-kit.ts +148 -0
  130. package/src/version.ts +1 -1
  131. package/version.d.mts +1 -1
  132. package/version.d.ts +1 -1
  133. package/version.js +1 -1
  134. package/version.mjs +1 -1
@@ -0,0 +1,148 @@
1
+ import {
2
+ getBase64EncodedWireTransaction,
3
+ getTransactionDecoder,
4
+ type Address,
5
+ type SignatureBytes,
6
+ } from '@solana/kit';
7
+ import { base58, base64 } from '@scure/base';
8
+ import type {
9
+ MessagePartialSigner,
10
+ TransactionPartialSigner,
11
+ TransactionSendingSigner,
12
+ } from '@solana/signers';
13
+ import type { AuthorizationContext } from './lib/authorization';
14
+ import type { PrivyClient } from './public-api/PrivyClient';
15
+
16
+ export interface CreateSolanaKitSignerInput {
17
+ /** ID for the wallet. */
18
+ walletId: string;
19
+ /** Solana address for the wallet. */
20
+ address: Address;
21
+ /** Authorization context for the wallet. */
22
+ authorizationContext?: AuthorizationContext;
23
+ /**
24
+ * CAIP-2 for the Solana network.
25
+ * @optional This field is only required for sending transactions.
26
+ */
27
+ caip2?: string;
28
+ }
29
+
30
+ /**
31
+ * Defines a signer that uses a {@link PrivyClient} to sign messages and transactions.
32
+ *
33
+ * It implements the {@link MessagePartialSigner}, {@link TransactionPartialSigner},
34
+ * and {@link TransactionSendingSigner} interfaces and keeps track of the ID of the
35
+ * wallet used to sign them.
36
+ */
37
+ export type SolanaKitSigner = MessagePartialSigner &
38
+ TransactionPartialSigner &
39
+ TransactionSendingSigner &
40
+ Readonly<{ walletId: string; address: Address }>;
41
+
42
+ /**
43
+ * Creates a {@link SolanaKitSigner} from a provided Privy wallet and authorization context.
44
+ *
45
+ * The returned signer implements:
46
+ * - {@link MessagePartialSigner} - for signing messages via `signMessages`
47
+ * - {@link TransactionPartialSigner} - for signing transactions via `signTransactions`
48
+ * - {@link TransactionSendingSigner} - for signing and sending transactions via `signAndSendTransactions`
49
+ *
50
+ * And it keeps track of the `walletId` used to sign them.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { PrivyClient } from '@privy-io/node';
55
+ * import { createSolanaKitSigner } from '@privy-io/node/solana-kit';
56
+ * import { address } from '@solana/kit';
57
+ *
58
+ * const client = new PrivyClient({ appId: '...', appSecret: '...' });
59
+ * const signer = createSolanaKitSigner(client, {
60
+ * walletId: 'wallet-id',
61
+ * address: address('...'),
62
+ * });
63
+ * ```
64
+ */
65
+ export function createSolanaKitSigner(
66
+ client: PrivyClient,
67
+ { walletId, address, authorizationContext, caip2 }: CreateSolanaKitSignerInput,
68
+ ): SolanaKitSigner {
69
+ const authCtxOptions = authorizationContext ? { authorization_context: authorizationContext } : {};
70
+ return {
71
+ address,
72
+ walletId,
73
+
74
+ async signMessages(messages) {
75
+ return await Promise.all(
76
+ messages.map(async (message) => {
77
+ const response = await client
78
+ .wallets()
79
+ .solana()
80
+ .signMessage(walletId, {
81
+ message: message.content,
82
+ ...authCtxOptions,
83
+ });
84
+
85
+ // We assert the signature is valid by casting to `SignatureBytes`
86
+ const signatureBytes = base64.decode(response.signature) as SignatureBytes;
87
+ return {
88
+ [address]: signatureBytes,
89
+ };
90
+ }),
91
+ );
92
+ },
93
+
94
+ async signTransactions(transactions) {
95
+ return await Promise.all(
96
+ transactions.map(async (transaction) => {
97
+ // Convert compiled transaction to wire format base64
98
+ const transactionBase64 = getBase64EncodedWireTransaction(transaction);
99
+
100
+ const response = await client
101
+ .wallets()
102
+ .solana()
103
+ .signTransaction(walletId, {
104
+ transaction: transactionBase64,
105
+ ...authCtxOptions,
106
+ });
107
+
108
+ const signedTransactionBytes = base64.decode(response.signed_transaction);
109
+ const decoder = getTransactionDecoder();
110
+ const signedTransaction = decoder.decode(signedTransactionBytes);
111
+
112
+ return {
113
+ // We assert the signature exists by asserting as non-null
114
+ [address]: signedTransaction.signatures[address]!,
115
+ };
116
+ }),
117
+ );
118
+ },
119
+
120
+ async signAndSendTransactions(transactions) {
121
+ if (!caip2) {
122
+ throw new Error(
123
+ 'CAIP-2 is required for sending transactions. Please provide one in the createSolanaKitSigner input.',
124
+ );
125
+ }
126
+
127
+ return await Promise.all(
128
+ transactions.map(async (transaction) => {
129
+ // Convert compiled transaction to wire format base64
130
+ const transactionBase64 = getBase64EncodedWireTransaction(transaction);
131
+
132
+ const response = await client
133
+ .wallets()
134
+ .solana()
135
+ .signAndSendTransaction(walletId, {
136
+ transaction: transactionBase64,
137
+ caip2,
138
+ ...authCtxOptions,
139
+ });
140
+
141
+ // The hash returned is base58-encoded, convert to bytes
142
+ // and cast as a SignatureBytes, asserting it is a valid signature.
143
+ return base58.decode(response.hash) as SignatureBytes;
144
+ }),
145
+ );
146
+ },
147
+ };
148
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.6.2'; // x-release-please-version
1
+ export const VERSION = '0.8.0'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.6.2";
1
+ export declare const VERSION = "0.8.0";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.6.2";
1
+ export declare const VERSION = "0.8.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.6.2'; // x-release-please-version
4
+ exports.VERSION = '0.8.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.6.2'; // x-release-please-version
1
+ export const VERSION = '0.8.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map