Skip to content

Commit

Permalink
Move to @mysten/kms, export aws inside that
Browse files Browse the repository at this point in the history
  • Loading branch information
manolisliolios committed Oct 30, 2024
1 parent 29d38ff commit a350c91
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 24 deletions.
1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ packages:
- '!sdk/typescript/keypairs/secp256r1'
- '!sdk/typescript/graphql/schemas/2024.1'
- '!sdk/typescript/graphql/schemas/2024.4'
- '!sdk/kms/aws'
3 changes: 0 additions & 3 deletions sdk/aws-kms-signer/README.md

This file was deleted.

File renamed without changes.
21 changes: 21 additions & 0 deletions sdk/kms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Sui KMS Signers

This package is the source for finding exported KMS signers.

## AWS KMS Signer

You can use AWS KMS signer like the following:

```typescript
import { AwsKmsSigner } from "@mysten/kms/aws";

const prepareSigner = async () => {
const { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_KMS_KEY_ID } = process.env;

return AwsKmsSigner.fromCredentials(AWS_KMS_KEY_ID, {
region: AWS_REGION,
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
});
}
```
6 changes: 6 additions & 0 deletions sdk/kms/aws/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"import": "../dist/esm/aws/index.js",
"main": "../dist/cjs/aws/index.js",
"sideEffects": false
}
19 changes: 10 additions & 9 deletions sdk/aws-kms-signer/package.json → sdk/kms/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"name": "@mysten/aws-kms-signer",
"name": "@mysten/kms",
"version": "0.0.1",
"description": "TODO: Write Description",
"description": "A collection of KMS signers for various cloud providers",
"license": "Apache-2.0",
"author": "Mysten Labs <[email protected]>",
"type": "commonjs",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/cjs/index.d.ts",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
"./aws": {
"import": "./dist/esm/aws/index.js",
"require": "./dist/cjs/aws/index.js"
}
},
"sideEffects": false,
"files": [
"CHANGELOG.md",
"dist"
"LICENSE",
"README.md",
"aws",
"dist",
"src"
],
"scripts": {
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface AwsKmsSignerOptions {
}

/**
* AWSKMSSigner integrates AWS Key Management Service (KMS) with the Sui blockchain
* Aws KMS Signer integrates AWS Key Management Service (KMS) with the Sui blockchain
* to provide signing capabilities using AWS-managed cryptographic keys.
*/
export class AwsKmsSigner extends Signer {
Expand All @@ -34,24 +34,24 @@ export class AwsKmsSigner extends Signer {
#kmsKeyId: string;

/**
* Creates an instance of AwsKmsSigner. It's recommened to call `fromAwsCredentials` method to create an instance.
* @param options - Configuration options for AWS KMS.
* Creates an instance of AwsKmsSigner. It's expected to call the static `fromCredentials` method to create an instance.
* For example:
* ```
* const signer = await AwsKmsSigner.fromCredentials(keyId, options);
* ```
* @throws Will throw an error if required AWS credentials or region are not provided.
*/
constructor({ kmsKeyId, client, publicKey }: AwsKmsSignerOptions) {
super();
this.#client = client;

if (!kmsKeyId) {
throw new Error('KMS Key ID is required');
}
if (!kmsKeyId) throw new Error('KMS Key ID is required');

this.#client = client;
this.#kmsKeyId = kmsKeyId;
this.#publicKey = publicKey;
}

/**
* Retrieves the key scheme used by this signer.
* Retrieves the key scheme used by this signer. Errors if the public key is not initialized.
* @returns The string 'Secp256k1' indicating the key scheme.
*/
getKeyScheme() {
Expand Down Expand Up @@ -133,7 +133,7 @@ export class AwsKmsSigner extends Signer {
* It is recommended to initialize an `AwsKmsSigner` instance using this function.
* @returns A promise that resolves once a `AwsKmsSigner` instance is prepared (public key is set).
*/
static async fromAwsCredentials(keyId: string, options: AwsClientOptions) {
static async fromCredentials(keyId: string, options: AwsClientOptions) {
const client = new AwsKmsClient(options);

const pubKey = await client.getPublicKey(keyId);
Expand Down
9 changes: 9 additions & 0 deletions sdk/kms/src/aws/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import type { AwsClientOptions } from './aws-client.js';
import type { AwsKmsSignerOptions } from './aws-kms-signer.js';
import { AwsKmsSigner } from './aws-kms-signer.js';

export { AwsKmsSigner };

export type { AwsKmsSignerOptions, AwsClientOptions };
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { beforeAll, describe, expect, it } from 'vitest';

import { AwsKmsSigner } from '../src/index';
import { AwsKmsSigner } from '../src/aws/aws-kms-signer';

describe('Aws KMS signer E2E testing', () => {
let signer: AwsKmsSigner;
Expand All @@ -13,7 +13,7 @@ describe('Aws KMS signer E2E testing', () => {
throw new Error('Missing one or more required environment variables.');
}

signer = await AwsKmsSigner.fromAwsCredentials(AWS_KMS_KEY_ID, {
signer = await AwsKmsSigner.fromCredentials(AWS_KMS_KEY_ID, {
region: AWS_REGION,
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a350c91

Please sign in to comment.