@privy-io/privy-node
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -14,2 +14,2 @@ import crypto from 'crypto'; | ||
*/ | ||
export declare const jwtKeyFromApiSecret: (apiSecret: string) => crypto.KeyObject; | ||
export declare const jwtKeyFromApiSecret: (apiSecret: string) => Promise<crypto.KeyObject>; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.jwtKeyFromApiSecret = exports.createAccessTokenClaims = exports.signAccessToken = void 0; | ||
const crypto_1 = __importDefault(require("crypto")); | ||
const jose_1 = require("jose"); | ||
const tweetnacl_1 = __importDefault(require("tweetnacl")); | ||
const secondsSinceEpoch = () => { | ||
@@ -43,19 +38,15 @@ return Math.floor(new Date().getTime() / 1000); | ||
const jwtKeyFromApiSecret = (apiSecret) => { | ||
// Decode from URL-safe base64. | ||
const apiSecretBuffer = Buffer.from(apiSecret, 'base64'); | ||
// Generate the signing key pair deterministicaly from the secret. | ||
const keyPair = tweetnacl_1.default.sign.keyPair.fromSeed(apiSecretBuffer); | ||
// Convert raw Ed25519 key buffers into Node crypto KeyObjects. | ||
const privateKeyJwk = { | ||
alg: 'EdDSA', | ||
crv: 'Ed25519', | ||
d: Buffer.from(keyPair.secretKey.slice(0, 32)).toString('base64'), | ||
x: Buffer.from(keyPair.publicKey).toString('base64'), | ||
d: apiSecret, | ||
x: '', | ||
kty: 'OKP', | ||
}; | ||
return crypto_1.default.createPrivateKey({ | ||
key: privateKeyJwk, | ||
format: 'jwk', | ||
}); | ||
// In Node.js, the return value is a `KeyObject`. | ||
// https://github.com/panva/jose/blob/main/docs/types/types.KeyLike.md | ||
return (0, jose_1.importJWK)(privateKeyJwk); | ||
}; | ||
exports.jwtKeyFromApiSecret = jwtKeyFromApiSecret; | ||
//# sourceMappingURL=accessToken.js.map |
/// <reference types="node" /> | ||
import { BatchOptions, EncryptedUserDataResponseValue, DataKeyUserRequest, DataKeyBatchRequest } from './types'; | ||
import { UpdateFieldInstanceRequest } from './model/requests'; | ||
import { FieldInstance, BatchFieldInstances } from './fieldInstance'; | ||
@@ -100,7 +101,26 @@ import { PrivyConfig, SigningFn } from './config'; | ||
*/ | ||
put(userId: string, fields: { | ||
field: string; | ||
value: string; | ||
}[]): Promise<FieldInstance[]>; | ||
put(userId: string, fields: UpdateFieldInstanceRequest[]): Promise<FieldInstance[]>; | ||
/** | ||
* Delete a field of data for a given user. | ||
* | ||
* ```typescript | ||
* await client.del("0x123", "email"); | ||
* ``` | ||
* | ||
* @param userId The id of the user. | ||
* @param fields The field to delete. | ||
*/ | ||
del(userId: string, fields: string): Promise<void>; | ||
/** | ||
* Delete multiple fields of data for a given user. | ||
* | ||
* ```typescript | ||
* await client.del("0x123", ["email", "name"]); | ||
* ``` | ||
* | ||
* @param userId The id of the user. | ||
* @param fields The list of fields to delete. | ||
*/ | ||
del(userId: string, fields: string[]): Promise<void>; | ||
/** | ||
* Download a file stored under a field. | ||
@@ -107,0 +127,0 @@ * |
@@ -128,2 +128,12 @@ "use strict"; | ||
} | ||
async del(userId, fields) { | ||
const path = (0, paths_1.userDataPath)(userId, (0, utils_1.wrap)(fields)); | ||
try { | ||
await this.api.delete(path); | ||
return; | ||
} | ||
catch (error) { | ||
throw (0, errors_1.formatPrivyError)(error); | ||
} | ||
} | ||
/** | ||
@@ -130,0 +140,0 @@ * Download a file stored under a field. |
@@ -43,3 +43,3 @@ "use strict"; | ||
const jwtKey = (0, accessToken_1.jwtKeyFromApiSecret)(apiSecret); | ||
return (claims) => (0, accessToken_1.signAccessToken)(jwtKey, claims); | ||
return async (claims) => (0, accessToken_1.signAccessToken)(await jwtKey, claims); | ||
}; | ||
@@ -46,0 +46,0 @@ class PrivyConfig { |
export { PrivyClient } from './client'; | ||
export { AliasKeyRequest, AliasWrapperKeyRequest, CreateFieldRequest, UpdateRoleRequest, CreateRoleRequest, CreateAccessGroupRequest, UpdateFieldRequest, UpdateAccessGroupRequest, EncryptedAliasRequestValue, } from './model/requests'; | ||
export { AliasKeyRequest, AliasWrapperKeyRequest, CreateFieldRequest, UpdateRoleRequest, CreateRoleRequest, CreateAccessGroupRequest, UpdateAccessGroupRequest, UpdateFieldRequest, UpdateFieldInstanceRequest, EncryptedAliasRequestValue, } from './model/requests'; | ||
export { AccessGroup, AccessTokenClaims, Field, Role, UserPermission } from './model/data'; | ||
@@ -4,0 +4,0 @@ export { FieldInstance, BatchFieldInstances, UserFieldInstances } from './fieldInstance'; |
@@ -35,2 +35,6 @@ export interface AccessTokenRequest { | ||
} | ||
export interface UpdateFieldInstanceRequest { | ||
field: string; | ||
value: string; | ||
} | ||
/** | ||
@@ -37,0 +41,0 @@ * The required attributes of an access group |
@@ -6,3 +6,3 @@ "use strict"; | ||
const path = `/users/${userId}/data`; | ||
const query = ['new=t']; | ||
const query = []; | ||
if (fields && fields.length > 0) { | ||
@@ -52,3 +52,3 @@ const uriEncodedFields = fields.map(encodeURIComponent); | ||
const integrityHashPath = (integrityHash) => { | ||
return `/data/${integrityHash}?new=t`; | ||
return `/data/${integrityHash}`; | ||
}; | ||
@@ -55,0 +55,0 @@ exports.integrityHashPath = integrityHashPath; |
{ | ||
"name": "@privy-io/privy-node", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Node server-side client for the Privy API", | ||
@@ -44,4 +44,3 @@ "keywords": [ | ||
"jose": "^4.8.0", | ||
"jwt-decode": "^3.1.2", | ||
"tweetnacl": "^1.0.3" | ||
"jwt-decode": "^3.1.2" | ||
}, | ||
@@ -48,0 +47,0 @@ "engines": { |
@@ -92,4 +92,4 @@ # @privy-io/privy-node | ||
PRIVY_KMS_URL=<privy kms url> | ||
PRIVY_API_PUBLIC_KEY=<your public key> | ||
PRIVY_API_SECRET_KEY=<your private key> | ||
PRIVY_API_KEY=<your public key> | ||
PRIVY_API_SECRET=<your private key> | ||
``` | ||
@@ -96,0 +96,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
147535
7
2426
0
- Removedtweetnacl@^1.0.3
- Removedtweetnacl@1.0.3(transitive)