Skip to content

Commit

Permalink
fix: review and update profile readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsan-javaid authored and diwakergupta committed Aug 24, 2021
1 parent a834742 commit 227b25a
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions packages/profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,86 @@ Functions for manipulating user profiles.
```
npm install @stacks/profile
```

### Get profile from token

```typescript
import { extractProfile } from '@stacks/profile';

// Token received after signin in browser using auth or connect package
const token = '<insert profile token here>';

const profile = extractProfile(token);
// profile
```

### Verify profile token

```typescript
import { verifyProfileToken } from '@stacks/profile';

// Token received after signin in browser using auth or connect package
const token = '<insert profile token here>';
const publicKey = '<insert public key>';

const decodedToken = verifyProfileToken(token, publicKey);
// decodedToken if verified successfully
// Otherwise throws an error if token verification fails
```

### Make zonefile

```typescript
import { makeProfileZoneFile } from '@stacks/profile';

const fileUrl = 'https://mq9.s3.amazonaws.com/naval.id/profile.json';
const origin = 'naval.id';
const zoneFile = makeProfileZoneFile(origin, fileUrl);
// zoneFile contents
```
### Profile to token

```typescript
import { signProfileToken, verifyProfileToken, extractProfile } from '@stacks/profile';

// Token received after signin in browser using auth or connect
const token = '<insert profile token here>';
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 = '<private key>'; // process.env.privateKey
const publicKey = '<public key>';

const signedToken = signProfileToken(profile, privateKey);
const decodedToken = verifyProfileToken(signedToken, publicKey);
// decodedToken if verified successfully
// Otherwise throws an error if token verification fails
```

### Profile Validation

```typescript
import { extractProfile, Profile } from '@stacks/profile';

// Token received after signin in browser using auth or connect
const token = '<insert profile token here>';
// warning: Do not expose your private key by hard coding in code. Use env variables to load private keys.
const privateKey = '<private key>'; // process.env.privateKey
const publicKey = '<public key>';

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);
```

1 comment on commit 227b25a

@vercel
Copy link

@vercel vercel bot commented on 227b25a Aug 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.