From a323af881651ce89adbe0eb7b4d1de892d5afd2c Mon Sep 17 00:00:00 2001 From: samuel Date: Thu, 29 Aug 2024 11:17:22 +0200 Subject: [PATCH 1/4] Make only use of armory sdk inside entity manager --- .../_components/EntityManager.tsx | 6 +-- .../_components/cards/AccountCard.tsx | 2 +- .../_components/cards/CredentialCard.tsx | 2 +- .../_components/cards/UserCard.tsx | 2 +- .../dialogs/DeriveAccountDialog.tsx | 3 +- .../dialogs/GenerateWalletDialog.tsx | 11 ++++- .../_components/dialogs/ImportKeyDialog.tsx | 4 +- .../_components/forms/AccountForm.tsx | 2 +- .../_components/forms/AssignAccountForm.tsx | 2 +- .../_components/forms/CredentialForm.tsx | 12 +++++- .../_components/forms/UserForm.tsx | 13 +++++- packages/armory-sdk/src/index.ts | 42 ++++++++++++------- 12 files changed, 66 insertions(+), 35 deletions(-) diff --git a/apps/devtool/src/app/entity-manager/_components/EntityManager.tsx b/apps/devtool/src/app/entity-manager/_components/EntityManager.tsx index 413382db9..f8d72310b 100644 --- a/apps/devtool/src/app/entity-manager/_components/EntityManager.tsx +++ b/apps/devtool/src/app/entity-manager/_components/EntityManager.tsx @@ -21,9 +21,9 @@ import { Entities, EntityUtil, UserAccountEntity, - UserEntity -} from '@narval/policy-engine-shared' -import { hash } from '@narval/signature' + UserEntity, + hash +} from '@narval/armory-sdk' import { useEffect, useState } from 'react' import { z } from 'zod' import CodeEditor from '../../_components/CodeEditor' diff --git a/apps/devtool/src/app/entity-manager/_components/cards/AccountCard.tsx b/apps/devtool/src/app/entity-manager/_components/cards/AccountCard.tsx index b5883a9d4..c566b36ae 100644 --- a/apps/devtool/src/app/entity-manager/_components/cards/AccountCard.tsx +++ b/apps/devtool/src/app/entity-manager/_components/cards/AccountCard.tsx @@ -1,5 +1,5 @@ import { faTrash, faUnlink } from '@fortawesome/free-solid-svg-icons' -import { AccountEntity } from '@narval/policy-engine-shared' +import { AccountEntity } from '@narval/armory-sdk' import NarIconButtonWithTooltip from '../../../_design-system/NarIconButtonWithTooltip' interface AccountCardProps { diff --git a/apps/devtool/src/app/entity-manager/_components/cards/CredentialCard.tsx b/apps/devtool/src/app/entity-manager/_components/cards/CredentialCard.tsx index e630bba99..93c596a45 100644 --- a/apps/devtool/src/app/entity-manager/_components/cards/CredentialCard.tsx +++ b/apps/devtool/src/app/entity-manager/_components/cards/CredentialCard.tsx @@ -1,5 +1,5 @@ import { faTrash } from '@fortawesome/free-solid-svg-icons' -import { CredentialEntity } from '@narval/policy-engine-shared' +import { CredentialEntity } from '@narval/armory-sdk' import NarIconButtonWithTooltip from '../../../_design-system/NarIconButtonWithTooltip' interface CredentialCardProps { diff --git a/apps/devtool/src/app/entity-manager/_components/cards/UserCard.tsx b/apps/devtool/src/app/entity-manager/_components/cards/UserCard.tsx index efce25676..472ddc3c1 100644 --- a/apps/devtool/src/app/entity-manager/_components/cards/UserCard.tsx +++ b/apps/devtool/src/app/entity-manager/_components/cards/UserCard.tsx @@ -6,7 +6,7 @@ import { faTrash, faWallet } from '@fortawesome/free-solid-svg-icons' -import { UserEntity } from '@narval/policy-engine-shared' +import { UserEntity } from '@narval/armory-sdk' import * as Collapsible from '@radix-ui/react-collapsible' import { capitalize } from 'lodash/fp' import { useState } from 'react' diff --git a/apps/devtool/src/app/entity-manager/_components/dialogs/DeriveAccountDialog.tsx b/apps/devtool/src/app/entity-manager/_components/dialogs/DeriveAccountDialog.tsx index 6a3adefbd..7002588ae 100644 --- a/apps/devtool/src/app/entity-manager/_components/dialogs/DeriveAccountDialog.tsx +++ b/apps/devtool/src/app/entity-manager/_components/dialogs/DeriveAccountDialog.tsx @@ -1,8 +1,7 @@ 'use client' import { faXmarkCircle } from '@fortawesome/free-solid-svg-icons' -import { Permission } from '@narval/armory-sdk' -import { AccountType, Action, Entities, EntityUtil, hexSchema } from '@narval/policy-engine-shared' +import { AccountType, Action, Entities, EntityUtil, Permission, hexSchema } from '@narval/armory-sdk' import { parseInt } from 'lodash' import { Dispatch, FC, SetStateAction, useState } from 'react' import { v4 as uuid } from 'uuid' diff --git a/apps/devtool/src/app/entity-manager/_components/dialogs/GenerateWalletDialog.tsx b/apps/devtool/src/app/entity-manager/_components/dialogs/GenerateWalletDialog.tsx index fdb2ea693..5601bba92 100644 --- a/apps/devtool/src/app/entity-manager/_components/dialogs/GenerateWalletDialog.tsx +++ b/apps/devtool/src/app/entity-manager/_components/dialogs/GenerateWalletDialog.tsx @@ -2,8 +2,15 @@ import { faCheckCircle, faWallet, faXmarkCircle } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { GenerateKeyResponse, Permission } from '@narval/armory-sdk' -import { AccountType, Action, Entities, EntityUtil, hexSchema } from '@narval/policy-engine-shared' +import { + AccountType, + Action, + Entities, + EntityUtil, + GenerateKeyResponse, + Permission, + hexSchema +} from '@narval/armory-sdk' import { Dispatch, FC, SetStateAction, useMemo, useState } from 'react' import { v4 as uuid } from 'uuid' import ValueWithCopy from '../../../_components/ValueWithCopy' diff --git a/apps/devtool/src/app/entity-manager/_components/dialogs/ImportKeyDialog.tsx b/apps/devtool/src/app/entity-manager/_components/dialogs/ImportKeyDialog.tsx index c09b94c1a..b569f4473 100644 --- a/apps/devtool/src/app/entity-manager/_components/dialogs/ImportKeyDialog.tsx +++ b/apps/devtool/src/app/entity-manager/_components/dialogs/ImportKeyDialog.tsx @@ -1,9 +1,7 @@ 'use client' import { faXmarkCircle } from '@fortawesome/free-solid-svg-icons' -import { Permission } from '@narval/armory-sdk' -import { AccountEntity, AccountType, Action, Entities, getAddress } from '@narval/policy-engine-shared' -import { Hex } from '@narval/signature' +import { AccountEntity, AccountType, Action, Entities, Hex, Permission, getAddress } from '@narval/armory-sdk' import { Dispatch, SetStateAction, useState } from 'react' import { v4 as uuid } from 'uuid' import NarButton from '../../../_design-system/NarButton' diff --git a/apps/devtool/src/app/entity-manager/_components/forms/AccountForm.tsx b/apps/devtool/src/app/entity-manager/_components/forms/AccountForm.tsx index 7558af71f..6a20ba161 100644 --- a/apps/devtool/src/app/entity-manager/_components/forms/AccountForm.tsx +++ b/apps/devtool/src/app/entity-manager/_components/forms/AccountForm.tsx @@ -1,6 +1,6 @@ 'use client' -import { AccountEntity, AccountType, getAddress, isAddress } from '@narval/policy-engine-shared' +import { AccountEntity, AccountType, getAddress, isAddress } from '@narval/armory-sdk' import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react' import NarInput from '../../../_design-system/NarInput' diff --git a/apps/devtool/src/app/entity-manager/_components/forms/AssignAccountForm.tsx b/apps/devtool/src/app/entity-manager/_components/forms/AssignAccountForm.tsx index 77492eab1..afe02d07a 100644 --- a/apps/devtool/src/app/entity-manager/_components/forms/AssignAccountForm.tsx +++ b/apps/devtool/src/app/entity-manager/_components/forms/AssignAccountForm.tsx @@ -1,4 +1,4 @@ -import { AccountEntity, UserAccountEntity, UserEntity } from '@narval/policy-engine-shared' +import { AccountEntity, UserAccountEntity, UserEntity } from '@narval/armory-sdk' import { Dispatch, FC, SetStateAction, useCallback } from 'react' import MultiSelectList from '../MultiselectList' diff --git a/apps/devtool/src/app/entity-manager/_components/forms/CredentialForm.tsx b/apps/devtool/src/app/entity-manager/_components/forms/CredentialForm.tsx index 69a1f99dc..e21064475 100644 --- a/apps/devtool/src/app/entity-manager/_components/forms/CredentialForm.tsx +++ b/apps/devtool/src/app/entity-manager/_components/forms/CredentialForm.tsx @@ -1,5 +1,13 @@ -import { CredentialEntity, UserEntity, isAddress } from '@narval/policy-engine-shared' -import { Curves, KeyTypes, SigningAlg, jwkEoaSchema, publicKeySchema } from '@narval/signature' +import { + CredentialEntity, + Curves, + KeyTypes, + SigningAlg, + UserEntity, + isAddress, + jwkEoaSchema, + publicKeySchema +} from '@narval/armory-sdk' import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react' import NarButton from '../../../_design-system/NarButton' import NarInput from '../../../_design-system/NarInput' diff --git a/apps/devtool/src/app/entity-manager/_components/forms/UserForm.tsx b/apps/devtool/src/app/entity-manager/_components/forms/UserForm.tsx index daf69dc81..216e30450 100644 --- a/apps/devtool/src/app/entity-manager/_components/forms/UserForm.tsx +++ b/apps/devtool/src/app/entity-manager/_components/forms/UserForm.tsx @@ -1,7 +1,16 @@ import { faChevronDown } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { CredentialEntity, UserEntity, UserRole, isAddress } from '@narval/policy-engine-shared' -import { Curves, KeyTypes, SigningAlg, jwkEoaSchema, publicKeySchema } from '@narval/signature' +import { + CredentialEntity, + Curves, + KeyTypes, + SigningAlg, + UserEntity, + UserRole, + isAddress, + jwkEoaSchema, + publicKeySchema +} from '@narval/armory-sdk' import { capitalize } from 'lodash' import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react' import { v4 as uuid } from 'uuid' diff --git a/packages/armory-sdk/src/index.ts b/packages/armory-sdk/src/index.ts index 1d336254e..b7b868fda 100644 --- a/packages/armory-sdk/src/index.ts +++ b/packages/armory-sdk/src/index.ts @@ -9,9 +9,12 @@ export * from './lib/vault' export { resourceId } from './lib/utils' -export type { Alg, PrivateKey, PublicKey, RsaPublicKey, SigningAlg } from '@narval/signature' +export type { Alg, PrivateKey, PublicKey, RsaPublicKey } from '@narval/signature' export { + Curves, + KeyTypes, + SigningAlg, base64UrlToHex, buildSignerEip191, buildSignerForAlg, @@ -19,37 +22,44 @@ export { getPublicKey, hash, hexToBase64Url, + jwkEoaSchema, jwkSchema, privateKeyToJwk, + publicKeySchema, publicKeyToJwk, signJwt } from '@narval/signature' -export { +export type { AccessToken, - AccountType, - Action, + AccountEntity, + Address, CreateAuthorizationRequest, + CredentialEntity, Criterion, Decision, Eip712TypedData, + Entities, EntityType, + Hex, JwtString, + Policy, + PolicyCriterion, Request, Then, TransactionRequest, - UserRole, - ValueOperators + UserAccountEntity, + UserEntity, + ValueOperators, } from '@narval/policy-engine-shared' -export type { - AccountEntity, - Address, - Entities, - Hex, - Policy, - PolicyCriterion, - UserEntity +export { + AccountType, + Action, + EntityUtil, + UserRole, + getAddress, + hexSchema, + isAddress, + toHex } from '@narval/policy-engine-shared' - -export { EntityUtil, getAddress, toHex } from '@narval/policy-engine-shared' From 84928adeddd4f31b2c74c062bcb7d98b4766b86c Mon Sep 17 00:00:00 2001 From: samuel Date: Thu, 29 Aug 2024 11:39:19 +0200 Subject: [PATCH 2/4] update sdk version --- package-lock.json | 2 +- packages/armory-sdk/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3248b8e5c..ba05d7f58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46904,7 +46904,7 @@ }, "packages/armory-sdk": { "name": "@narval-xyz/armory-sdk", - "version": "0.8.1", + "version": "0.8.2", "license": "MPL-2.0", "dependencies": { "@noble/curves": "1.5.0", diff --git a/packages/armory-sdk/package.json b/packages/armory-sdk/package.json index 129177bf3..6006be2f5 100644 --- a/packages/armory-sdk/package.json +++ b/packages/armory-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@narval-xyz/armory-sdk", - "version": "0.8.1", + "version": "0.8.2", "license": "MPL-2.0", "publishConfig": { "access": "public" From 905fd96f706339bd0936068f8400a480802ef167 Mon Sep 17 00:00:00 2001 From: samuel Date: Thu, 29 Aug 2024 16:40:37 +0200 Subject: [PATCH 3/4] add sdk hooks import --- .../devtool/src/app/_hooks/useAccountSignature.tsx | 2 +- apps/devtool/src/app/_hooks/useAuthServerApi.tsx | 4 ++-- apps/devtool/src/app/_hooks/useDataStoreApi.tsx | 9 +++++---- apps/devtool/src/app/_hooks/useEngineApi.tsx | 4 ++-- apps/devtool/src/app/_hooks/useVaultApi.tsx | 14 +++++++++----- packages/armory-sdk/src/index.ts | 11 +++++++++-- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/apps/devtool/src/app/_hooks/useAccountSignature.tsx b/apps/devtool/src/app/_hooks/useAccountSignature.tsx index 927041b0d..7c45f5349 100644 --- a/apps/devtool/src/app/_hooks/useAccountSignature.tsx +++ b/apps/devtool/src/app/_hooks/useAccountSignature.tsx @@ -1,4 +1,4 @@ -import { Curves, KeyTypes, PublicKey, SigningAlg, hexToBase64Url } from '@narval/signature' +import { Curves, KeyTypes, PublicKey, SigningAlg, hexToBase64Url } from '@narval/armory-sdk' import { signMessage } from '@wagmi/core' import { useEffect, useState } from 'react' import { useAccount } from 'wagmi' diff --git a/apps/devtool/src/app/_hooks/useAuthServerApi.tsx b/apps/devtool/src/app/_hooks/useAuthServerApi.tsx index 7a0227409..0273a95d7 100644 --- a/apps/devtool/src/app/_hooks/useAuthServerApi.tsx +++ b/apps/devtool/src/app/_hooks/useAuthServerApi.tsx @@ -4,9 +4,9 @@ import { AuthorizationRequestStatus, EntityStoreClient, Evaluate, - Request + Request, + SigningAlg } from '@narval/armory-sdk' -import { SigningAlg } from '@narval/signature' import { useMemo, useState } from 'react' import { SetOptional } from 'type-fest' import { extractErrorMessage, getUrlProtocol } from '../_lib/utils' diff --git a/apps/devtool/src/app/_hooks/useDataStoreApi.tsx b/apps/devtool/src/app/_hooks/useDataStoreApi.tsx index 416733560..f9bb30310 100644 --- a/apps/devtool/src/app/_hooks/useDataStoreApi.tsx +++ b/apps/devtool/src/app/_hooks/useDataStoreApi.tsx @@ -1,14 +1,15 @@ -import { EntityStoreClient, PolicyStoreClient } from '@narval/armory-sdk' import { Entities, EntityData, EntityStore, + EntityStoreClient, EntityUtil, Policy, PolicyData, - PolicyStore -} from '@narval/policy-engine-shared' -import { SigningAlg } from '@narval/signature' + PolicyStore, + PolicyStoreClient, + SigningAlg +} from '@narval/armory-sdk' import { useEffect, useMemo, useState } from 'react' import { backOff, extractErrorMessage, getHost, isValidUrl } from '../_lib/utils' import useAccountSignature from './useAccountSignature' diff --git a/apps/devtool/src/app/_hooks/useEngineApi.tsx b/apps/devtool/src/app/_hooks/useEngineApi.tsx index a8d933a8b..5ee5d6848 100644 --- a/apps/devtool/src/app/_hooks/useEngineApi.tsx +++ b/apps/devtool/src/app/_hooks/useEngineApi.tsx @@ -1,12 +1,12 @@ import { EngineClientConfig, + EvaluationRequest, + SigningAlg, onboardEngineClient, pingEngine, sendEvaluationRequest, syncPolicyEngine } from '@narval/armory-sdk' -import { EvaluationRequest } from '@narval/policy-engine-shared' -import { SigningAlg } from '@narval/signature' import { useMemo, useState } from 'react' import { extractErrorMessage, getUrlProtocol } from '../_lib/utils' import useAccountSignature from './useAccountSignature' diff --git a/apps/devtool/src/app/_hooks/useVaultApi.tsx b/apps/devtool/src/app/_hooks/useVaultApi.tsx index a4b56a37b..a93b0a380 100644 --- a/apps/devtool/src/app/_hooks/useVaultApi.tsx +++ b/apps/devtool/src/app/_hooks/useVaultApi.tsx @@ -3,11 +3,15 @@ import { GenerateKeyRequest, ImportPrivateKeyRequest, ImportSeedRequest, + Jwk, + Request, + RsaPublicKey, + SigningAlg, VaultAdminClient, - VaultClient + VaultClient, + rsaKeyToKid, + rsaPublicKeySchema } from '@narval/armory-sdk' -import { Request } from '@narval/policy-engine-shared' -import { Alg, Jwk, RsaPublicKey, SigningAlg, rsaKeyToKid, rsaPublicKeySchema } from '@narval/signature' import { exportJWK, importSPKI } from 'jose' import { useMemo, useState } from 'react' import { extractErrorMessage, getHost, isValidUrl } from '../_lib/utils' @@ -81,13 +85,13 @@ const useVaultApi = () => { } = vaultClientData const getJwkFromRsaPem = async (pem: string): Promise => { - const key = await importSPKI(pem, Alg.RS256, { extractable: true }) + const key = await importSPKI(pem, SigningAlg.RS256, { extractable: true }) const jwk = await exportJWK(key) const kid = rsaKeyToKid(jwk as Jwk) return rsaPublicKeySchema.parse({ ...jwk, - alg: Alg.RS256, + alg: SigningAlg.RS256, kid }) } diff --git a/packages/armory-sdk/src/index.ts b/packages/armory-sdk/src/index.ts index b7b868fda..10f35d498 100644 --- a/packages/armory-sdk/src/index.ts +++ b/packages/armory-sdk/src/index.ts @@ -9,7 +9,7 @@ export * from './lib/vault' export { resourceId } from './lib/utils' -export type { Alg, PrivateKey, PublicKey, RsaPublicKey } from '@narval/signature' +export type { Alg, Jwk, PrivateKey, PublicKey, RsaPublicKey } from '@narval/signature' export { Curves, @@ -27,6 +27,8 @@ export { privateKeyToJwk, publicKeySchema, publicKeyToJwk, + rsaKeyToKid, + rsaPublicKeySchema, signJwt } from '@narval/signature' @@ -41,6 +43,7 @@ export type { Eip712TypedData, Entities, EntityType, + EvaluationRequest, Hex, JwtString, Policy, @@ -50,13 +53,17 @@ export type { TransactionRequest, UserAccountEntity, UserEntity, - ValueOperators, + ValueOperators } from '@narval/policy-engine-shared' export { AccountType, Action, + EntityData, + EntityStore, EntityUtil, + PolicyData, + PolicyStore, UserRole, getAddress, hexSchema, From bf531c90b723042e2229d9cac862a7592bfa5ec6 Mon Sep 17 00:00:00 2001 From: Matt Schoch Date: Thu, 29 Aug 2024 14:27:35 -0400 Subject: [PATCH 4/4] Fixing type/const separation in sdk root --- apps/devtool/src/app/_hooks/useVaultApi.tsx | 5 +++-- packages/armory-sdk/src/index.ts | 25 +++++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/devtool/src/app/_hooks/useVaultApi.tsx b/apps/devtool/src/app/_hooks/useVaultApi.tsx index a93b0a380..191542b7a 100644 --- a/apps/devtool/src/app/_hooks/useVaultApi.tsx +++ b/apps/devtool/src/app/_hooks/useVaultApi.tsx @@ -1,4 +1,5 @@ import { + Alg, DeriveAccountRequest, GenerateKeyRequest, ImportPrivateKeyRequest, @@ -85,13 +86,13 @@ const useVaultApi = () => { } = vaultClientData const getJwkFromRsaPem = async (pem: string): Promise => { - const key = await importSPKI(pem, SigningAlg.RS256, { extractable: true }) + const key = await importSPKI(pem, Alg.RS256, { extractable: true }) const jwk = await exportJWK(key) const kid = rsaKeyToKid(jwk as Jwk) return rsaPublicKeySchema.parse({ ...jwk, - alg: SigningAlg.RS256, + alg: Alg.RS256, kid }) } diff --git a/packages/armory-sdk/src/index.ts b/packages/armory-sdk/src/index.ts index 10f35d498..e1f4e19ab 100644 --- a/packages/armory-sdk/src/index.ts +++ b/packages/armory-sdk/src/index.ts @@ -9,9 +9,10 @@ export * from './lib/vault' export { resourceId } from './lib/utils' -export type { Alg, Jwk, PrivateKey, PublicKey, RsaPublicKey } from '@narval/signature' +export type { Jwk, PrivateKey, PublicKey, RsaPublicKey } from '@narval/signature' export { + Alg, Curves, KeyTypes, SigningAlg, @@ -33,38 +34,38 @@ export { } from '@narval/signature' export type { - AccessToken, AccountEntity, Address, - CreateAuthorizationRequest, CredentialEntity, - Criterion, Decision, - Eip712TypedData, Entities, - EntityType, EvaluationRequest, Hex, - JwtString, Policy, PolicyCriterion, - Request, - Then, - TransactionRequest, UserAccountEntity, - UserEntity, - ValueOperators + UserEntity } from '@narval/policy-engine-shared' export { + AccessToken, AccountType, Action, + CreateAuthorizationRequest, + Criterion, + Eip712TypedData, EntityData, EntityStore, + EntityType, EntityUtil, + JwtString, PolicyData, PolicyStore, + Request, + Then, + TransactionRequest, UserRole, + ValueOperators, getAddress, hexSchema, isAddress,