Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-1.0.0-alpha #2347

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@
"version": "BEFORE=$(jq --raw-output .version src/static/manifest.json) && AFTER=$(date +%Y.%-m.%-d) && grep --files-with-matches --recursive $BEFORE src | xargs sed --in-place \"s/$BEFORE/$AFTER/g\" && git checkout -b version-bump && git commit --all --message=\"Version $AFTER\""
},
"dependencies": {
"@kiltprotocol/sdk-js": "^0.34.0",
"@kiltprotocol/chain-helpers": "0.100.0-alpha.1",
"@kiltprotocol/credentials": "0.100.0-alpha.1",
"@kiltprotocol/did": "0.100.0-alpha.1",
"@kiltprotocol/extension-api": "KILTprotocol/kilt-extension-api#rf-sdk-1-alpha",
"@kiltprotocol/legacy-credentials": "0.100.0-alpha.1",
"@kiltprotocol/sdk-js": "1.0.0-alpha.1",
"@kiltprotocol/types": "0.100.0-alpha.1",
"@kiltprotocol/utils": "0.100.0-alpha.1",
"@polkadot/extension-inject": "^0.46.6",
"@polkadot/keyring": "^12.6.2",
"@polkadot/types": "^10.11.2",
Expand Down
19 changes: 15 additions & 4 deletions src/channels/ChallengeChannels/backgroundChallengeChannel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Runtime } from 'webextension-polyfill';
import { Utils } from '@kiltprotocol/sdk-js';

import { Crypto } from '@kiltprotocol/utils';
import { multibaseKeyToDidKey } from '@kiltprotocol/did';

import { getTabEncryption } from '../../utilities/getTabEncryption/getTabEncryption';
import { initKiltSDK } from '../../utilities/initKiltSDK/initKiltSDK';
Expand All @@ -18,9 +20,18 @@ export async function produceEncryptedChallenge(

const { dAppEncryptionDidKey, sporranEncryptionDidKeyUri } = encryption;

const { nonce, box } = Utils.Crypto.encryptAsymmetricAsStr(
Utils.Crypto.coToUInt8(challenge),
dAppEncryptionDidKey.publicKey,
const { keyType, publicKey } = multibaseKeyToDidKey(
dAppEncryptionDidKey.publicKeyMultibase,
);
if (keyType !== 'x25519') {
throw new Error(
`key type ${keyType} is not suitable for x25519 key agreement`,
);
}

const { nonce, box } = Crypto.encryptAsymmetricAsStr(
Crypto.coToUInt8(challenge),
publicKey,
encryption.encryptionKey.secretKey,
);

Expand Down
6 changes: 3 additions & 3 deletions src/channels/ChallengeChannels/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DidResourceUri } from '@kiltprotocol/sdk-js';
import type { DidUrl } from '@kiltprotocol/types';

export interface ChallengeInput {
dAppEncryptionKeyId: DidResourceUri;
dAppEncryptionKeyId: DidUrl;
challenge: string;
}

export interface ChallengeOutput {
encryptionKeyId: DidResourceUri;
encryptionKeyId: DidUrl;
encryptedChallenge: string;
nonce: string;
}
5 changes: 3 additions & 2 deletions src/channels/CreateDidChannels/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { DidUri, KiltAddress } from '@kiltprotocol/sdk-js';
import type { Did, KiltAddress } from '@kiltprotocol/types';

import { HexString } from '@polkadot/util/types';

import { DAppName } from '../../dApps/AccessChannels/DAppName';
import { Origin } from '../../dApps/AccessChannels/Origin';

export type CreateDidInput = DAppName & {
submitter: KiltAddress;
pendingDidUri?: DidUri;
pendingDidUri?: Did;
Copy link

Choose a reason for hiding this comment

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

Would changing pendingDidUrl to pendingDid following the new naming convention of the SDK break anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless it's also changed in all the apps that use this API

};

export type CreateDidOriginInput = CreateDidInput & Origin;
Expand Down
37 changes: 25 additions & 12 deletions src/channels/CredentialChannels/backgroundCredentialChannel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import type {
IEncryptedMessage,
IReject,
} from '@kiltprotocol/extension-api/types';

import {
isSubmitTerms,
isSubmitAttestation,
isRejectAttestation,
isIRequestCredential,
} from '@kiltprotocol/extension-api/utils';

import { Runtime } from 'webextension-polyfill';
import { IEncryptedMessage, IRejectTerms } from '@kiltprotocol/sdk-js';

import { BrowserChannel } from '../base/BrowserChannel/BrowserChannel';
import { channelsEnum } from '../base/channelsEnum';
Expand Down Expand Up @@ -30,12 +41,14 @@ export async function showCredentialPopup(
await getTabEncryption(sender);
const message = await decrypt(encrypted);

if (message.body.type === 'submit-terms') {
if (isSubmitTerms(message)) {
try {
const { content } = message.body;
if (specVersion === '1.0') {
// @ts-expect-error compatibility with old cType interface
content.cTypes = content.cTypes?.map((cType) => cType.schema);
message.body.content.cTypes = content.cTypes?.map(
// @ts-expect-error compatibility with old cType interface
(cType) => cType.schema,
);
}

// the DID to use for signing could be predetermined by the dApp, if we have a matching identity we’ll use it
Expand All @@ -51,23 +64,23 @@ export async function showCredentialPopup(
sender,
);
} catch (error) {
const { claim, legitimations, delegationId } = message.body.content;

const rejectionBody: IRejectTerms = {
content: { claim, legitimations, delegationId },
type: 'reject-terms',
const rejectionBody: IReject = {
content: { message: 'Terms rejected' },
type: 'reject',
};

return encrypt(rejectionBody);
}
}
if (message.body.type === 'submit-attestation') {

if (isSubmitAttestation(message)) {
await saveChannel.get(message.body.content.attestation, sender);
}
if (message.body.type === 'reject-attestation') {

if (isRejectAttestation(message)) {
await rejectChannel.get(message.body.content, sender);
}
if (message.body.type === 'request-credential') {
if (isIRequestCredential(message)) {
return await shareChannel.get(
{
credentialRequest: message.body.content,
Expand Down
2 changes: 1 addition & 1 deletion src/channels/CredentialChannels/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IEncryptedMessage } from '@kiltprotocol/sdk-js';
import type { IEncryptedMessage } from '@kiltprotocol/extension-api/types';

import { DAppName } from '../../dApps/AccessChannels/DAppName';

Expand Down
4 changes: 2 additions & 2 deletions src/channels/ShareIdentitiesChannels/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DidUri } from '@kiltprotocol/sdk-js';
import type { Did } from '@kiltprotocol/types';

import { DAppName } from '../../dApps/AccessChannels/DAppName';
import { Origin } from '../../dApps/AccessChannels/Origin';
Expand All @@ -7,4 +7,4 @@ export type ShareIdentitiesInput = DAppName;

export type ShareIdentitiesOriginInput = ShareIdentitiesInput & Origin;

export type ShareIdentitiesOutput = Array<{ did: DidUri; name?: string }>;
export type ShareIdentitiesOutput = Array<{ did: Did; name?: string }>;
7 changes: 4 additions & 3 deletions src/channels/SignDidChannels/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import type { Did, DidUrl, ICredential } from '@kiltprotocol/types';

import { HexString } from '@polkadot/util/types';
import { DidResourceUri, DidUri, ICredential } from '@kiltprotocol/sdk-js';

import { DAppName } from '../../dApps/AccessChannels/DAppName';
import { Origin } from '../../dApps/AccessChannels/Origin';

export type SignDidInput = DAppName & {
plaintext: string;
didUri?: DidUri;
didUri?: Did;
lukeg90 marked this conversation as resolved.
Show resolved Hide resolved
};

export type SignDidOriginInput = SignDidInput & Origin;

export interface SignDidOutput {
signature: HexString;
didKeyUri: DidResourceUri;
didKeyUri: DidUrl;
Copy link

Choose a reason for hiding this comment

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

Just a heads-up, mind that the new definition of DidUrl can include optional query parameters, so something like did:kilt:4....?param=value#keyId would now be a valid URL. They can of course simply be ignored, but I wanted to raise awareness that that's also possible now.

credentials?: { name: string; credential: ICredential }[];
}
7 changes: 4 additions & 3 deletions src/channels/SignDidExtrinsicChannels/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import type { Did, DidUrl, KiltAddress } from '@kiltprotocol/types';

import { HexString } from '@polkadot/util/types';
import { DidResourceUri, DidUri, KiltAddress } from '@kiltprotocol/sdk-js';

import { DAppName } from '../../dApps/AccessChannels/DAppName';
import { Origin } from '../../dApps/AccessChannels/Origin';

export type SignDidExtrinsicInput = DAppName & {
extrinsic: HexString;
submitter: KiltAddress;
didUri?: DidUri;
didUri?: Did;
};

export type SignDidExtrinsicOriginInput = SignDidExtrinsicInput & Origin;

export interface SignDidExtrinsicOutput {
signed: HexString;
didKeyUri: DidResourceUri;
didKeyUri: DidUrl;
}
8 changes: 6 additions & 2 deletions src/channels/claimChannel/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ITerms, DidUri, IEncryptedMessage } from '@kiltprotocol/sdk-js';
import type { Did } from '@kiltprotocol/types';
import type {
IEncryptedMessage,
ITerms,
} from '@kiltprotocol/extension-api/types';

export interface ClaimInput extends ITerms {
attesterName: string;
attesterDid: DidUri;
attesterDid: Did;
specVersion: '1.0' | '3.0';
}

Expand Down
2 changes: 1 addition & 1 deletion src/channels/rejectChannel/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICredential } from '@kiltprotocol/sdk-js';
import type { ICredential } from '@kiltprotocol/types';

export type RejectInput = ICredential['rootHash'];

Expand Down
2 changes: 1 addition & 1 deletion src/channels/saveChannel/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IAttestation } from '@kiltprotocol/sdk-js';
import type { IAttestation } from '@kiltprotocol/types';

export type SaveInput = IAttestation;

Expand Down
8 changes: 4 additions & 4 deletions src/channels/shareChannel/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
DidUri,
import type { Did } from '@kiltprotocol/types';
import type {
IEncryptedMessage,
IRequestCredentialContent,
} from '@kiltprotocol/sdk-js';
} from '@kiltprotocol/extension-api/types';

export type ShareInput = {
credentialRequest: IRequestCredentialContent;
verifierDid: DidUri;
verifierDid: Did;
specVersion: '1.0' | '3.0';
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/IdentitiesCarousel/IdentitiesCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function IdentityLink({
const modifiedIndex = !isNew(identity)
? identities.indexOf(identity) + delta
: isPrevious
? length - 1
: 0;
? length - 1
: 0;

const isInRange = 0 <= modifiedIndex && modifiedIndex < length;
const isNewIdentity = showAdd && !isInRange;
Expand Down
2 changes: 1 addition & 1 deletion src/components/KiltAmount/KiltAmount.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta } from '@storybook/react';
import { BalanceUtils } from '@kiltprotocol/sdk-js';
import { BalanceUtils } from '@kiltprotocol/chain-helpers';

import { KiltAmount } from './KiltAmount';

Expand Down
2 changes: 1 addition & 1 deletion src/components/KiltAmount/KiltAmount.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BalanceUtils } from '@kiltprotocol/sdk-js';
import { BalanceUtils } from '@kiltprotocol/chain-helpers';

import { render } from '../../testing/testing';

Expand Down
8 changes: 4 additions & 4 deletions src/components/PasswordField/PasswordField.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { KiltKeyringPair } from '@kiltprotocol/types';

import { FormEvent } from 'react';
import { userEvent } from '@testing-library/user-event';
import { KiltKeyringPair, Utils } from '@kiltprotocol/sdk-js';
import { Crypto } from '@kiltprotocol/utils';

import {
identitiesMock as identities,
Expand All @@ -22,9 +24,7 @@ import { useInterval } from '../../utilities/useInterval/useInterval';

import { PasswordField } from './PasswordField';

jest
.mocked(Utils.Crypto.makeKeypairFromSeed)
.mockReturnValue({} as KiltKeyringPair);
jest.mocked(Crypto.makeKeypairFromSeed).mockReturnValue({} as KiltKeyringPair);

jest.mock('../../channels/SavedPasswordsChannels/SavedPasswordsChannels');
jest.mock('../../utilities/identities/identities');
Expand Down
6 changes: 4 additions & 2 deletions src/components/PasswordField/PasswordField.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { KiltKeyringPair } from '@kiltprotocol/types';

import {
Dispatch,
FormEvent,
Expand All @@ -11,7 +13,7 @@ import {
} from 'react';
import { Link } from 'react-router-dom';
import browser from 'webextension-polyfill';
import { KiltKeyringPair, Utils } from '@kiltprotocol/sdk-js';
import { Crypto } from '@kiltprotocol/utils';

import * as styles from './PasswordField.module.css';

Expand Down Expand Up @@ -124,7 +126,7 @@ export function PasswordField({
await forgetPasswordChannel.get(address);
}

const keypair = Utils.Crypto.makeKeypairFromSeed(seed, 'sr25519');
const keypair = Crypto.makeKeypairFromSeed(seed, 'sr25519');
return { password, keypair, seed };
},
[address, rememberRef, savedPassword, t],
Expand Down
2 changes: 1 addition & 1 deletion src/components/UnknownIdentity/UnknownIdentity.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { KiltAddress } from '@kiltprotocol/sdk-js';
import type { KiltAddress } from '@kiltprotocol/types';

import browser from 'webextension-polyfill';

Expand Down