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 Mar 9, 2022
1 parent c45a81c commit 1ce8c83
Show file tree
Hide file tree
Showing 31 changed files with 4,192 additions and 4,116 deletions.
76 changes: 41 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
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,57 +60,50 @@ 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

```js
const {
signerService,
stakingService,
messagingService,
connectToCacheServer,
isSessionActive,
storeSession
} = await initWithPrivateKeySigner(privateKey, rpcUrl)
const {
signerService,
stakingService,
messagingService,
connectToCacheServer,
isSessionActive,
storeSession,
} = await initWithPrivateKeySigner(privateKey, rpcUrl);
```

2. Connecting to cache server. Depending on signer type signature might be requested

```js
// IAM has builtin default settings for VOLTA CHAIN, which can overriden
setChainConfig(1111, {
didContractAddress: '0x3e2fb24edc3536d655720280b427c91bcb55f3d6',
ensRegistryAddress: '0xa372d665f83197a63bbe633ebe19c7bfd4943003',
ensResolverAddress: '0xe878bdcf5148307378043bfd2b584909aa48a227',
rpcUrl: 'http://some-rpc.com',
})
didContractAddress: '0x3e2fb24edc3536d655720280b427c91bcb55f3d6',
ensRegistryAddress: '0xa372d665f83197a63bbe633ebe19c7bfd4943003',
ensResolverAddress: '0xe878bdcf5148307378043bfd2b584909aa48a227',
rpcUrl: 'http://some-rpc.com',
});

setMessagingOptions(1111, {
messagingMethod: MessagingMethod.Nats,
natsServerUrl: 'https://some-exchange-server.com'
})
messagingMethod: MessagingMethod.Nats,
natsServerUrl: 'https://some-exchange-server.com',
});

setCacheClientOptions(1111, {
url: 'https://some-cache-server.com/',
cacheServerSupportsAuth: true,
})
url: 'https://some-cache-server.com/',
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 Expand Up @@ -130,9 +136,9 @@ npm run build

## Active Maintainers

* [Ahmed Ibrahim](https://github.com/ahmedolaibrahim)
* [John Henderson](https://github.com/jrhender)
* [Dmitry Fesenko](https://github.com/JGiter)
- [Ahmed Ibrahim](https://github.com/ahmedolaibrahim)
- [John Henderson](https://github.com/jrhender)
- [Dmitry Fesenko](https://github.com/JGiter)

## Contributing

Expand Down
76 changes: 41 additions & 35 deletions docs/api/README.md
Original file line number Diff line number Diff line change
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,57 +60,50 @@ 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

```js
const {
signerService,
stakingService,
messagingService,
connectToCacheServer,
isSessionActive,
storeSession
} = await initWithPrivateKeySigner(privateKey, rpcUrl)
const {
signerService,
stakingService,
messagingService,
connectToCacheServer,
isSessionActive,
storeSession,
} = await initWithPrivateKeySigner(privateKey, rpcUrl);
```

2. Connecting to cache server. Depending on signer type signature might be requested

```js
// IAM has builtin default settings for VOLTA CHAIN, which can overriden
setChainConfig(1111, {
didContractAddress: '0x3e2fb24edc3536d655720280b427c91bcb55f3d6',
ensRegistryAddress: '0xa372d665f83197a63bbe633ebe19c7bfd4943003',
ensResolverAddress: '0xe878bdcf5148307378043bfd2b584909aa48a227',
rpcUrl: 'http://some-rpc.com',
})
didContractAddress: '0x3e2fb24edc3536d655720280b427c91bcb55f3d6',
ensRegistryAddress: '0xa372d665f83197a63bbe633ebe19c7bfd4943003',
ensResolverAddress: '0xe878bdcf5148307378043bfd2b584909aa48a227',
rpcUrl: 'http://some-rpc.com',
});

setMessagingOptions(1111, {
messagingMethod: MessagingMethod.Nats,
natsServerUrl: 'https://some-exchange-server.com'
})
messagingMethod: MessagingMethod.Nats,
natsServerUrl: 'https://some-exchange-server.com',
});

setCacheClientOptions(1111, {
url: 'https://some-cache-server.com/',
cacheServerSupportsAuth: true,
})
url: 'https://some-cache-server.com/',
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 Expand Up @@ -130,9 +136,9 @@ npm run build

## Active Maintainers

* [Ahmed Ibrahim](https://github.com/ahmedolaibrahim)
* [John Henderson](https://github.com/jrhender)
* [Dmitry Fesenko](https://github.com/JGiter)
- [Ahmed Ibrahim](https://github.com/ahmedolaibrahim)
- [John Henderson](https://github.com/jrhender)
- [Dmitry Fesenko](https://github.com/JGiter)

## Contributing

Expand Down
19 changes: 19 additions & 0 deletions docs/api/classes/EkcSigner.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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`\>
Loading

0 comments on commit 1ce8c83

Please sign in to comment.