Skip to content

Commit 73f455f

Browse files
authored
chore(generated-clients): ID-3843: Added Magic TEE generated client (#2660)
1 parent 4164e99 commit 73f455f

29 files changed

+1567
-0
lines changed

packages/internal/generated-clients/Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,28 @@ generate-blockchain-data-types:
8080
-o /app/src/blockchain-data \
8181
-c /app/config/blockchain-data.config.json \
8282
--additional-properties=stringEnums=true
83+
84+
# -------------------------------------------------
85+
# Magic TEE
86+
# -------------------------------------------------
87+
88+
.PHONY: generate-magic-tee-openapi
89+
generate-magic-tee-openapi: get-magic-tee-openapi generate-magic-tee-client
90+
91+
.PHONY: get-magic-tee-openapi
92+
get-magic-tee-openapi:
93+
rm -f src/magic-tee-openapi.json && touch src/magic-tee-openapi.json && \
94+
curl -H "Accept: application/json+v3" \
95+
https://tee.express.magiclabs.com/openapi.json \
96+
-o src/magic-tee-openapi.json
97+
98+
.PHONY: generate-magic-tee-client
99+
generate-magic-tee-client:
100+
pnpm rimraf src/magic-tee && \
101+
mkdir src/magic-tee && \
102+
docker run --rm -v $(shell pwd):/app openapitools/openapi-generator-cli:v7.0.1 generate \
103+
--inline-schema-options REFACTOR_ALLOF_INLINE_SCHEMAS=true \
104+
-i ./app/src/magic-tee-openapi.json \
105+
-g typescript-axios \
106+
-o /app/src/magic-tee \
107+
-c /app/config/magic-tee.config.json
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"supportsES6": true,
3+
"npmVersion": "6.9.0",
4+
"typescriptThreePlus": true,
5+
"withSeparateModelsAndApi": true,
6+
"modelPackage": "models",
7+
"apiPackage": "domain",
8+
"useSingleRequestParameter": true
9+
}

packages/internal/generated-clients/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * as mr from './multi-rollup';
33
export * as BlockchainData from './blockchain-data/index';
44
export { ImxApiClients } from './imx-api-clients';
55
export { MultiRollupApiClients } from './mr-api-clients';
6+
export { MagicTeeApiClients } from './magic-tee-api-clients';
67
export {
78
imxApiConfig,
89
multiRollupConfig, createConfig,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import axios from 'axios';
2+
import { TransactionApi, WalletApi } from './magic-tee';
3+
4+
export type MagicTeeApiClientsConfig = {
5+
basePath: string;
6+
timeout: number;
7+
magicPublishableApiKey: string;
8+
magicProviderId: string;
9+
};
10+
11+
export class MagicTeeApiClients {
12+
public transactionApi: TransactionApi;
13+
14+
public walletApi: WalletApi;
15+
16+
constructor(config: MagicTeeApiClientsConfig) {
17+
const instance = axios.create({
18+
timeout: config.timeout,
19+
headers: {
20+
'Content-Type': 'application/json',
21+
'X-Magic-API-Key': config.magicPublishableApiKey,
22+
'X-OIDC-Provider-ID': config.magicProviderId,
23+
},
24+
});
25+
26+
this.transactionApi = new TransactionApi(undefined, config.basePath, instance);
27+
this.walletApi = new WalletApi(undefined, config.basePath, instance);
28+
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"openapi":"3.1.0","info":{"title":"TEE Express","description":"\nTEE Express is a service that simplifies wallet management for developers. Unlike traditional wallet solutions that require complex key management, TEE Express handles all key management internally, providing a streamlined API for wallet operations.\nTEE Express leverages secure enclave technology to ensure that private keys never leave the secure environment. All wallet operations, including creation, signing, and key management, are performed within a trusted execution environment (TEE). This provides enterprise-grade security while maintaining the simplicity of a REST API.\n\nThe service supports Ethereum wallets and provides endpoints for wallet creation, transaction signing, and message signing. All operations are authenticated using JWT tokens passed in the Authorization header, ensuring secure access to user wallets.\n\n**Migration Notice:**\nIf you're an existing customer, your users' wallets have been automatically migrated to TEE Express. There's no action required on your part - all existing wallets are now accessible through the TEE Express API using the same JWT tokens you currently use for authentication.\n\nSimply update your API calls to use the TEE Express endpoints, and pass your existing JWT token in the Authorization header for all requests.\n\n**Authentication:**\n- An API key via the `X-Magic-API-Key` header or a secret key via the `X-Magic-Secret-Key` header.\n- The OIDC provider ID via the `X-OIDC-Provider-ID` header.\n- Bearer token in the `Authorization` header.\n\n**Data Hashing for Signing:**\n\nFor personal sign operations, encode your data as base64:\n\n```typescript\nconst message = Buffer.from(data, 'utf-8').toString('base64');\n```\n\nFor signing transaction data or other structured data, provide a keccak256 hash:\n\n```typescript\nimport {\n MessageTypes,\n SignTypedDataVersion,\n TypedDataUtils,\n TypedDataV1,\n TypedMessage,\n typedSignatureHash,\n} from '@metamask/eth-sig-util';\nimport { resolveProperties, Signature, Transaction, TransactionLike, TransactionRequest } from 'ethers';\n\nconst computeEip712Hash = (\n data: TypedMessage<MessageTypes>,\n version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4,\n): string => {\n const hashBuffer = TypedDataUtils.eip712Hash(data, version);\n return '0x' + hashBuffer.toString('hex');\n};\n\nconst personalSign = async (data: string) => {\n const message = Buffer.from(data, 'utf-8').toString('base64');\n const body = { message_base64: message, chain: 'ETH' };\n return await fetch('/v1/wallet/personal-sign', { method: 'POST', body: JSON.stringify(body) });\n};\n\nconst signTypedDataV1 = async (data: TypedDataV1) => {\n const rawDataHash = typedSignatureHash(data);\n const body = { raw_data_hash: rawDataHash, chain: 'ETH' };\n return await fetch('/v1/wallet/sign', { method: 'POST', body: JSON.stringify(body) });\n};\n\nconst signTypedDataV3 = async (data: TypedMessage<MessageTypes>) => {\n const rawDataHash = computeEip712Hash(data, SignTypedDataVersion.V3);\n const body = { raw_data_hash: rawDataHash, chain: 'ETH' };\n return await fetch('/v1/wallet/sign', { method: 'POST', body: JSON.stringify(body) });\n};\n\nconst signTypedDataV4 = async (data: TypedMessage<MessageTypes>) => {\n const rawDataHash = computeEip712Hash(data, SignTypedDataVersion.V4);\n const body = { raw_data_hash: rawDataHash, chain: 'ETH' };\n return await fetch('/v1/wallet/sign', { method: 'POST', body: JSON.stringify(body) });\n};\n\nconst signTransaction = async (tx: TransactionRequest) => {\n const resolvedTx = await resolveProperties(tx);\n const txForSigning = { ...resolvedTx };\n delete txForSigning.from;\n\n const btx = Transaction.from(txForSigning as TransactionLike);\n\n const body = { raw_data_hash: btx.unsignedHash, chain: 'ETH' };\n const res = await fetch('/v1/wallet/sign', { method: 'POST', body: JSON.stringify(body) });\n const { r, s, v } = res.json();\n btx.signature = Signature.from({ r, s, v });\n return btx.serialized;\n};\n```\n","version":"0.1.0"},"paths":{"/v1/wallet/personal-sign":{"post":{"tags":["Transaction"],"summary":"Sign a message with the wallet.","description":"Signs an arbitrary message using the wallet's private key. Useful for authentication and off-chain verification.\n\n**Example cURL:**\n```bash\ncurl -X POST 'https://tee.express.magiclabs.com/v1/wallet/personal-sign' \\\n -H 'Content-Type: application/json' \\\n -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNhYVl5dGR3d2UwMzJzMXIzVElyOSJ9...' \\\n -H 'X-Magic-API-Key: your-magic-api-key' \\\n -H 'X-OIDC-Provider-ID: your-oidc-provider-id' \\\n -d '{\n \"chain\": \"ETH\",\n \"message_base64\": \"bm9uZQ==\"\n }'\n```\n\n**Example Response:**\n```json\n{\n \"signature\": \"0x0cebb670d8375ac74122b46c44def7e1ce593e80434a3e6557108ae124f8b44f3c5068fc104279fe7f51918cbe4c249d707bc1c0ce2ffb6d201d3cf4e2fdee8d1b\",\n \"r\": \"0x0cebb670d8375ac74122b46c44def7e1ce593e80434a3e6557108ae124f8b44f\",\n \"s\": \"0x3c5068fc104279fe7f51918cbe4c249d707bc1c0ce2ffb6d201d3cf4e2fdee8d\",\n \"v\": \"27\"\n}\n```","operationId":"sign_message_v1_wallet_personal_sign_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"X-Magic-API-Key","in":"header","required":false,"schema":{"type":"string","title":"X-Magic-Api-Key"}},{"name":"X-Magic-Secret-Key","in":"header","required":false,"schema":{"type":"string","title":"X-Magic-Secret-Key"}},{"name":"X-OIDC-Provider-ID","in":"header","required":false,"schema":{"type":"string","title":"X-Oidc-Provider-Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/PersonalSignRequest"},{"type":"array","items":{"$ref":"#/components/schemas/PersonalSignRequest"}}],"title":"Item"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/PersonalSignResponse"},{"type":"array","items":{"$ref":"#/components/schemas/PersonalSignResponse"}}],"title":"Response Sign Message V1 Wallet Personal Sign Post"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/v1/wallet/sign":{"post":{"tags":["Transaction"],"summary":"Sign arbitrary data with the wallet.","description":"Signs a hash of arbitrary data using the wallet's private key.\n\n**Example cURL:**\n```bash\ncurl -X POST 'https://tee.express.magiclabs.com/v1/wallet/sign' \\\n -H 'Content-Type: application/json' \\\n -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNhYVl5dGR3d2UwMzJzMXIzVElyOSJ9...' \\\n -H 'X-Magic-API-Key: your-magic-api-key' \\\n -H 'X-OIDC-Provider-ID: your-oidc-provider-id' \\\n -d '{\n \"chain\": \"ETH\",\n \"raw_data_hash\": \"0xabc123def4567890abc123def4567890abc123def4567890abc123def4567890\"\n }'\n```\n\n**Example Response:**\n```json\n{\n \"message_hash\": \"0xabc123def4567890abc123def4567890abc123def4567890abc123def4567890\",\n \"signature\": \"0x8e7d6c5b4a3928172635445566778899aabbccddeeff00112233445566778899\",\n \"r\": \"0x3d4e5f678901234567890abcdef1234567890abcdef1234567890abcdef1234\",\n \"s\": \"0x4e5f678901234567890abcdef1234567890abcdef1234567890abcdef123456\",\n \"v\": \"27\"\n}\n```","operationId":"sign_data_v1_wallet_sign_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"X-Magic-API-Key","in":"header","required":false,"schema":{"type":"string","title":"X-Magic-Api-Key"}},{"name":"X-Magic-Secret-Key","in":"header","required":false,"schema":{"type":"string","title":"X-Magic-Secret-Key"}},{"name":"X-OIDC-Provider-ID","in":"header","required":false,"schema":{"type":"string","title":"X-Oidc-Provider-Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SignDataRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SignDataResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/v1/wallet":{"get":{"tags":["Wallet"],"summary":"Get wallet details.","description":"Returns the wallet's public address for the given chain.\n\n**Example cURL:**\n```bash\ncurl -X GET 'https://tee.express.magiclabs.com/v1/wallet?chain=ETH' \\\n -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNhYVl5dGR3d2UwMzJzMXIzVElyOSJ9...' \\\n -H 'X-Magic-API-Key: your-magic-api-key' \\\n -H 'X-OIDC-Provider-ID: your-oidc-provider-id'\n```\n\n**Example Response:**\n```json\n{\n \"public_address\": \"0x6b422EefBFBc47a6900A1fc5454Ef4b940B7e36e\"\n}\n```","operationId":"get_wallet_v1_wallet_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"chain","in":"query","required":true,"schema":{"$ref":"#/components/schemas/Chain"}},{"name":"X-Magic-API-Key","in":"header","required":false,"schema":{"type":"string","title":"X-Magic-Api-Key"}},{"name":"X-Magic-Secret-Key","in":"header","required":false,"schema":{"type":"string","title":"X-Magic-Secret-Key"}},{"name":"X-OIDC-Provider-ID","in":"header","required":false,"schema":{"type":"string","title":"X-Oidc-Provider-Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/WalletResponseModel"},{"type":"null"}],"title":"Response Get Wallet V1 Wallet Get"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"post":{"tags":["Wallet"],"summary":"Create a new wallet.","description":"Creates a new wallet for the given chain and returns its public address.\n\n**Example cURL:**\n```bash\ncurl -X POST 'https://tee.express.magiclabs.com/v1/wallet' \\\n -H 'Content-Type: application/json' \\\n -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNhYVl5dGR3d2UwMzJzMXIzVElyOSJ9...' \\\n -H 'X-Magic-API-Key: your-magic-api-key' \\\n -H 'X-OIDC-Provider-ID: your-oidc-provider-id' \\\n -d '{\n \"chain\": \"ETH\"\n }'\n```\n\n**Example Response:**\n```json\n{\n \"public_address\": \"0x6b422EefBFBc47a6900A1fc5454Ef4b940B7e36e\"\n}\n```","operationId":"create_wallet_v1_wallet_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"X-Magic-API-Key","in":"header","required":false,"schema":{"type":"string","title":"X-Magic-Api-Key"}},{"name":"X-Magic-Secret-Key","in":"header","required":false,"schema":{"type":"string","title":"X-Magic-Secret-Key"}},{"name":"X-OIDC-Provider-ID","in":"header","required":false,"schema":{"type":"string","title":"X-Oidc-Provider-Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateWalletRequestModel"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WalletResponseModel"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"Chain":{"type":"string","enum":["ETH"],"title":"Chain"},"CreateWalletRequestModel":{"properties":{"chain":{"$ref":"#/components/schemas/Chain"}},"type":"object","required":["chain"],"title":"CreateWalletRequestModel"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"PersonalSignRequest":{"properties":{"chain":{"$ref":"#/components/schemas/Chain"},"message_base64":{"type":"string","title":"Message Base64"}},"type":"object","required":["chain","message_base64"],"title":"PersonalSignRequest"},"PersonalSignResponse":{"properties":{"signature":{"type":"string","title":"Signature"},"r":{"type":"string","title":"R"},"s":{"type":"string","title":"S"},"v":{"type":"string","title":"V"}},"type":"object","required":["signature","r","s","v"],"title":"PersonalSignResponse"},"SignDataRequest":{"properties":{"chain":{"$ref":"#/components/schemas/Chain"},"raw_data_hash":{"type":"string","title":"Raw Data Hash"}},"type":"object","required":["chain","raw_data_hash"],"title":"SignDataRequest"},"SignDataResponse":{"properties":{"message_hash":{"type":"string","title":"Message Hash"},"signature":{"type":"string","title":"Signature"},"r":{"type":"string","title":"R"},"s":{"type":"string","title":"S"},"v":{"type":"string","title":"V"}},"type":"object","required":["message_hash","signature","r","s","v"],"title":"SignDataResponse"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"},"WalletResponseModel":{"properties":{"public_address":{"type":"string","title":"Public Address"}},"type":"object","required":["public_address"],"title":"WalletResponseModel"}},"securitySchemes":{"HTTPBearer":{"type":"http","scheme":"bearer"}}}}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
wwwroot/*.js
2+
node_modules
3+
typings
4+
dist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.gitignore
2+
.npmignore
3+
.openapi-generator-ignore
4+
api.ts
5+
base.ts
6+
common.ts
7+
configuration.ts
8+
domain/transaction-api.ts
9+
domain/wallet-api.ts
10+
git_push.sh
11+
index.ts
12+
models/chain.ts
13+
models/create-wallet-request-model.ts
14+
models/httpvalidation-error.ts
15+
models/index.ts
16+
models/personal-sign-request.ts
17+
models/personal-sign-response.ts
18+
models/sign-data-request.ts
19+
models/sign-data-response.ts
20+
models/validation-error-loc-inner.ts
21+
models/validation-error.ts
22+
models/wallet-response-model.ts
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.0.1

0 commit comments

Comments
 (0)