0.0.13 ā€¢ Published 1 year ago

mattr-vii-client v0.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

šŸš€ MATTR VII Client

A Node.js server-side client for MATTR VII API platform

ā“ Background

Interacting with MATTR VII API platform has a steep learning curve, doesn't matter if you make API calls to their platform using Postman or writing custom code. The most challenging part of it comes down to not knowing the exact data type you need to provide and will be receiving for each API call, which makes it even harder for teams to understand how to interact with MATTR VII API platform --- on top of learning the domain knowledge surrounding dencentralised identities, cryptography as well as Open-ID Connect (OIDC). This SDK is an attempt to provide a layer of abstraction over the complexities and making it easier for everyone to interact with MATTR VII

šŸ”‘ The problem we're solving:

Simplifying API calls to MATTR VII by giving you code autocompletion for making requests & return data-types.

šŸ“š Usage:

Install the SDK

yarn add mattr-vii-client
// or
npm install mattr-vii-vlient

šŸ›’ Import the SDK

import { MattrViiClient, ApiTypes } from 'mattr-vii-client'

šŸ”„ Initialise the client

const client = new MattrViiClient({
  tenantSubdomain: process.env.MATTR_TENANT_URL,
  authToken: process.env.MATTR_AUTH_TOKEN,
});

ā€šŸ« Start using the SDK following these guidelines:

Platform Core:

šŸˆ Misc: Using the SDK in NestJS

// mattr.service.ts
@Injectable()
export class MattrService extends MattrViiClient {
  super({
    tenantSubdomain: process.env.MATTR_TENANT_URL,
    authToken: process.env.MATTR_AUTH_TOKEN,
  })
}

// user.controller.ts
@Controller('user')
export class UserController {
  constructor(
    private readonly mattrService: MattrService,
    private readonly prismaService: PrismaService,
  ) {};

  @Post('create')
  public async createUser(@Body() args: CreateUserBody) {
    const body: ApiTypes.PlatformCore.DIDs.CreateDidReqBody = {
      method: 'key',
      options: {
        keyType: 'ed25519',
      },
    };
    const did = await this.mattrService.PlatformCore.DIDs.createDid(body);
    return await this.prismaService.user.create({
      ...args,
      did: did.did,
    })
  }
}

ā° Use-case example - Then VS now

/*
Example use-case:
=== Send a verifiable credential to a Digital Wallet ===

Main steps:
1. Create a DID
2. Create a Credential using the DID created
3. Sign a message using the Credential you just created
4. Encrypt the signed message
5. Send the message to a wallet
*/

// šŸ’© Before šŸ’©
// āŒ Raw API calls
const url = `https://${process.env.MATTR_TENANT}.vii.mattr.global/core/v1`;
const createDid = async () => {
  const res = await fetch(`${url}/dids`, {
    method: "post",
    headers: {
      "Content-type": "application/json",
      Authorization: 'Bearer <YOUR_JWT_HERE>',
    },
    // āŒ You have no idea if the body you passed in is what the endpoint expects
    body: JSON.stringify({
      method: 'key',
      options: {keyType: 'ed25519'},
    }),
  });
  return res.json();
  // āŒ You have no clue how big & nested your response will be...
}


// āœ… Now with our SDK āœ…
/* main.ts */
import { MattrViiClient, ApiTypes } from 'mattr-vii-client';

// āœ… Initialise the SDK once and use it across your backend
// āœ… Minimal environment variables required
const client = new MattrViiClient({
  tenantSubdomain: process.env.MATTR_TENANT_URL,
  authToken: process.env.MATTR_AUTH_TOKEN,
});

export const createDid = async () => {
  // āœ… Tells you exactly the shape of your request body
  const body: ApiTypes.PlatformCore.DIDs.CreateDidReqBody = {
    method: 'key',
    options: {
      keyType: 'ed25519',
    },
  };
  // āœ… Auto-completion helps you figuring out which method to call
  // āœ… Enforcing you to pass in the correct body for each request
  // āœ… Has a response type
  return await client.PlatformCore.DIDs.createDid({ body });
}
0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

1.0.0

1 year ago