forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Describe the changes or additions included in this PR. ## Test Plan How did you test the new or updated feature? --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
- Loading branch information
1 parent
9d9c90f
commit 9ac7e2f
Showing
24 changed files
with
887 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@mysten/sui.js': patch | ||
'@mysten/zklogin': patch | ||
--- | ||
|
||
Add additional type exports to zklogin package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@mysten/enoki': patch | ||
--- | ||
|
||
Introduce Enoki SDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ packages: | |
- '!sdk/typescript/utils' | ||
- '!sdk/typescript/bcs' | ||
- '!sdk/typescript/zklogin' | ||
- '!sdk/enoki/react' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CHANGELOG.md | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# `@mysten/enoki` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"name": "@mysten/enoki", | ||
"version": "0.0.1", | ||
"description": "TODO: Description", | ||
"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" | ||
}, | ||
"./react": { | ||
"import": "./dist/esm/react.js", | ||
"require": "./dist/cjs/react.js" | ||
} | ||
}, | ||
"files": [ | ||
"CHANGELOG.md", | ||
"dist", | ||
"react", | ||
"src" | ||
], | ||
"scripts": { | ||
"clean": "rm -rf tsconfig.tsbuildinfo ./dist", | ||
"build": "build-package", | ||
"prepublishOnly": "pnpm build", | ||
"prettier:check": "prettier -c --ignore-unknown .", | ||
"prettier:fix": "prettier -w --ignore-unknown .", | ||
"eslint:check": "eslint --max-warnings=0 .", | ||
"eslint:fix": "pnpm run eslint:check --fix", | ||
"lint": "pnpm run eslint:check && pnpm run prettier:check", | ||
"lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/mystenlabs/sui.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/mystenlabs/sui/issues" | ||
}, | ||
"homepage": "https://github.com/mystenlabs/sui#readme", | ||
"devDependencies": { | ||
"@mysten/build-scripts": "workspace:*", | ||
"@types/node": "^20.4.2", | ||
"@types/react": "^18.2.15", | ||
"react": "^18.2.0", | ||
"tsx": "^3.12.7", | ||
"typescript": "^5.1.6" | ||
}, | ||
"dependencies": { | ||
"@metamask/browser-passworder": "^4.1.0", | ||
"@mysten/sui.js": "workspace:*", | ||
"@mysten/zklogin": "workspace:*", | ||
"@nanostores/react": "^0.7.1", | ||
"jose": "^4.14.4", | ||
"nanostores": "^0.9.3" | ||
}, | ||
"peerDependencies": { | ||
"@types/react": ">=17.0.0", | ||
"react": ">=17.0.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"react": { | ||
"optional": true | ||
}, | ||
"@types/react": { | ||
"optional": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"private": true, | ||
"import": "../dist/esm/react.js", | ||
"main": "../dist/cjs/react.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { | ||
CreateZkLoginNonceApiInput, | ||
CreateZkLoginNonceApiResponse, | ||
CreateZkLoginZkpApiInput, | ||
CreateZkLoginZkpApiResponse, | ||
GetAppApiInput, | ||
GetAppApiResponse, | ||
GetZkLoginApiInput, | ||
GetZkLoginApiResponse, | ||
} from './type.js'; | ||
|
||
const DEFAULT_API_URL = 'https://api.enoki.mystenlabs.com'; | ||
const ZKLOGIN_HEADER = 'zklogin-jwt'; | ||
|
||
export interface EnokiClientConfig { | ||
/** The API key for the Enoki app, available in the Enoki Portal. */ | ||
apiKey: string; | ||
|
||
/** The API URL for Enoki. In most cases, this should not be set. */ | ||
apiUrl?: string; | ||
} | ||
|
||
/** | ||
* A low-level client for interacting with the Enoki API. | ||
*/ | ||
export class EnokiClient { | ||
#version: string; | ||
#apiUrl: string; | ||
#apiKey: string; | ||
|
||
constructor(config: EnokiClientConfig) { | ||
this.#version = 'v1'; | ||
this.#apiUrl = config.apiUrl ?? DEFAULT_API_URL; | ||
this.#apiKey = config.apiKey; | ||
} | ||
|
||
getApp(_input?: GetAppApiInput) { | ||
return this.#fetch<GetAppApiResponse>('app', { | ||
method: 'GET', | ||
}); | ||
} | ||
|
||
getZkLogin(input: GetZkLoginApiInput) { | ||
return this.#fetch<GetZkLoginApiResponse>('zklogin', { | ||
method: 'GET', | ||
headers: { | ||
[ZKLOGIN_HEADER]: input.jwt, | ||
}, | ||
}); | ||
} | ||
|
||
createZkLoginNonce(input: CreateZkLoginNonceApiInput) { | ||
return this.#fetch<CreateZkLoginNonceApiResponse>('zklogin/nonce', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
ephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(), | ||
}), | ||
}); | ||
} | ||
|
||
createZkLoginZkp(input: CreateZkLoginZkpApiInput) { | ||
return this.#fetch<CreateZkLoginZkpApiResponse>('zklogin/kzp', { | ||
method: 'POST', | ||
headers: { | ||
[ZKLOGIN_HEADER]: input.jwt, | ||
}, | ||
body: JSON.stringify({ | ||
ephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(), | ||
maxEpoch: input.maxEpoch, | ||
randomness: input.randomness, | ||
}), | ||
}); | ||
} | ||
|
||
async #fetch<T = unknown>(path: string, init: RequestInit): Promise<T> { | ||
const res = await fetch(`${this.#apiUrl}/${this.#version}/${path}`, { | ||
...init, | ||
headers: { | ||
...init.headers, | ||
Authorization: `Bearer ${this.#apiKey}`, | ||
'Content-Type': 'application/json', | ||
'Request-Id': crypto.randomUUID(), | ||
}, | ||
}); | ||
|
||
if (!res.ok) { | ||
throw new Error('Failed to fetch'); | ||
} | ||
|
||
const { data } = await res.json(); | ||
|
||
return data as T; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { PublicKey } from '@mysten/sui.js/cryptography'; | ||
import type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin'; | ||
|
||
import type { AuthProvider } from '../EnokiFlow.js'; | ||
|
||
export interface GetAppApiInput {} | ||
export interface GetAppApiResponse { | ||
authenticationProviders: { | ||
providerType: AuthProvider; | ||
clientId: string; | ||
}[]; | ||
} | ||
|
||
export interface GetZkLoginApiInput { | ||
jwt: string; | ||
} | ||
export interface GetZkLoginApiResponse { | ||
address: string; | ||
salt: string; | ||
} | ||
|
||
export interface CreateZkLoginNonceApiInput { | ||
ephemeralPublicKey: PublicKey; | ||
} | ||
export interface CreateZkLoginNonceApiResponse { | ||
nonce: string; | ||
randomness: string; | ||
epoch: number; | ||
maxEpoch: number; | ||
estimatedExpiration: number; | ||
} | ||
|
||
export interface CreateZkLoginZkpApiInput { | ||
jwt: string; | ||
ephemeralPublicKey: PublicKey; | ||
randomness: string; | ||
maxEpoch: number; | ||
} | ||
export interface CreateZkLoginZkpApiResponse extends ZkLoginSignatureInputs {} |
Oops, something went wrong.