Library for Stacks profiles
npm install @stacks/profileFunctions for manipulating user profiles.
```
npm install @stacks/profile
`typescript
import { extractProfile } from '@stacks/profile';
// Token received after signin in browser using auth or connect package
const token = '
const profile = extractProfile(token);
// profile
`
`typescript
import { verifyProfileToken } from '@stacks/profile';
// Token received after signin in browser using auth or connect package
const token = '
const publicKey = '
const decodedToken = verifyProfileToken(token, publicKey);
// decodedToken if verified successfully
// Otherwise throws an error if token verification fails
`
`typescript
import { makeProfileZoneFile } from '@stacks/profile';
const fileUrl = 'https://_example_.s3.amazonaws.com/naval.id/profile.json';
const origin = 'naval.id';
const zoneFile = makeProfileZoneFile(origin, fileUrl);
// zoneFile contents
`
`typescript
import { signProfileToken, verifyProfileToken, extractProfile } from '@stacks/profile';
// Token received after signin in browser using auth or connect
const token = '
const profile = extractProfile(token);
// warning: Do not expose your private key by hard coding in code. Use env variables to load private keys.
const privateKey = '
const publicKey = '
const signedToken = signProfileToken(profile, privateKey);
const decodedToken = verifyProfileToken(signedToken, publicKey);
// decodedToken if verified successfully
// Otherwise throws an error if token verification fails
`
`typescript
import { extractProfile, Profile } from '@stacks/profile';
// Token received after signin in browser using auth or connect
const token = '
// warning: Do not expose your private key by hard coding in code. Use env variables to load private keys.
const privateKey = '
const publicKey = '
const profile = extractProfile(token);
const profileObject = new Profile(profile);
console.log(profileObject);
const validationResults = Profile.validateSchema(profile);
console.log(validationResults.valid);
const profileJson = profileObject.toJSON();
console.log(profileJson);
const tokenRecords = profileObject.toToken(privateKey);
console.log(tokenRecords);
const profileFromToken = Profile.fromToken(tokenRecords, publicKey);
console.log(profileFromToken);
``