[](https://www.npmjs.org/package/@openfort/shield-js)
npm install @openfort/shield-jsShieldJS is a TypeScript library for interacting with the Openfort Shield API. It provides easy-to-use methods for retrieving and storing secrets.
To use ShieldJS in your project, install it via npm or pnpm:
``bash`
pnpm add @openfort/shield-js
`typescript`
import {
ShieldSDK,
ShieldOptions,
ShieldAuthProvider,
OpenfortAuthOptions,
CustomAuthOptions,
OpenfortOAuthProvider,
OpenfortOAuthTokenType
} from '@openfort/shield-js';
typescript
const shieldOptions: ShieldOptions = {
apiKey: 'your-api-key',
// Optional: Specify a custom base URL
baseURL: 'https://shield.openfort.io'
};const shieldSDK = new ShieldSDK(shieldOptions);
`$3
`typescript
import { Share } from '@openfort/shield-js';const share: Share = {
secret: "your-secret-data",
entropy: "optional-entropy",
encryptionParameters: {
salt: "salt-value",
iterations: 10000,
length: 32,
digest: "SHA-256"
}
};
const authOptions: ShieldAuthOptions = {
// ... authentication options
};
await shieldSDK.storeSecret(share, authOptions);
`$3
`typescript
// Delete all secrets for the authenticated user
await shieldSDK.deleteSecret(authOptions);// Delete a specific secret by reference
await shieldSDK.deleteSecret(authOptions, undefined, "reference-id");
`$3
`typescript
const share = await shieldSDK.getSecret(authOptions);
console.log(share.secret);// Retrieve by specific reference
const shareByRef = await shieldSDK.getSecretByReference(authOptions, "reference-id");
console.log(shareByRef.secret);
`$3
`typescript
const encryptionMethods = await shieldSDK.getEncryptionMethodsBySignerReferences(
authOptions,
["ref1", "ref2"]
);
// Returns Map with reference as key and method as value// Get detailed information including passkey details
const detailedMethods = await shieldSDK.getEncryptionMethodsBySignerReferencesDetailed(
authOptions,
["ref1", "ref2"]
);
// Returns Map with additional details
`$3
`typescript
const encryptionMethods = await shieldSDK.getEncryptionMethodsByOwnerId(
authOptions,
["user1", "user2"]
);
// Returns Map with userId as key and method as value// Get detailed information including passkey details
const detailedMethods = await shieldSDK.getEncryptionMethodsByOwnerIdDetailed(
authOptions,
["user1", "user2"]
);
// Returns Map with additional details
`$3
#### Update a Secret
`typescript
const updatedShare: Share = {
secret: "updated-secret-data",
// ... other share properties
};await shieldSDK.updateSecret(authOptions, updatedShare);
`#### Get Keychain (List of Shares)
`typescript
// Get all shares for the authenticated user
const shares = await shieldSDK.keychain(authOptions);// Get shares filtered by reference
const shares = await shieldSDK.keychain(authOptions, "reference-filter");
`#### Pre-register a Secret (Admin)
`typescript
await shieldSDK.preRegister(share, authOptions);
`API Reference
$3
- storeSecret(share: Share, auth: ShieldAuthOptions, requestId?: string): Promise
- getSecret(auth: ShieldAuthOptions, requestId?: string): Promise
- getSecretByReference(auth: ShieldAuthOptions, reference: string, requestId?: string): Promise
- updateSecret(auth: ShieldAuthOptions, share: Share, requestId?: string): Promise
- deleteSecret(auth: ShieldAuthOptions, requestId?: string, reference?: string): Promise
- keychain(auth: ShieldAuthOptions, reference?: string, requestId?: string): Promise
- getEncryptionMethodsBySignerReferences(auth: ShieldAuthOptions, signers: string[], requestId?: string): Promise