mattr-vii-client v0.0.13
š 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 });
}