Skip to content

Commit

Permalink
feat: verifiable credential poc
Browse files Browse the repository at this point in the history
  • Loading branch information
Harasz committed Apr 7, 2022
1 parent 4dd335d commit a7f8df7
Show file tree
Hide file tree
Showing 30 changed files with 2,155 additions and 896 deletions.
42 changes: 24 additions & 18 deletions README.md
Expand Up @@ -26,11 +26,24 @@ For development purposes, please follow below steps to integrate the library wit

### Prerequisites

`iam-client-lib` is written in TypeScript. Make sure to have Node.js (>= v10) installed.
Create a folder named **_iam-client-lib_** and clone this GIT project.
`iam-client-lib` is written in TypeScript. Make sure to have Node.js (>= v10) installed. Create a folder named **_iam-client-lib_** and clone this GIT project.

Also note that having a DID document with a public key is a prerequisite for using iam-client-lib and during initialization the library with attempt to add a public key to the DID document if one doesn't exist. This addition of the public key requires the account to be funded.

`iam-client-lib` has a WebAssembly dependency. Some bundlers/frameworks doesn't support it out of the box, so some action are required. Here is a list of known problems:

- **Angular** - you'll have to add following in you `package.json`

```
"browser": {
"fs": false,
"os": false,
"path": false
}
```

- **React** - you'll have to add a `wasm-loader` for the files with `.wasm` extension to your Webpack configuration. To edit Webpack config you can use [@craco/craco](https://www.npmjs.com/package/@craco/craco) or [react-app-rewired](https://www.npmjs.com/package/react-app-rewired).

### Install

Latest stable version
Expand All @@ -49,8 +62,7 @@ Some library dependencies require Node.js built-ins. Therefore when library is u

### Initialization

Because of dependencies between modules they should be initialized in right order.
This is achieved by accessing module initializer from initialization function of required module.
Because of dependencies between modules they should be initialized in right order. This is achieved by accessing module initializer from initialization function of required module.

1. Initializing signer service. It will initialize staking and messaging services and allow to connect to cache server

Expand All @@ -68,11 +80,11 @@ This is achieved by accessing module initializer from initialization function of
// IAM has builtin default settings for VOLTA CHAIN, which can overriden
// 1111 is an example of another ChainID (https://chainlist.org/)
setChainConfig(1111, {
didContractAddress: '0x3e2fb24edc3536d655720280b427c91bcb55f3d6',
ensRegistryAddress: '0xa372d665f83197a63bbe633ebe19c7bfd4943003',
ensResolverAddress: '0xe878bdcf5148307378043bfd2b584909aa48a227',
rpcUrl: 'http://some-rpc.com',
})
didContractAddress: '0x3e2fb24edc3536d655720280b427c91bcb55f3d6',
ensRegistryAddress: '0xa372d665f83197a63bbe633ebe19c7bfd4943003',
ensResolverAddress: '0xe878bdcf5148307378043bfd2b584909aa48a227',
rpcUrl: 'http://some-rpc.com',
});

setMessagingConfig(1111, {
messagingMethod: MessagingMethod.Nats,
Expand All @@ -84,20 +96,14 @@ setCacheConfig(1111, {
cacheServerSupportsAuth: true,
})

const {
cacheClient,
domainsService,
connectToDidRegistry
} = await connectToCacheServer()
const { cacheClient, domainsService, connectToDidRegistry } =
await connectToCacheServer();
```

3. Connecting to DID registry.

```js
const {
didRegistry,
claimsService
} = await connectToDidRegistry()
const { didRegistry, claimsService } = await connectToDidRegistry();
```

## Development
Expand Down
42 changes: 24 additions & 18 deletions docs/api/README.md
Expand Up @@ -26,11 +26,24 @@ For development purposes, please follow below steps to integrate the library wit

### Prerequisites

`iam-client-lib` is written in TypeScript. Make sure to have Node.js (>= v10) installed.
Create a folder named **_iam-client-lib_** and clone this GIT project.
`iam-client-lib` is written in TypeScript. Make sure to have Node.js (>= v10) installed. Create a folder named **_iam-client-lib_** and clone this GIT project.

Also note that having a DID document with a public key is a prerequisite for using iam-client-lib and during initialization the library with attempt to add a public key to the DID document if one doesn't exist. This addition of the public key requires the account to be funded.

`iam-client-lib` has a WebAssembly dependency. Some bundlers/frameworks doesn't support it out of the box, so some action are required. Here is a list of known problems:

- **Angular** - you'll have to add following in you `package.json`

```
"browser": {
"fs": false,
"os": false,
"path": false
}
```

- **React** - you'll have to add a `wasm-loader` for the files with `.wasm` extension to your Webpack configuration. To edit Webpack config you can use [@craco/craco](https://www.npmjs.com/package/@craco/craco) or [react-app-rewired](https://www.npmjs.com/package/react-app-rewired).

### Install

Latest stable version
Expand All @@ -47,8 +60,7 @@ npm i iam-client-lib@canary

### Initialization

Because of dependencies between modules they should be initialized in right order.
This is achieved by accessing module initializer from initialization function of required module.
Because of dependencies between modules they should be initialized in right order. This is achieved by accessing module initializer from initialization function of required module.

1. Initializing signer service. It will initialize staking and messaging services and allow to connect to cache server

Expand All @@ -66,11 +78,11 @@ This is achieved by accessing module initializer from initialization function of
// IAM has builtin default settings for VOLTA CHAIN, which can overriden
// 1111 is an example of another ChainID (https://chainlist.org/)
setChainConfig(1111, {
didContractAddress: '0x3e2fb24edc3536d655720280b427c91bcb55f3d6',
ensRegistryAddress: '0xa372d665f83197a63bbe633ebe19c7bfd4943003',
ensResolverAddress: '0xe878bdcf5148307378043bfd2b584909aa48a227',
rpcUrl: 'http://some-rpc.com',
})
didContractAddress: '0x3e2fb24edc3536d655720280b427c91bcb55f3d6',
ensRegistryAddress: '0xa372d665f83197a63bbe633ebe19c7bfd4943003',
ensResolverAddress: '0xe878bdcf5148307378043bfd2b584909aa48a227',
rpcUrl: 'http://some-rpc.com',
});

setMessagingConfig(1111, {
messagingMethod: MessagingMethod.Nats,
Expand All @@ -82,20 +94,14 @@ setCacheConfig(1111, {
cacheServerSupportsAuth: true,
})

const {
cacheClient,
domainsService,
connectToDidRegistry
} = await connectToCacheServer()
const { cacheClient, domainsService, connectToDidRegistry } =
await connectToCacheServer();
```

3. Connecting to DID registry.

```js
const {
didRegistry,
claimsService
} = await connectToDidRegistry()
const { didRegistry, claimsService } = await connectToDidRegistry();
```

## Development
Expand Down
19 changes: 19 additions & 0 deletions docs/api/classes/EkcSigner.md
Expand Up @@ -6,6 +6,10 @@

**`EkcSigner`**

## Implements

- `TypedDataSigner`

## Table of contents

### Constructors
Expand All @@ -19,6 +23,7 @@

### Methods

- [\_signTypedData](EkcSigner.md#_signtypeddata)
- [connect](EkcSigner.md#connect)
- [getAddress](EkcSigner.md#getaddress)
- [signMessage](EkcSigner.md#signmessage)
Expand Down Expand Up @@ -59,6 +64,20 @@ Signer.provider

## Methods

### \_signTypedData

**_signTypedData**(): `Promise`<`string`\>

#### Returns

`Promise`<`string`\>

#### Implementation of

TypedDataSigner.\_signTypedData

___

### connect

**connect**(`provider`): `Signer`
Expand Down
40 changes: 36 additions & 4 deletions docs/api/classes/SignerService.md
Expand Up @@ -12,6 +12,7 @@
- [address](SignerService.md#address)
- [chainId](SignerService.md#chainid)
- [did](SignerService.md#did)
- [didHex](SignerService.md#didhex)
- [isEthSigner](SignerService.md#isethsigner)
- [provider](SignerService.md#provider)
- [providerType](SignerService.md#providertype)
Expand All @@ -33,6 +34,7 @@
- [publicKeyAndIdentityToken](SignerService.md#publickeyandidentitytoken)
- [send](SignerService.md#send)
- [signMessage](SignerService.md#signmessage)
- [signTypedData](SignerService.md#signtypeddata)

## Constructors

Expand All @@ -44,7 +46,7 @@

| Name | Type |
| :------ | :------ |
| `_signer` | `Required`<`Signer`\> |
| `_signer` | `Required`<[`SignerT`](../modules.md#signert)\> |
| `_providerType` | [`ProviderType`](../enums/ProviderType.md) |

## Accessors
Expand Down Expand Up @@ -89,6 +91,16 @@ ___

___

### didHex

`get` **didHex**(): `string`

#### Returns

`string`

___

### isEthSigner

`get` **isEthSigner**(): `boolean`
Expand Down Expand Up @@ -121,11 +133,11 @@ ___

### signer

`get` **signer**(): `Required`<`Signer`\>
`get` **signer**(): `Required`<[`SignerT`](../modules.md#signert)\>

#### Returns

`Required`<`Signer`\>
`Required`<[`SignerT`](../modules.md#signert)\>

## Methods

Expand Down Expand Up @@ -188,7 +200,7 @@ ___

| Name | Type |
| :------ | :------ |
| `signer` | `Required`<`Signer`\> |
| `signer` | `Required`<[`SignerT`](../modules.md#signert)\> |
| `providerType` | [`ProviderType`](../enums/ProviderType.md) |

#### Returns
Expand Down Expand Up @@ -325,3 +337,23 @@ When running in browser `isEthSigner` variable should be stored in local storage
#### Returns

`Promise`<`string`\>

___

### signTypedData

**signTypedData**(`domain`, `types`, `message`): `Promise`<`string`\>

**`description`** Tries to create conformant signature (https://eips.ethereum.org/EIPS/eip-712)

#### Parameters

| Name | Type |
| :------ | :------ |
| `domain` | `TypedDataDomain` |
| `types` | `Record`<`string`, `TypedDataField`[]\> |
| `message` | `Record`<`string`, `unknown`\> |

#### Returns

`Promise`<`string`\>

0 comments on commit a7f8df7

Please sign in to comment.