@privy-io/node 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +146 -0
- package/LICENSE +201 -0
- package/README.md +48 -0
- package/api-promise.d.mts +2 -0
- package/api-promise.d.mts.map +1 -0
- package/api-promise.d.ts +2 -0
- package/api-promise.d.ts.map +1 -0
- package/api-promise.js +6 -0
- package/api-promise.js.map +1 -0
- package/api-promise.mjs +2 -0
- package/api-promise.mjs.map +1 -0
- package/client.d.mts +215 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +215 -0
- package/client.d.ts.map +1 -0
- package/client.js +499 -0
- package/client.js.map +1 -0
- package/client.mjs +495 -0
- package/client.mjs.map +1 -0
- package/core/api-promise.d.mts +46 -0
- package/core/api-promise.d.mts.map +1 -0
- package/core/api-promise.d.ts +46 -0
- package/core/api-promise.d.ts.map +1 -0
- package/core/api-promise.js +74 -0
- package/core/api-promise.js.map +1 -0
- package/core/api-promise.mjs +70 -0
- package/core/api-promise.mjs.map +1 -0
- package/core/error.d.mts +46 -0
- package/core/error.d.mts.map +1 -0
- package/core/error.d.ts +46 -0
- package/core/error.d.ts.map +1 -0
- package/core/error.js +113 -0
- package/core/error.js.map +1 -0
- package/core/error.mjs +97 -0
- package/core/error.mjs.map +1 -0
- package/core/pagination.d.mts +54 -0
- package/core/pagination.d.mts.map +1 -0
- package/core/pagination.d.ts +54 -0
- package/core/pagination.d.ts.map +1 -0
- package/core/pagination.js +101 -0
- package/core/pagination.js.map +1 -0
- package/core/pagination.mjs +95 -0
- package/core/pagination.mjs.map +1 -0
- package/core/resource.d.mts +6 -0
- package/core/resource.d.mts.map +1 -0
- package/core/resource.d.ts +6 -0
- package/core/resource.d.ts.map +1 -0
- package/core/resource.js +11 -0
- package/core/resource.js.map +1 -0
- package/core/resource.mjs +7 -0
- package/core/resource.mjs.map +1 -0
- package/core/uploads.d.mts +3 -0
- package/core/uploads.d.mts.map +1 -0
- package/core/uploads.d.ts +3 -0
- package/core/uploads.d.ts.map +1 -0
- package/core/uploads.js +6 -0
- package/core/uploads.js.map +1 -0
- package/core/uploads.mjs +2 -0
- package/core/uploads.mjs.map +1 -0
- package/error.d.mts +2 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +2 -0
- package/error.d.ts.map +1 -0
- package/error.js +6 -0
- package/error.js.map +1 -0
- package/error.mjs +2 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +13 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +13 -0
- package/index.d.ts.map +1 -0
- package/index.js +29 -0
- package/index.js.map +1 -0
- package/index.mjs +5 -0
- package/index.mjs.map +1 -0
- package/internal/builtin-types.d.mts +73 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +73 -0
- package/internal/builtin-types.d.ts.map +1 -0
- package/internal/builtin-types.js +4 -0
- package/internal/builtin-types.js.map +1 -0
- package/internal/builtin-types.mjs +3 -0
- package/internal/builtin-types.mjs.map +1 -0
- package/internal/detect-platform.d.mts +15 -0
- package/internal/detect-platform.d.mts.map +1 -0
- package/internal/detect-platform.d.ts +15 -0
- package/internal/detect-platform.d.ts.map +1 -0
- package/internal/detect-platform.js +162 -0
- package/internal/detect-platform.js.map +1 -0
- package/internal/detect-platform.mjs +157 -0
- package/internal/detect-platform.mjs.map +1 -0
- package/internal/errors.d.mts +3 -0
- package/internal/errors.d.mts.map +1 -0
- package/internal/errors.d.ts +3 -0
- package/internal/errors.d.ts.map +1 -0
- package/internal/errors.js +41 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +36 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +6 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +6 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +79 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +74 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +12 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +12 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +35 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +32 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/qs/formats.d.mts +7 -0
- package/internal/qs/formats.d.mts.map +1 -0
- package/internal/qs/formats.d.ts +7 -0
- package/internal/qs/formats.d.ts.map +1 -0
- package/internal/qs/formats.js +13 -0
- package/internal/qs/formats.js.map +1 -0
- package/internal/qs/formats.mjs +9 -0
- package/internal/qs/formats.mjs.map +1 -0
- package/internal/qs/index.d.mts +10 -0
- package/internal/qs/index.d.mts.map +1 -0
- package/internal/qs/index.d.ts +10 -0
- package/internal/qs/index.d.ts.map +1 -0
- package/internal/qs/index.js +14 -0
- package/internal/qs/index.js.map +1 -0
- package/internal/qs/index.mjs +10 -0
- package/internal/qs/index.mjs.map +1 -0
- package/internal/qs/stringify.d.mts +3 -0
- package/internal/qs/stringify.d.mts.map +1 -0
- package/internal/qs/stringify.d.ts +3 -0
- package/internal/qs/stringify.d.ts.map +1 -0
- package/internal/qs/stringify.js +277 -0
- package/internal/qs/stringify.js.map +1 -0
- package/internal/qs/stringify.mjs +274 -0
- package/internal/qs/stringify.mjs.map +1 -0
- package/internal/qs/types.d.mts +57 -0
- package/internal/qs/types.d.mts.map +1 -0
- package/internal/qs/types.d.ts +57 -0
- package/internal/qs/types.d.ts.map +1 -0
- package/internal/qs/types.js +3 -0
- package/internal/qs/types.js.map +1 -0
- package/internal/qs/types.mjs +2 -0
- package/internal/qs/types.mjs.map +1 -0
- package/internal/qs/utils.d.mts +15 -0
- package/internal/qs/utils.d.mts.map +1 -0
- package/internal/qs/utils.d.ts +15 -0
- package/internal/qs/utils.d.ts.map +1 -0
- package/internal/qs/utils.js +230 -0
- package/internal/qs/utils.js.map +1 -0
- package/internal/qs/utils.mjs +217 -0
- package/internal/qs/utils.mjs.map +1 -0
- package/internal/request-options.d.mts +75 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +75 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +14 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +10 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +17 -0
- package/internal/shim-types.d.mts.map +1 -0
- package/internal/shim-types.d.ts +17 -0
- package/internal/shim-types.d.ts.map +1 -0
- package/internal/shim-types.js +4 -0
- package/internal/shim-types.js.map +1 -0
- package/internal/shim-types.mjs +3 -0
- package/internal/shim-types.mjs.map +1 -0
- package/internal/shims.d.mts +20 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +20 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +92 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +85 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/to-file.d.mts +45 -0
- package/internal/to-file.d.mts.map +1 -0
- package/internal/to-file.d.ts +45 -0
- package/internal/to-file.d.ts.map +1 -0
- package/internal/to-file.js +91 -0
- package/internal/to-file.js.map +1 -0
- package/internal/to-file.mjs +88 -0
- package/internal/to-file.mjs.map +1 -0
- package/internal/tslib.js +85 -0
- package/internal/tslib.mjs +17 -0
- package/internal/types.d.mts +69 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +69 -0
- package/internal/types.d.ts.map +1 -0
- package/internal/types.js +4 -0
- package/internal/types.js.map +1 -0
- package/internal/types.mjs +3 -0
- package/internal/types.mjs.map +1 -0
- package/internal/uploads.d.mts +42 -0
- package/internal/uploads.d.mts.map +1 -0
- package/internal/uploads.d.ts +42 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +141 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +131 -0
- package/internal/uploads.mjs.map +1 -0
- package/internal/utils/base64.d.mts +3 -0
- package/internal/utils/base64.d.mts.map +1 -0
- package/internal/utils/base64.d.ts +3 -0
- package/internal/utils/base64.d.ts.map +1 -0
- package/internal/utils/base64.js +38 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +33 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/bytes.d.mts +4 -0
- package/internal/utils/bytes.d.mts.map +1 -0
- package/internal/utils/bytes.d.ts +4 -0
- package/internal/utils/bytes.d.ts.map +1 -0
- package/internal/utils/bytes.js +31 -0
- package/internal/utils/bytes.js.map +1 -0
- package/internal/utils/bytes.mjs +26 -0
- package/internal/utils/bytes.mjs.map +1 -0
- package/internal/utils/env.d.mts +9 -0
- package/internal/utils/env.d.mts.map +1 -0
- package/internal/utils/env.d.ts +9 -0
- package/internal/utils/env.d.ts.map +1 -0
- package/internal/utils/env.js +22 -0
- package/internal/utils/env.js.map +1 -0
- package/internal/utils/env.mjs +18 -0
- package/internal/utils/env.mjs.map +1 -0
- package/internal/utils/log.d.mts +37 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +37 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +85 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +79 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/path.d.mts +15 -0
- package/internal/utils/path.d.mts.map +1 -0
- package/internal/utils/path.d.ts +15 -0
- package/internal/utils/path.d.ts.map +1 -0
- package/internal/utils/path.js +79 -0
- package/internal/utils/path.js.map +1 -0
- package/internal/utils/path.mjs +74 -0
- package/internal/utils/path.mjs.map +1 -0
- package/internal/utils/sleep.d.mts +2 -0
- package/internal/utils/sleep.d.mts.map +1 -0
- package/internal/utils/sleep.d.ts +2 -0
- package/internal/utils/sleep.d.ts.map +1 -0
- package/internal/utils/sleep.js +7 -0
- package/internal/utils/sleep.js.map +1 -0
- package/internal/utils/sleep.mjs +3 -0
- package/internal/utils/sleep.mjs.map +1 -0
- package/internal/utils/uuid.d.mts +5 -0
- package/internal/utils/uuid.d.mts.map +1 -0
- package/internal/utils/uuid.d.ts +5 -0
- package/internal/utils/uuid.d.ts.map +1 -0
- package/internal/utils/uuid.js +19 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +15 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +18 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +18 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +112 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +94 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.mts +7 -0
- package/internal/utils.d.mts.map +1 -0
- package/internal/utils.d.ts +7 -0
- package/internal/utils.d.ts.map +1 -0
- package/internal/utils.js +11 -0
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +8 -0
- package/internal/utils.mjs.map +1 -0
- package/lib/authorization.d.mts +87 -0
- package/lib/authorization.d.mts.map +1 -0
- package/lib/authorization.d.ts +87 -0
- package/lib/authorization.d.ts.map +1 -0
- package/lib/authorization.js +73 -0
- package/lib/authorization.js.map +1 -0
- package/lib/authorization.mjs +67 -0
- package/lib/authorization.mjs.map +1 -0
- package/lib/cryptography.d.mts +8 -0
- package/lib/cryptography.d.mts.map +1 -0
- package/lib/cryptography.d.ts +8 -0
- package/lib/cryptography.d.ts.map +1 -0
- package/lib/cryptography.js +72 -0
- package/lib/cryptography.js.map +1 -0
- package/lib/cryptography.mjs +67 -0
- package/lib/cryptography.mjs.map +1 -0
- package/lib/jwt-exchange.d.mts +9 -0
- package/lib/jwt-exchange.d.mts.map +1 -0
- package/lib/jwt-exchange.d.ts +9 -0
- package/lib/jwt-exchange.d.ts.map +1 -0
- package/lib/jwt-exchange.js +55 -0
- package/lib/jwt-exchange.js.map +1 -0
- package/lib/jwt-exchange.mjs +51 -0
- package/lib/jwt-exchange.mjs.map +1 -0
- package/lib/wallet-entropy.d.mts +7 -0
- package/lib/wallet-entropy.d.mts.map +1 -0
- package/lib/wallet-entropy.d.ts +7 -0
- package/lib/wallet-entropy.d.ts.map +1 -0
- package/lib/wallet-entropy.js +44 -0
- package/lib/wallet-entropy.js.map +1 -0
- package/lib/wallet-entropy.mjs +41 -0
- package/lib/wallet-entropy.mjs.map +1 -0
- package/package.json +46 -0
- package/pagination.d.mts +2 -0
- package/pagination.d.mts.map +1 -0
- package/pagination.d.ts +2 -0
- package/pagination.d.ts.map +1 -0
- package/pagination.js +6 -0
- package/pagination.js.map +1 -0
- package/pagination.mjs +2 -0
- package/pagination.mjs.map +1 -0
- package/public-api/PrivyClient.d.mts +33 -0
- package/public-api/PrivyClient.d.mts.map +1 -0
- package/public-api/PrivyClient.d.ts +33 -0
- package/public-api/PrivyClient.d.ts.map +1 -0
- package/public-api/PrivyClient.js +59 -0
- package/public-api/PrivyClient.js.map +1 -0
- package/public-api/PrivyClient.mjs +55 -0
- package/public-api/PrivyClient.mjs.map +1 -0
- package/public-api/services/ethereum.d.mts +39 -0
- package/public-api/services/ethereum.d.mts.map +1 -0
- package/public-api/services/ethereum.d.ts +39 -0
- package/public-api/services/ethereum.d.ts.map +1 -0
- package/public-api/services/ethereum.js +77 -0
- package/public-api/services/ethereum.js.map +1 -0
- package/public-api/services/ethereum.mjs +73 -0
- package/public-api/services/ethereum.mjs.map +1 -0
- package/public-api/services/key-quorums.d.mts +18 -0
- package/public-api/services/key-quorums.d.mts.map +1 -0
- package/public-api/services/key-quorums.d.ts +18 -0
- package/public-api/services/key-quorums.d.ts.map +1 -0
- package/public-api/services/key-quorums.js +51 -0
- package/public-api/services/key-quorums.js.map +1 -0
- package/public-api/services/key-quorums.mjs +47 -0
- package/public-api/services/key-quorums.mjs.map +1 -0
- package/public-api/services/policies.d.mts +27 -0
- package/public-api/services/policies.d.mts.map +1 -0
- package/public-api/services/policies.d.ts +27 -0
- package/public-api/services/policies.d.ts.map +1 -0
- package/public-api/services/policies.js +110 -0
- package/public-api/services/policies.js.map +1 -0
- package/public-api/services/policies.mjs +106 -0
- package/public-api/services/policies.mjs.map +1 -0
- package/public-api/services/solana.d.mts +42 -0
- package/public-api/services/solana.d.mts.map +1 -0
- package/public-api/services/solana.d.ts +42 -0
- package/public-api/services/solana.d.ts.map +1 -0
- package/public-api/services/solana.js +67 -0
- package/public-api/services/solana.js.map +1 -0
- package/public-api/services/solana.mjs +63 -0
- package/public-api/services/solana.mjs.map +1 -0
- package/public-api/services/transactions.d.mts +4 -0
- package/public-api/services/transactions.d.mts.map +1 -0
- package/public-api/services/transactions.d.ts +4 -0
- package/public-api/services/transactions.d.ts.map +1 -0
- package/public-api/services/transactions.js +8 -0
- package/public-api/services/transactions.js.map +1 -0
- package/public-api/services/transactions.mjs +4 -0
- package/public-api/services/transactions.mjs.map +1 -0
- package/public-api/services/types.d.mts +54 -0
- package/public-api/services/types.d.mts.map +1 -0
- package/public-api/services/types.d.ts +54 -0
- package/public-api/services/types.d.ts.map +1 -0
- package/public-api/services/types.js +3 -0
- package/public-api/services/types.js.map +1 -0
- package/public-api/services/types.mjs +2 -0
- package/public-api/services/types.mjs.map +1 -0
- package/public-api/services/users.d.mts +4 -0
- package/public-api/services/users.d.mts.map +1 -0
- package/public-api/services/users.d.ts +4 -0
- package/public-api/services/users.d.ts.map +1 -0
- package/public-api/services/users.js +8 -0
- package/public-api/services/users.js.map +1 -0
- package/public-api/services/users.mjs +4 -0
- package/public-api/services/users.mjs.map +1 -0
- package/public-api/services/utils.d.mts +26 -0
- package/public-api/services/utils.d.mts.map +1 -0
- package/public-api/services/utils.d.ts +26 -0
- package/public-api/services/utils.d.ts.map +1 -0
- package/public-api/services/utils.js +18 -0
- package/public-api/services/utils.js.map +1 -0
- package/public-api/services/utils.mjs +14 -0
- package/public-api/services/utils.mjs.map +1 -0
- package/public-api/services/wallets.d.mts +70 -0
- package/public-api/services/wallets.d.mts.map +1 -0
- package/public-api/services/wallets.d.ts +70 -0
- package/public-api/services/wallets.d.ts.map +1 -0
- package/public-api/services/wallets.js +145 -0
- package/public-api/services/wallets.js.map +1 -0
- package/public-api/services/wallets.mjs +141 -0
- package/public-api/services/wallets.mjs.map +1 -0
- package/resource.d.mts +2 -0
- package/resource.d.mts.map +1 -0
- package/resource.d.ts +2 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +6 -0
- package/resource.js.map +1 -0
- package/resource.mjs +2 -0
- package/resource.mjs.map +1 -0
- package/resources/index.d.mts +6 -0
- package/resources/index.d.mts.map +1 -0
- package/resources/index.d.ts +6 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +15 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +7 -0
- package/resources/index.mjs.map +1 -0
- package/resources/key-quorums.d.mts +106 -0
- package/resources/key-quorums.d.mts.map +1 -0
- package/resources/key-quorums.d.ts +106 -0
- package/resources/key-quorums.d.ts.map +1 -0
- package/resources/key-quorums.js +84 -0
- package/resources/key-quorums.js.map +1 -0
- package/resources/key-quorums.mjs +80 -0
- package/resources/key-quorums.mjs.map +1 -0
- package/resources/policies.d.mts +1283 -0
- package/resources/policies.d.mts.map +1 -0
- package/resources/policies.d.ts +1283 -0
- package/resources/policies.d.ts.map +1 -0
- package/resources/policies.js +228 -0
- package/resources/policies.js.map +1 -0
- package/resources/policies.mjs +224 -0
- package/resources/policies.mjs.map +1 -0
- package/resources/transactions.d.mts +29 -0
- package/resources/transactions.d.mts.map +1 -0
- package/resources/transactions.d.ts +29 -0
- package/resources/transactions.d.ts.map +1 -0
- package/resources/transactions.js +23 -0
- package/resources/transactions.js.map +1 -0
- package/resources/transactions.mjs +19 -0
- package/resources/transactions.mjs.map +1 -0
- package/resources/users.d.mts +766 -0
- package/resources/users.d.mts.map +1 -0
- package/resources/users.d.ts +766 -0
- package/resources/users.d.ts.map +1 -0
- package/resources/users.js +278 -0
- package/resources/users.js.map +1 -0
- package/resources/users.mjs +274 -0
- package/resources/users.mjs.map +1 -0
- package/resources/wallets/balance.d.mts +40 -0
- package/resources/wallets/balance.d.mts.map +1 -0
- package/resources/wallets/balance.d.ts +40 -0
- package/resources/wallets/balance.d.ts.map +1 -0
- package/resources/wallets/balance.js +24 -0
- package/resources/wallets/balance.js.map +1 -0
- package/resources/wallets/balance.mjs +20 -0
- package/resources/wallets/balance.mjs.map +1 -0
- package/resources/wallets/index.d.mts +4 -0
- package/resources/wallets/index.d.mts.map +1 -0
- package/resources/wallets/index.d.ts +4 -0
- package/resources/wallets/index.d.ts.map +1 -0
- package/resources/wallets/index.js +11 -0
- package/resources/wallets/index.js.map +1 -0
- package/resources/wallets/index.mjs +5 -0
- package/resources/wallets/index.mjs.map +1 -0
- package/resources/wallets/transactions.d.mts +73 -0
- package/resources/wallets/transactions.d.mts.map +1 -0
- package/resources/wallets/transactions.d.ts +73 -0
- package/resources/wallets/transactions.d.ts.map +1 -0
- package/resources/wallets/transactions.js +24 -0
- package/resources/wallets/transactions.js.map +1 -0
- package/resources/wallets/transactions.mjs +20 -0
- package/resources/wallets/transactions.mjs.map +1 -0
- package/resources/wallets/wallets.d.mts +1122 -0
- package/resources/wallets/wallets.d.mts.map +1 -0
- package/resources/wallets/wallets.d.ts +1122 -0
- package/resources/wallets/wallets.d.ts.map +1 -0
- package/resources/wallets/wallets.js +235 -0
- package/resources/wallets/wallets.js.map +1 -0
- package/resources/wallets/wallets.mjs +230 -0
- package/resources/wallets/wallets.mjs.map +1 -0
- package/resources/wallets.d.mts +2 -0
- package/resources/wallets.d.mts.map +1 -0
- package/resources/wallets.d.ts +2 -0
- package/resources/wallets.d.ts.map +1 -0
- package/resources/wallets.js +6 -0
- package/resources/wallets.js.map +1 -0
- package/resources/wallets.mjs +3 -0
- package/resources/wallets.mjs.map +1 -0
- package/resources.d.mts +2 -0
- package/resources.d.mts.map +1 -0
- package/resources.d.ts +2 -0
- package/resources.d.ts.map +1 -0
- package/resources.js +5 -0
- package/resources.js.map +1 -0
- package/resources.mjs +2 -0
- package/resources.mjs.map +1 -0
- package/src/api-promise.ts +2 -0
- package/src/client.ts +942 -0
- package/src/core/README.md +3 -0
- package/src/core/api-promise.ts +92 -0
- package/src/core/error.ts +130 -0
- package/src/core/pagination.ts +157 -0
- package/src/core/resource.ts +11 -0
- package/src/core/uploads.ts +2 -0
- package/src/error.ts +2 -0
- package/src/index.ts +34 -0
- package/src/internal/README.md +3 -0
- package/src/internal/builtin-types.ts +93 -0
- package/src/internal/detect-platform.ts +196 -0
- package/src/internal/errors.ts +33 -0
- package/src/internal/headers.ts +97 -0
- package/src/internal/parse.ts +50 -0
- package/src/internal/qs/LICENSE.md +13 -0
- package/src/internal/qs/README.md +3 -0
- package/src/internal/qs/formats.ts +10 -0
- package/src/internal/qs/index.ts +13 -0
- package/src/internal/qs/stringify.ts +385 -0
- package/src/internal/qs/types.ts +71 -0
- package/src/internal/qs/utils.ts +265 -0
- package/src/internal/request-options.ts +91 -0
- package/src/internal/shim-types.ts +26 -0
- package/src/internal/shims.ts +107 -0
- package/src/internal/to-file.ts +154 -0
- package/src/internal/types.ts +95 -0
- package/src/internal/uploads.ts +187 -0
- package/src/internal/utils/base64.ts +40 -0
- package/src/internal/utils/bytes.ts +32 -0
- package/src/internal/utils/env.ts +18 -0
- package/src/internal/utils/log.ts +126 -0
- package/src/internal/utils/path.ts +88 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/uuid.ts +17 -0
- package/src/internal/utils/values.ts +105 -0
- package/src/internal/utils.ts +8 -0
- package/src/lib/.keep +4 -0
- package/src/lib/authorization.ts +153 -0
- package/src/lib/cryptography.ts +109 -0
- package/src/lib/jwt-exchange.ts +65 -0
- package/src/lib/wallet-entropy.ts +48 -0
- package/src/pagination.ts +2 -0
- package/src/public-api/PrivyClient.ts +91 -0
- package/src/public-api/services/ethereum.ts +134 -0
- package/src/public-api/services/key-quorums.ts +77 -0
- package/src/public-api/services/policies.ts +175 -0
- package/src/public-api/services/solana.ts +111 -0
- package/src/public-api/services/transactions.ts +3 -0
- package/src/public-api/services/types.ts +50 -0
- package/src/public-api/services/users.ts +3 -0
- package/src/public-api/services/utils.ts +40 -0
- package/src/public-api/services/wallets.ts +270 -0
- package/src/resource.ts +2 -0
- package/src/resources/index.ts +71 -0
- package/src/resources/key-quorums.ts +177 -0
- package/src/resources/policies.ts +1992 -0
- package/src/resources/transactions.ts +42 -0
- package/src/resources/users.ts +1312 -0
- package/src/resources/wallets/balance.ts +62 -0
- package/src/resources/wallets/index.ts +25 -0
- package/src/resources/wallets/transactions.ts +116 -0
- package/src/resources/wallets/wallets.ts +1609 -0
- package/src/resources/wallets.ts +3 -0
- package/src/resources.ts +1 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +2 -0
- package/src/version.ts +1 -0
- package/uploads.d.mts +2 -0
- package/uploads.d.mts.map +1 -0
- package/uploads.d.ts +2 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +6 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +2 -0
- package/uploads.mjs.map +1 -0
- package/version.d.mts +2 -0
- package/version.d.mts.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { PrivyAPIError } from '../../core/error';
|
|
4
|
+
|
|
5
|
+
// https://url.spec.whatwg.org/#url-scheme-string
|
|
6
|
+
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
7
|
+
|
|
8
|
+
export const isAbsoluteURL = (url: string): boolean => {
|
|
9
|
+
return startsWithSchemeRegexp.test(url);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export let isArray = (val: unknown): val is unknown[] => ((isArray = Array.isArray), isArray(val));
|
|
13
|
+
export let isReadonlyArray = isArray as (val: unknown) => val is readonly unknown[];
|
|
14
|
+
|
|
15
|
+
/** Returns an object if the given value isn't an object, otherwise returns as-is */
|
|
16
|
+
export function maybeObj(x: unknown): object {
|
|
17
|
+
if (typeof x !== 'object') {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return x ?? {};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// https://stackoverflow.com/a/34491287
|
|
25
|
+
export function isEmptyObj(obj: Object | null | undefined): boolean {
|
|
26
|
+
if (!obj) return true;
|
|
27
|
+
for (const _k in obj) return false;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// https://eslint.org/docs/latest/rules/no-prototype-builtins
|
|
32
|
+
export function hasOwn<T extends object = object>(obj: T, key: PropertyKey): key is keyof T {
|
|
33
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isObj(obj: unknown): obj is Record<string, unknown> {
|
|
37
|
+
return obj != null && typeof obj === 'object' && !Array.isArray(obj);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
41
|
+
if (value == null) {
|
|
42
|
+
throw new PrivyAPIError(`Expected a value to be given but received ${value} instead.`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return value;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const validatePositiveInteger = (name: string, n: unknown): number => {
|
|
49
|
+
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
50
|
+
throw new PrivyAPIError(`${name} must be an integer`);
|
|
51
|
+
}
|
|
52
|
+
if (n < 0) {
|
|
53
|
+
throw new PrivyAPIError(`${name} must be a positive integer`);
|
|
54
|
+
}
|
|
55
|
+
return n;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const coerceInteger = (value: unknown): number => {
|
|
59
|
+
if (typeof value === 'number') return Math.round(value);
|
|
60
|
+
if (typeof value === 'string') return parseInt(value, 10);
|
|
61
|
+
|
|
62
|
+
throw new PrivyAPIError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const coerceFloat = (value: unknown): number => {
|
|
66
|
+
if (typeof value === 'number') return value;
|
|
67
|
+
if (typeof value === 'string') return parseFloat(value);
|
|
68
|
+
|
|
69
|
+
throw new PrivyAPIError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const coerceBoolean = (value: unknown): boolean => {
|
|
73
|
+
if (typeof value === 'boolean') return value;
|
|
74
|
+
if (typeof value === 'string') return value === 'true';
|
|
75
|
+
return Boolean(value);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const maybeCoerceInteger = (value: unknown): number | undefined => {
|
|
79
|
+
if (value === undefined) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
return coerceInteger(value);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const maybeCoerceFloat = (value: unknown): number | undefined => {
|
|
86
|
+
if (value === undefined) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
return coerceFloat(value);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
|
|
93
|
+
if (value === undefined) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
return coerceBoolean(value);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const safeJSON = (text: string) => {
|
|
100
|
+
try {
|
|
101
|
+
return JSON.parse(text);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
export * from './utils/values';
|
|
4
|
+
export * from './utils/base64';
|
|
5
|
+
export * from './utils/env';
|
|
6
|
+
export * from './utils/log';
|
|
7
|
+
export * from './utils/uuid';
|
|
8
|
+
export * from './utils/sleep';
|
package/src/lib/.keep
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { p256 } from '@noble/curves/nist';
|
|
2
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
3
|
+
import canonicalize from 'canonicalize';
|
|
4
|
+
import { PrivyAPIError } from '../core/error';
|
|
5
|
+
import { importPKCS8PrivateKey } from './cryptography';
|
|
6
|
+
import { PrivyClient } from '../public-api/PrivyClient';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The authorization context should contain:
|
|
10
|
+
* - Any authorization private keys that must sign the request
|
|
11
|
+
* - The JWTs for any users that must sign the request
|
|
12
|
+
* - Any additional signatures you have computed for the request
|
|
13
|
+
*
|
|
14
|
+
* The Privy client will accept the authorization context, sign the request given the parameters,
|
|
15
|
+
* and include all signatures in the privy-authorization-signature header to the API.
|
|
16
|
+
*/
|
|
17
|
+
export interface AuthorizationContext {
|
|
18
|
+
/**
|
|
19
|
+
* The private keys to use for authorization.
|
|
20
|
+
* These should be base64-encoded PKCS8-formatted private keys, with no PEM headers.
|
|
21
|
+
*/
|
|
22
|
+
authorization_private_keys?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* The JWTs for the users that should sign the request authorization.
|
|
25
|
+
* These should be valid JWTs for the user.
|
|
26
|
+
*/
|
|
27
|
+
user_jwts?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* The signatures that should be used for authorization.
|
|
30
|
+
* These should be base64-encoded signatures.
|
|
31
|
+
*/
|
|
32
|
+
signatures?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Sign functions can be used to sign requests directly, by managing the private keys and signing
|
|
35
|
+
* logic externally.
|
|
36
|
+
*
|
|
37
|
+
* Sign functions should perform an ECDSA P-256 signature on the payload received, and return the
|
|
38
|
+
* base64-encoded signature.
|
|
39
|
+
*/
|
|
40
|
+
sign_fns?: AuthorizationContext.SignFn[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export namespace AuthorizationContext {
|
|
44
|
+
export type SignFn = (payload: Uint8Array) => Promise<string>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type WalletApiRequestSignatureInput = {
|
|
48
|
+
/** Signature version. 1 is currently the only valid version. */
|
|
49
|
+
version: 1;
|
|
50
|
+
/** Request method. Signatures are not required on 'GET' requests. */
|
|
51
|
+
method: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
52
|
+
/** URL for the request. Should not contain a trailing slash. */
|
|
53
|
+
url: string;
|
|
54
|
+
/** Request body. */
|
|
55
|
+
body: any;
|
|
56
|
+
/** Privy-specific headers. */
|
|
57
|
+
headers: {
|
|
58
|
+
'privy-app-id': string;
|
|
59
|
+
'privy-idempotency-key'?: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Formats the request payload into the expected authorization payload, canconicalizes it,
|
|
65
|
+
* and encodes the JSON string into bytes.
|
|
66
|
+
*
|
|
67
|
+
* @param request The request to be formatted.
|
|
68
|
+
* @return The raw bytes representing the authorization payload.
|
|
69
|
+
*/
|
|
70
|
+
export function formatRequestForAuthorizationSignature(input: WalletApiRequestSignatureInput): Uint8Array {
|
|
71
|
+
const body: unknown = input.body;
|
|
72
|
+
if (typeof body === 'object' && body !== null && Object.keys(body).length === 0) {
|
|
73
|
+
// This is a special case, where if the body is empty, we want to serialize it
|
|
74
|
+
// as an empty string.
|
|
75
|
+
input.body = '';
|
|
76
|
+
}
|
|
77
|
+
const serializedInput = canonicalize(input);
|
|
78
|
+
if (!serializedInput) {
|
|
79
|
+
throw new PrivyAPIError('Failed to serialize request for authorization signature');
|
|
80
|
+
}
|
|
81
|
+
return new TextEncoder().encode(serializedInput);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Generates authorization signatures from the given authorization context and signable request.
|
|
86
|
+
* This method handles JWT exchange and private key signing.
|
|
87
|
+
*
|
|
88
|
+
* Manual signing of requests is intended for advanced use cases.
|
|
89
|
+
*
|
|
90
|
+
* @param authorizationContext The authorization context containing JWTs, private keys, and signatures.
|
|
91
|
+
* @param input The request payload to sign.
|
|
92
|
+
* @returns An array of authorization signatures.
|
|
93
|
+
*/
|
|
94
|
+
export async function generateAuthorizationSignatures(
|
|
95
|
+
client: PrivyClient,
|
|
96
|
+
{
|
|
97
|
+
authorizationContext,
|
|
98
|
+
input,
|
|
99
|
+
}: {
|
|
100
|
+
authorizationContext: AuthorizationContext;
|
|
101
|
+
input: WalletApiRequestSignatureInput;
|
|
102
|
+
},
|
|
103
|
+
): Promise<string[]> {
|
|
104
|
+
const payload = formatRequestForAuthorizationSignature(input);
|
|
105
|
+
|
|
106
|
+
const userJwts = authorizationContext.user_jwts ?? [];
|
|
107
|
+
let userKeys: string[] = [];
|
|
108
|
+
if (userJwts.length > 0) {
|
|
109
|
+
userKeys = await Promise.all(
|
|
110
|
+
userJwts.map((jwt) => client._jwtExchange().exchangeJwtForAuthorizationKey(jwt)),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** These are the private keys provided by the caller, either directly or via JWT exchange */
|
|
115
|
+
const privateKeys = [...(authorizationContext.authorization_private_keys ?? []), ...userKeys];
|
|
116
|
+
|
|
117
|
+
/** These are the signatures calculated from the private keys */
|
|
118
|
+
const calculatedSignatures = privateKeys.map((sk) =>
|
|
119
|
+
generateAuthorizationSignature({ authorizationPrivateKey: sk, input: payload }),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
/** These are the signatures calculated externally from the given sign functions */
|
|
123
|
+
const signFnSignatures = await Promise.all(
|
|
124
|
+
(authorizationContext.sign_fns ?? []).map((signFn) => signFn(payload)),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
/** These are the signatures provided directly by the caller */
|
|
128
|
+
const providedRawSignatures = authorizationContext.signatures ?? [];
|
|
129
|
+
|
|
130
|
+
return [...providedRawSignatures, ...calculatedSignatures, ...signFnSignatures];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Signs the given request with the provided private key.
|
|
135
|
+
*
|
|
136
|
+
* @param authorizationPrivateKey The base64-encoded PKCS8-formatted private key, with no PEM headers.
|
|
137
|
+
* @param input The request payload to sign, or one serialized using {@link formatRequestForAuthorizationSignature}.
|
|
138
|
+
* @return The authorization signature.
|
|
139
|
+
*/
|
|
140
|
+
export function generateAuthorizationSignature({
|
|
141
|
+
authorizationPrivateKey,
|
|
142
|
+
input,
|
|
143
|
+
}: {
|
|
144
|
+
authorizationPrivateKey: string;
|
|
145
|
+
input: WalletApiRequestSignatureInput | Uint8Array;
|
|
146
|
+
}): string {
|
|
147
|
+
const payload = input instanceof Uint8Array ? input : formatRequestForAuthorizationSignature(input);
|
|
148
|
+
const privateKey = importPKCS8PrivateKey(authorizationPrivateKey);
|
|
149
|
+
|
|
150
|
+
const signature = p256.sign(sha256(payload), privateKey).toBytes('der');
|
|
151
|
+
// We fall back to `Buffer` here as Uint8Array.toBase64 is not widely supported yet
|
|
152
|
+
return Buffer.from(signature).toString('base64');
|
|
153
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Chacha20Poly1305 } from '@hpke/chacha20poly1305';
|
|
2
|
+
import { CipherSuite, DhkemP256HkdfSha256, HkdfSha256 } from '@hpke/core';
|
|
3
|
+
import { p256 } from '@noble/curves/nist';
|
|
4
|
+
import type { PrivKey } from '@noble/curves/utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Imports a P-256 private key for use with the `@noble/curves` library.
|
|
8
|
+
*
|
|
9
|
+
* @param privateKey - A base64-encoded PKCS8-formatted private key, with no PEM headers.
|
|
10
|
+
* @returns A private key object for the P-256 curve.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export function importPKCS8PrivateKey(privateKey: string): PrivKey {
|
|
14
|
+
// We fall back to `Buffer` here as Uint8Array.fromBase64 is not widely supported yet
|
|
15
|
+
const pkcs8Bytes = Buffer.from(privateKey, 'base64');
|
|
16
|
+
const privateKeyStart = pkcs8Bytes.indexOf(Buffer.from([0x04, 0x20]));
|
|
17
|
+
|
|
18
|
+
if (privateKeyStart === -1) {
|
|
19
|
+
throw new Error('Invalid wallet authorization private key');
|
|
20
|
+
}
|
|
21
|
+
const privateKeyBytes = pkcs8Bytes.subarray(privateKeyStart + 2, privateKeyStart + 34);
|
|
22
|
+
return p256.Point.Fn.fromBytes(privateKeyBytes);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export interface HPKERecipient {
|
|
27
|
+
/** The recipient's public key. */
|
|
28
|
+
publicKeySpki: Uint8Array;
|
|
29
|
+
/**
|
|
30
|
+
* Decrypts an HPKE-encrypted message received from the sender.
|
|
31
|
+
* @param encapsulatedKey - The encapsulated key to use for decryption.
|
|
32
|
+
* @param ciphertext - The ciphertext to decrypt.
|
|
33
|
+
* @returns The decrypted message.
|
|
34
|
+
*/
|
|
35
|
+
decryptPayload: (encapsulatedKey: Uint8Array, ciphertext: Uint8Array) => Promise<Uint8Array>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sets up HPKE for securely requesting a payload (as the recipient)
|
|
40
|
+
* from a sender (e.g. the Privy API).
|
|
41
|
+
* @returns The HPKE receiver object.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export async function setupHPKERecipient(): Promise<HPKERecipient> {
|
|
45
|
+
const suite = new CipherSuite({
|
|
46
|
+
kem: new DhkemP256HkdfSha256(),
|
|
47
|
+
kdf: new HkdfSha256(),
|
|
48
|
+
aead: new Chacha20Poly1305(),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const keypair = await suite.kem.generateKeyPair();
|
|
52
|
+
const publicKeySpki = await crypto.subtle.exportKey('spki', keypair.publicKey);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
publicKeySpki: new Uint8Array(publicKeySpki),
|
|
56
|
+
decryptPayload: async (encapsulatedKey: Uint8Array, ciphertext: Uint8Array) => {
|
|
57
|
+
const recipient = await suite.createRecipientContext({
|
|
58
|
+
recipientKey: keypair.privateKey,
|
|
59
|
+
enc: encapsulatedKey,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const decodedBytes = await recipient.open(ciphertext);
|
|
63
|
+
|
|
64
|
+
return new Uint8Array(decodedBytes);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @internal */
|
|
70
|
+
export interface HPKESender {
|
|
71
|
+
/**
|
|
72
|
+
* Encrypts a payload for the recipient in an HPKE flow.
|
|
73
|
+
* @param publicKey - The public key of the recipient to use for encryption.
|
|
74
|
+
* @param payload - The payload to encrypt.
|
|
75
|
+
* @returns The encapsulated key and ciphertext to send out.
|
|
76
|
+
*/
|
|
77
|
+
encryptPayload: (publicKey: Uint8Array, payload: Uint8Array) => Promise<HPKESender.EncryptPayloadOutput>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export namespace HPKESender {
|
|
81
|
+
export interface EncryptPayloadOutput {
|
|
82
|
+
ciphertext: Uint8Array;
|
|
83
|
+
encapsulatedKey: Uint8Array;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function setupHPKESender(): Promise<HPKESender> {
|
|
88
|
+
const suite = new CipherSuite({
|
|
89
|
+
kem: new DhkemP256HkdfSha256(),
|
|
90
|
+
kdf: new HkdfSha256(),
|
|
91
|
+
aead: new Chacha20Poly1305(),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
encryptPayload: async (publicKey: Uint8Array, payload: Uint8Array) => {
|
|
96
|
+
const recipientPublicKey = await suite.kem.deserializePublicKey(publicKey);
|
|
97
|
+
const sender = await suite.createSenderContext({
|
|
98
|
+
recipientPublicKey,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const ciphertext = await sender.seal(payload);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
ciphertext: new Uint8Array(ciphertext),
|
|
105
|
+
encapsulatedKey: new Uint8Array(sender.enc),
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { LRUCache } from 'lru-cache';
|
|
2
|
+
import { PrivyAPIError } from '../core/error';
|
|
3
|
+
import { Wallets } from '../resources';
|
|
4
|
+
import { HPKERecipient, setupHPKERecipient } from './cryptography';
|
|
5
|
+
|
|
6
|
+
export class JwtExchangeService {
|
|
7
|
+
private _hpkeRecipient: HPKERecipient | null = null;
|
|
8
|
+
private walletsService: Wallets;
|
|
9
|
+
private jwtCache: LRUCache<string, string>;
|
|
10
|
+
|
|
11
|
+
constructor(walletsService: Wallets, authorizationKeyCacheMaxCapacity: number) {
|
|
12
|
+
this.walletsService = walletsService;
|
|
13
|
+
this.jwtCache = new LRUCache({ max: authorizationKeyCacheMaxCapacity });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private async getHpkeRecipient(): Promise<HPKERecipient> {
|
|
17
|
+
if (!this._hpkeRecipient) {
|
|
18
|
+
this._hpkeRecipient = await setupHPKERecipient();
|
|
19
|
+
}
|
|
20
|
+
return this._hpkeRecipient;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Exchanges a JWT for an authorization key.
|
|
25
|
+
* @param jwt - The JWT to exchange for an authorization key.
|
|
26
|
+
* @returns The (base-64 encoded PKCS8-formatted) authorization key.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
async exchangeJwtForAuthorizationKey(jwt: string): Promise<string> {
|
|
30
|
+
const cachedAuthorizationKey = this.jwtCache.get(jwt);
|
|
31
|
+
if (cachedAuthorizationKey) {
|
|
32
|
+
return cachedAuthorizationKey;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const { publicKeySpki, decryptPayload } = await this.getHpkeRecipient();
|
|
36
|
+
|
|
37
|
+
const signer = await this.walletsService.authenticateWithJwt({
|
|
38
|
+
user_jwt: jwt,
|
|
39
|
+
encryption_type: 'HPKE',
|
|
40
|
+
// We fall back to `Buffer` here as Uint8Array.toBase64 is not widely supported yet
|
|
41
|
+
recipient_public_key: Buffer.from(publicKeySpki).toString('base64'),
|
|
42
|
+
});
|
|
43
|
+
if (
|
|
44
|
+
'encrypted_authorization_key' in signer &&
|
|
45
|
+
signer.encrypted_authorization_key.encryption_type === 'HPKE'
|
|
46
|
+
) {
|
|
47
|
+
const encryptedAuthorizationKey = signer.encrypted_authorization_key;
|
|
48
|
+
const decryptedAuthorizationKey = await decryptPayload(
|
|
49
|
+
// We fall back to `Buffer` here as Uint8Array.fromBase64 is not widely supported yet
|
|
50
|
+
Buffer.from(encryptedAuthorizationKey.encapsulated_key, 'base64'),
|
|
51
|
+
Buffer.from(encryptedAuthorizationKey.ciphertext, 'base64'),
|
|
52
|
+
);
|
|
53
|
+
const authorizationKey = new TextDecoder().decode(decryptedAuthorizationKey);
|
|
54
|
+
this.jwtCache.set(
|
|
55
|
+
jwt,
|
|
56
|
+
authorizationKey,
|
|
57
|
+
// Setting the TTL here makes the LRU cache check and prune on `.get`.
|
|
58
|
+
{ ttl: signer.expires_at - Date.now() },
|
|
59
|
+
);
|
|
60
|
+
return authorizationKey;
|
|
61
|
+
} else {
|
|
62
|
+
throw new PrivyAPIError('JWT exchange failed: unsupported encryption type');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { base58 } from '@scure/base';
|
|
2
|
+
import { PrivyAPIError } from '../error';
|
|
3
|
+
|
|
4
|
+
export interface EntropyToBytesInput {
|
|
5
|
+
entropy: string | Uint8Array;
|
|
6
|
+
entropyType: 'hd' | 'private-key';
|
|
7
|
+
chainType: 'ethereum' | 'solana';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function entropyToBytes(wallet: EntropyToBytesInput): Uint8Array {
|
|
11
|
+
const { entropy, entropyType, chainType } = wallet;
|
|
12
|
+
if (typeof entropy !== 'string') {
|
|
13
|
+
// If a straight entropy byte array is provided, return it
|
|
14
|
+
return entropy;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
switch (entropyType) {
|
|
18
|
+
case 'hd':
|
|
19
|
+
// HD entropy is a BIP39 mnemonic that can be encoded as utf-8
|
|
20
|
+
return new TextEncoder().encode(entropy);
|
|
21
|
+
case 'private-key':
|
|
22
|
+
if (chainType === 'ethereum') {
|
|
23
|
+
try {
|
|
24
|
+
// Private key strings are hex encoded for Ethereum
|
|
25
|
+
const entropyWithout0x = entropy.startsWith('0x') ? entropy.slice(2) : entropy;
|
|
26
|
+
// We fall back to `Buffer` here as Uint8Array.fromHex is not widely supported yet
|
|
27
|
+
return new Uint8Array(Buffer.from(entropyWithout0x, 'hex'));
|
|
28
|
+
} catch (error) {
|
|
29
|
+
throw new PrivyAPIError(`Invalid private key: Ethereum entropy must be hex encoded`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (chainType === 'solana') {
|
|
34
|
+
try {
|
|
35
|
+
// Private key strings are base58 encoded for Solana
|
|
36
|
+
return base58.decode(entropy);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new PrivyAPIError(`Invalid private key: Solana entropy must be base58 encoded`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// This should be unreachable, so we check with `satisfies never`
|
|
43
|
+
throw new PrivyAPIError(`Invalid chain type for imports: ${chainType satisfies never}`);
|
|
44
|
+
default:
|
|
45
|
+
// This should be unreachable, so we check with `satisfies never`
|
|
46
|
+
throw new PrivyAPIError(`Invalid entropy type: ${entropyType satisfies never}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ClientOptions, PrivyAPI } from '../client';
|
|
2
|
+
import { PrivyWalletsService } from './services/wallets';
|
|
3
|
+
import { PrivyPoliciesService } from './services/policies';
|
|
4
|
+
import { PrivyTransactionsService } from './services/transactions';
|
|
5
|
+
import { PrivyKeyQuorumsService } from './services/key-quorums';
|
|
6
|
+
import { PrivyUsersService } from './services/users';
|
|
7
|
+
import { PrivyUtils } from './services/utils';
|
|
8
|
+
import { JwtExchangeService } from '../lib/jwt-exchange';
|
|
9
|
+
import { VERSION } from '../version';
|
|
10
|
+
|
|
11
|
+
type InternalClientOptions = Omit<ClientOptions, 'appID' | 'appSecret' | 'baseUrl'>;
|
|
12
|
+
|
|
13
|
+
export interface PrivyClientOptions extends InternalClientOptions {
|
|
14
|
+
appId: string;
|
|
15
|
+
appSecret: string;
|
|
16
|
+
apiUrl?: string;
|
|
17
|
+
authorizationKeyCacheMaxCapacity?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const DEFAULT_AUTHORIZATION_KEY_CACHE_MAX_CAPACITY = 1000;
|
|
21
|
+
|
|
22
|
+
export class PrivyClient {
|
|
23
|
+
private privyApiClient: PrivyAPI;
|
|
24
|
+
private walletsService: PrivyWalletsService;
|
|
25
|
+
private policiesService: PrivyPoliciesService;
|
|
26
|
+
private transactionsService: PrivyTransactionsService;
|
|
27
|
+
private keyQuorumsService: PrivyKeyQuorumsService;
|
|
28
|
+
private usersService: PrivyUsersService;
|
|
29
|
+
private utilsService: PrivyUtils;
|
|
30
|
+
private jwtExchangeService: JwtExchangeService;
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
_jwtExchange(): JwtExchangeService {
|
|
34
|
+
return this.jwtExchangeService;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public constructor({
|
|
38
|
+
appId,
|
|
39
|
+
appSecret,
|
|
40
|
+
apiUrl,
|
|
41
|
+
authorizationKeyCacheMaxCapacity = DEFAULT_AUTHORIZATION_KEY_CACHE_MAX_CAPACITY,
|
|
42
|
+
defaultHeaders,
|
|
43
|
+
...clientOptions
|
|
44
|
+
}: PrivyClientOptions) {
|
|
45
|
+
this.privyApiClient = new PrivyAPI({
|
|
46
|
+
...clientOptions,
|
|
47
|
+
appID: appId,
|
|
48
|
+
appSecret: appSecret,
|
|
49
|
+
baseURL: apiUrl,
|
|
50
|
+
defaultHeaders: {
|
|
51
|
+
...defaultHeaders,
|
|
52
|
+
// Convention is: <client_name>:<semantic_version>
|
|
53
|
+
'privy-client': `node:${VERSION}`,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
this.jwtExchangeService = new JwtExchangeService(
|
|
57
|
+
this.privyApiClient.wallets,
|
|
58
|
+
authorizationKeyCacheMaxCapacity,
|
|
59
|
+
);
|
|
60
|
+
this.walletsService = new PrivyWalletsService(this.privyApiClient, this);
|
|
61
|
+
this.policiesService = new PrivyPoliciesService(this.privyApiClient, this);
|
|
62
|
+
this.transactionsService = new PrivyTransactionsService(this.privyApiClient);
|
|
63
|
+
this.keyQuorumsService = new PrivyKeyQuorumsService(this.privyApiClient, this);
|
|
64
|
+
this.usersService = new PrivyUsersService(this.privyApiClient);
|
|
65
|
+
this.utilsService = new PrivyUtils(this);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public wallets(): PrivyWalletsService {
|
|
69
|
+
return this.walletsService;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public policies(): PrivyPoliciesService {
|
|
73
|
+
return this.policiesService;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public transactions(): PrivyTransactionsService {
|
|
77
|
+
return this.transactionsService;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public keyQuorums(): PrivyKeyQuorumsService {
|
|
81
|
+
return this.keyQuorumsService;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public users(): PrivyUsersService {
|
|
85
|
+
return this.usersService;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public utils(): PrivyUtils {
|
|
89
|
+
return this.utilsService;
|
|
90
|
+
}
|
|
91
|
+
}
|