JavaScript SDK
Installation and usage guide for the Humanmark JavaScript SDK.
Installation
npm install @humanmark/sdk-js
# or
yarn add @humanmark/sdk-js
# or
pnpm add @humanmark/sdk-js
Quick Start
Initialize the SDK with your API key and a challenge token from your backend:
import { HumanmarkSdk, ErrorCode } from '@humanmark/sdk-js';
const sdk = new HumanmarkSdk({
apiKey: 'your-api-key',
challengeToken: 'challenge-token-from-backend'
});
try {
const receipt = await sdk.verify();
// Send receipt to your backend for verification
console.log('Receipt:', receipt);
} catch (error) {
if (error.code === ErrorCode.USER_CANCELLED) {
console.log('User cancelled verification');
} else {
console.error('Verification failed:', error);
}
}
Configuration Options
Option | Type | Required | Description |
---|---|---|---|
apiKey | string | Yes | Your Humanmark API key |
challengeToken | string | Yes | Challenge token from your backend |
baseUrl | string | No | Base URL for API requests (default: 'https://humanmark.io') |
theme | 'light' | 'dark' | 'auto' | No | Modal theme (default: 'dark') |
CDN
<!-- Browser bundle (IIFE) with SRI -->
<script
src="https://cdn.jsdelivr.net/npm/@humanmark/sdk-js@1.0.0/dist/browser/index.js"
integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
crossorigin="anonymous">
</script>
<!-- Or UMD bundle with SRI -->
<script
src="https://cdn.jsdelivr.net/npm/@humanmark/sdk-js@1.0.0/dist/umd/index.js"
integrity="sha384-RKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
crossorigin="anonymous">
</script>
Security Note
Always use SRI (Subresource Integrity) hashes when loading scripts from CDN to ensure the integrity of the code.
Find the latest SRI hashes in the README at npm: @humanmark/sdk-js
Note: Humanmark is currently in beta. To get API credentials, please email sales@humanmark.io.