Search…
Vault
Manage cryptographic key material and sign on behalf of your users.
TypeScript
1
=import { identClientFactory, vaultClientFactory } from 'provide-js';
2
3
const appId = '<provide app id>'; // the app id
4
const appAccessToken = '<signed jwt>'; // application token
5
6
// initialize ident instance for the application
7
const ident = identClientFactory(accessToken);
8
9
// create a virtual application user
10
const virtualUser = await ident.createUser({
11
application_id: appId,
12
email: `joe.user.${new Date().getTime()}@example.com`,
13
first_name: 'Joe',
14
last_name: 'User',
15
})
16
17
console.log(virtualUser.id); // associate this id with your local user
18
19
const userAccessToken = (await ident.createToken({
20
application_id: appId,
21
user_id: virtualUser.id,
22
scope: 'offline_access',
23
})).accessToken!;
24
25
const org = await ident.createOrganization({
26
name: 'Acme Inc.',
27
});
28
29
const orgAccessToken = (await orgIdent.createToken({
30
organization_id: org.id,
31
scope: 'offline_access',
32
})).accessToken!;
33
34
// the refresh token is also returned here and should also be persisted
35
// and used to create future access tokens...
36
37
// initialize a vault client instance for the organization
38
const vault = vaultClientFactory(orgAccessToken);
39
40
// create a vault for the organization
41
const orgVault = await vault.createVault({
42
name: `${org.name} Vault`,
43
description: `${org.name} vault instance`,
44
});
45
46
// create a secp256k1 keypair for the organization...
47
const key = await vault.createVaultKey(orgVault.id, {
48
type: 'asymmetric',
49
usage: 'sign/verify',
50
spec: 'secp256k1',
51
name: `${org.name} ETH keypair`,
52
description: `${org.name} ETH keypair`,
53
});
Copied!
Last modified 1mo ago
Copy link