diff --git a/.changeset/funny-sheep-repeat.md b/.changeset/funny-sheep-repeat.md new file mode 100644 index 000000000..3dfe8bad2 --- /dev/null +++ b/.changeset/funny-sheep-repeat.md @@ -0,0 +1,5 @@ +--- +'@celo/metadata-claims': minor +--- + +Add support for RPC_URL claim type diff --git a/.changeset/three-spies-wonder.md b/.changeset/three-spies-wonder.md new file mode 100644 index 000000000..dd594f5e0 --- /dev/null +++ b/.changeset/three-spies-wonder.md @@ -0,0 +1,5 @@ +--- +'@celo/celocli': minor +--- + +Introduces a new command `account:claim-rpc-url` allowing to claim RPC URLs diff --git a/docs/command-line-interface/account.md b/docs/command-line-interface/account.md index e760d1c18..2d1d25c21 100644 --- a/docs/command-line-interface/account.md +++ b/docs/command-line-interface/account.md @@ -9,6 +9,7 @@ Manage your account, keys, and metadata * [`celocli account:claim-domain ARG1`](#celocli-accountclaim-domain-arg1) * [`celocli account:claim-keybase ARG1`](#celocli-accountclaim-keybase-arg1) * [`celocli account:claim-name ARG1`](#celocli-accountclaim-name-arg1) +* [`celocli account:claim-rpc-url ARG1`](#celocli-accountclaim-rpc-url-arg1) * [`celocli account:claim-storage ARG1`](#celocli-accountclaim-storage-arg1) * [`celocli account:create-metadata ARG1`](#celocli-accountcreate-metadata-arg1) * [`celocli account:deauthorize`](#celocli-accountdeauthorize) @@ -415,6 +416,67 @@ FLAG DESCRIPTIONS _See code: [src/commands/account/claim-name.ts](https://github.com/celo-org/developer-tooling/tree/master/packages/cli/src/commands/account/claim-name.ts)_ +## `celocli account:claim-rpc-url ARG1` + +Claim a RPC URL and add the claim to a local metadata file + +``` +USAGE + $ celocli account:claim-rpc-url ARG1 --from 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d + --rpcUrl https://www.celo.org [-k | --useLedger | ] [-n ] + [--gasCurrency 0x1234567890123456789012345678901234567890] [--ledgerAddresses + ] [--globalHelp] + +ARGUMENTS + ARG1 Path of the metadata file + +FLAGS + -k, --privateKey= + Use a private key to sign local transactions with + + -n, --node= + URL of the node to run commands against or an alias + + --from=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d + (required) Address of the account to set metadata for. Claiming address must be + registered as validator + + --gasCurrency=0x1234567890123456789012345678901234567890 + Use a specific gas currency for transaction fees (defaults to CELO if no gas + currency is supplied). It must be a whitelisted token. + + --globalHelp + View all available global flags + + --ledgerAddresses= + [default: 1] If --useLedger is set, this will get the first N addresses for local + signing + + --rpcUrl=https://www.celo.org + (required) The RPC URL to claim + + --useLedger + Set it to use a ledger wallet + +DESCRIPTION + Claim a RPC URL and add the claim to a local metadata file + +EXAMPLES + claim-rpc-url ~/metadata.json --rpc-url example.com --from 0x5409ED021D9299bf6814279A6A1411A7e866A631 + +FLAG DESCRIPTIONS + -n, --node= URL of the node to run commands against or an alias + + Can be a full url like https://forno.celo.org or an alias. default: + http://localhost:8545 + Alias options: + local, localhost => 'http://localhost:8545' + alfajores => Celo Alfajores Testnet, + mainnet, celo, forno => Celo Mainnet chain', +``` + +_See code: [src/commands/account/claim-rpc-url.ts](https://github.com/celo-org/developer-tooling/tree/master/packages/cli/src/commands/account/claim-rpc-url.ts)_ + ## `celocli account:claim-storage ARG1` Claim a storage root and add the claim to a local metadata file diff --git a/docs/command-line-interface/governance.md b/docs/command-line-interface/governance.md index 04ed0c52b..0e304ca01 100644 --- a/docs/command-line-interface/governance.md +++ b/docs/command-line-interface/governance.md @@ -535,8 +535,8 @@ Submit a governance proposal ``` USAGE $ celocli governance:propose --jsonTransactions --deposit --from - 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d --descriptionURL [-k | - --useLedger | ] [-n ] [--gasCurrency + 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d --descriptionURL https://www.celo.org [-k + | --useLedger | ] [-n ] [--gasCurrency 0x1234567890123456789012345678901234567890] [--ledgerAddresses ] [--globalHelp] [--for 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d --useMultiSig] [--force] [--noInfo] [--afterExecutingProposal | --afterExecutingID ] @@ -557,7 +557,7 @@ FLAGS --deposit= (required) Amount of Celo to attach to proposal - --descriptionURL= + --descriptionURL=https://www.celo.org (required) A URL where further information about the proposal can be viewed --for=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d diff --git a/docs/sdk/metadata-claims/classes/metadata.IdentityMetadataWrapper.md b/docs/sdk/metadata-claims/classes/metadata.IdentityMetadataWrapper.md index 589bc5417..5538f07b7 100644 --- a/docs/sdk/metadata-claims/classes/metadata.IdentityMetadataWrapper.md +++ b/docs/sdk/metadata-claims/classes/metadata.IdentityMetadataWrapper.md @@ -43,7 +43,7 @@ | Name | Type | Default value | | :------ | :------ | :------ | | `data` | `Object` | `undefined` | -| `data.claims` | (\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) } \| \{ `timestamp`: `number` = TimestampType; `type`: [`KEYBASE`](../enums/types.ClaimTypes.md#keybase) ; `username`: `string` = t.string } \| \{ `domain`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`DOMAIN`](../enums/types.ClaimTypes.md#domain) } \| \{ `name`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`NAME`](../enums/types.ClaimTypes.md#name) } \| \{ `address`: `string` = t.string; `filteredDataPaths`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`STORAGE`](../enums/types.ClaimTypes.md#storage) })[] | `undefined` | +| `data.claims` | (\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) } \| \{ `timestamp`: `number` = TimestampType; `type`: [`KEYBASE`](../enums/types.ClaimTypes.md#keybase) ; `username`: `string` = t.string } \| \{ `domain`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`DOMAIN`](../enums/types.ClaimTypes.md#domain) } \| \{ `rpcUrl`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`RPC_URL`](../enums/types.ClaimTypes.md#rpc_url) } \| \{ `name`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`NAME`](../enums/types.ClaimTypes.md#name) } \| \{ `address`: `string` = t.string; `filteredDataPaths`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`STORAGE`](../enums/types.ClaimTypes.md#storage) })[] | `undefined` | | `data.meta` | `Object` | `MetaType` | | `data.meta.address` | `string` | `AddressType` | | `data.meta.signature` | `string` | `SignatureType` | @@ -66,7 +66,7 @@ | Name | Type | | :------ | :------ | -| `claims` | (\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) } \| \{ `timestamp`: `number` = TimestampType; `type`: [`KEYBASE`](../enums/types.ClaimTypes.md#keybase) ; `username`: `string` = t.string } \| \{ `domain`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`DOMAIN`](../enums/types.ClaimTypes.md#domain) } \| \{ `name`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`NAME`](../enums/types.ClaimTypes.md#name) } \| \{ `address`: `string` = t.string; `filteredDataPaths`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`STORAGE`](../enums/types.ClaimTypes.md#storage) })[] | +| `claims` | (\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) } \| \{ `timestamp`: `number` = TimestampType; `type`: [`KEYBASE`](../enums/types.ClaimTypes.md#keybase) ; `username`: `string` = t.string } \| \{ `domain`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`DOMAIN`](../enums/types.ClaimTypes.md#domain) } \| \{ `rpcUrl`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`RPC_URL`](../enums/types.ClaimTypes.md#rpc_url) } \| \{ `name`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`NAME`](../enums/types.ClaimTypes.md#name) } \| \{ `address`: `string` = t.string; `filteredDataPaths`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`STORAGE`](../enums/types.ClaimTypes.md#storage) })[] | | `meta` | \{ `address`: `string` = AddressType; `signature`: `string` = SignatureType } | | `meta.address` | `string` | | `meta.signature` | `string` | @@ -79,11 +79,11 @@ ### claims -• `get` **claims**(): (\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) } \| \{ `timestamp`: `number` = TimestampType; `type`: [`KEYBASE`](../enums/types.ClaimTypes.md#keybase) ; `username`: `string` = t.string } \| \{ `domain`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`DOMAIN`](../enums/types.ClaimTypes.md#domain) } \| \{ `name`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`NAME`](../enums/types.ClaimTypes.md#name) } \| \{ `address`: `string` = t.string; `filteredDataPaths`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`STORAGE`](../enums/types.ClaimTypes.md#storage) })[] +• `get` **claims**(): (\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) } \| \{ `timestamp`: `number` = TimestampType; `type`: [`KEYBASE`](../enums/types.ClaimTypes.md#keybase) ; `username`: `string` = t.string } \| \{ `domain`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`DOMAIN`](../enums/types.ClaimTypes.md#domain) } \| \{ `rpcUrl`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`RPC_URL`](../enums/types.ClaimTypes.md#rpc_url) } \| \{ `name`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`NAME`](../enums/types.ClaimTypes.md#name) } \| \{ `address`: `string` = t.string; `filteredDataPaths`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`STORAGE`](../enums/types.ClaimTypes.md#storage) })[] #### Returns -(\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) } \| \{ `timestamp`: `number` = TimestampType; `type`: [`KEYBASE`](../enums/types.ClaimTypes.md#keybase) ; `username`: `string` = t.string } \| \{ `domain`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`DOMAIN`](../enums/types.ClaimTypes.md#domain) } \| \{ `name`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`NAME`](../enums/types.ClaimTypes.md#name) } \| \{ `address`: `string` = t.string; `filteredDataPaths`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`STORAGE`](../enums/types.ClaimTypes.md#storage) })[] +(\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) } \| \{ `timestamp`: `number` = TimestampType; `type`: [`KEYBASE`](../enums/types.ClaimTypes.md#keybase) ; `username`: `string` = t.string } \| \{ `domain`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`DOMAIN`](../enums/types.ClaimTypes.md#domain) } \| \{ `rpcUrl`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`RPC_URL`](../enums/types.ClaimTypes.md#rpc_url) } \| \{ `name`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`NAME`](../enums/types.ClaimTypes.md#name) } \| \{ `address`: `string` = t.string; `filteredDataPaths`: `string` = t.string; `timestamp`: `number` = TimestampType; `type`: [`STORAGE`](../enums/types.ClaimTypes.md#storage) })[] #### Defined in @@ -134,7 +134,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/metadata.ts:216](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/metadata.ts#L216) +[packages/sdk/metadata-claims/src/metadata.ts:223](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/metadata.ts#L223) ___ @@ -160,7 +160,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/metadata.ts:212](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/metadata.ts#L212) +[packages/sdk/metadata-claims/src/metadata.ts:219](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/metadata.ts#L219) ___ diff --git a/docs/sdk/metadata-claims/enums/types.ClaimTypes.md b/docs/sdk/metadata-claims/enums/types.ClaimTypes.md index 3d4949116..9d061e8fa 100644 --- a/docs/sdk/metadata-claims/enums/types.ClaimTypes.md +++ b/docs/sdk/metadata-claims/enums/types.ClaimTypes.md @@ -13,6 +13,7 @@ - [KEYBASE](types.ClaimTypes.md#keybase) - [NAME](types.ClaimTypes.md#name) - [PROFILE\_PICTURE](types.ClaimTypes.md#profile_picture) +- [RPC\_URL](types.ClaimTypes.md#rpc_url) - [STORAGE](types.ClaimTypes.md#storage) - [TWITTER](types.ClaimTypes.md#twitter) @@ -44,7 +45,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/types.ts:14](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L14) +[packages/sdk/metadata-claims/src/types.ts:15](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L15) ___ @@ -54,7 +55,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/types.ts:15](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L15) +[packages/sdk/metadata-claims/src/types.ts:16](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L16) ___ @@ -64,7 +65,17 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/types.ts:16](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L16) +[packages/sdk/metadata-claims/src/types.ts:17](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L17) + +___ + +### RPC\_URL + +• **RPC\_URL** = ``"RPC_URL"`` + +#### Defined in + +[packages/sdk/metadata-claims/src/types.ts:14](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L14) ___ @@ -74,7 +85,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/types.ts:17](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L17) +[packages/sdk/metadata-claims/src/types.ts:18](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L18) ___ @@ -84,4 +95,4 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/types.ts:18](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L18) +[packages/sdk/metadata-claims/src/types.ts:19](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L19) diff --git a/docs/sdk/metadata-claims/modules/claim.md b/docs/sdk/metadata-claims/modules/claim.md index 8bfc752c4..74a505ca7 100644 --- a/docs/sdk/metadata-claims/modules/claim.md +++ b/docs/sdk/metadata-claims/modules/claim.md @@ -11,6 +11,7 @@ - [DomainClaim](claim.md#domainclaim) - [KeybaseClaim](claim.md#keybaseclaim) - [NameClaim](claim.md#nameclaim) +- [RpcUrlClaim](claim.md#rpcurlclaim) - [StorageClaim](claim.md#storageclaim) ### Variables @@ -24,6 +25,7 @@ - [createDomainClaim](claim.md#createdomainclaim) - [createNameClaim](claim.md#createnameclaim) +- [createRpcUrlClaim](claim.md#createrpcurlclaim) - [createStorageClaim](claim.md#createstorageclaim) - [hashOfClaim](claim.md#hashofclaim) - [hashOfClaims](claim.md#hashofclaims) @@ -34,17 +36,17 @@ ### Claim -Ƭ **Claim**: [`DomainClaim`](claim.md#domainclaim) \| [`KeybaseClaim`](claim.md#keybaseclaim) \| [`NameClaim`](claim.md#nameclaim) \| [`AccountClaim`](account.md#accountclaim) \| [`StorageClaim`](claim.md#storageclaim) +Ƭ **Claim**: [`DomainClaim`](claim.md#domainclaim) \| [`RpcUrlClaim`](claim.md#rpcurlclaim) \| [`KeybaseClaim`](claim.md#keybaseclaim) \| [`NameClaim`](claim.md#nameclaim) \| [`AccountClaim`](account.md#accountclaim) \| [`StorageClaim`](claim.md#storageclaim) #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:50](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L50) +[packages/sdk/metadata-claims/src/claim.ts:58](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L58) ___ ### ClaimPayload -Ƭ **ClaimPayload**\<`K`\>: `K` extends typeof [`DOMAIN`](../enums/types.ClaimTypes.md#domain) ? [`DomainClaim`](claim.md#domainclaim) : `K` extends typeof [`NAME`](../enums/types.ClaimTypes.md#name) ? [`NameClaim`](claim.md#nameclaim) : `K` extends typeof [`KEYBASE`](../enums/types.ClaimTypes.md#keybase) ? [`KeybaseClaim`](claim.md#keybaseclaim) : `K` extends typeof [`ACCOUNT`](../enums/types.ClaimTypes.md#account) ? [`AccountClaim`](account.md#accountclaim) : [`StorageClaim`](claim.md#storageclaim) +Ƭ **ClaimPayload**\<`K`\>: `K` extends typeof [`DOMAIN`](../enums/types.ClaimTypes.md#domain) ? [`DomainClaim`](claim.md#domainclaim) : `K` extends typeof [`RPC_URL`](../enums/types.ClaimTypes.md#rpc_url) ? [`RpcUrlClaim`](claim.md#rpcurlclaim) : `K` extends typeof [`NAME`](../enums/types.ClaimTypes.md#name) ? [`NameClaim`](claim.md#nameclaim) : `K` extends typeof [`KEYBASE`](../enums/types.ClaimTypes.md#keybase) ? [`KeybaseClaim`](claim.md#keybaseclaim) : `K` extends typeof [`ACCOUNT`](../enums/types.ClaimTypes.md#account) ? [`AccountClaim`](account.md#accountclaim) : [`StorageClaim`](claim.md#storageclaim) #### Type parameters @@ -54,7 +56,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:52](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L52) +[packages/sdk/metadata-claims/src/claim.ts:66](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L66) ___ @@ -64,7 +66,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:47](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L47) +[packages/sdk/metadata-claims/src/claim.ts:54](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L54) ___ @@ -84,7 +86,17 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:48](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L48) +[packages/sdk/metadata-claims/src/claim.ts:56](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L56) + +___ + +### RpcUrlClaim + +Ƭ **RpcUrlClaim**: `t.TypeOf`\ + +#### Defined in + +[packages/sdk/metadata-claims/src/claim.ts:55](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L55) ___ @@ -94,17 +106,17 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:49](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L49) +[packages/sdk/metadata-claims/src/claim.ts:57](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L57) ## Variables ### ClaimType -• `Const` **ClaimType**: `UnionC`\<[`Type`\<\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) }, `any`, `unknown`\>, `TypeC`\<\{ `domain`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`DOMAIN`](../enums/types.ClaimTypes.md#domain)\> }\>, `TypeC`\<\{ `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`KEYBASE`](../enums/types.ClaimTypes.md#keybase)\> ; `username`: `StringC` = t.string }\>, `TypeC`\<\{ `name`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`NAME`](../enums/types.ClaimTypes.md#name)\> }\>, `TypeC`\<\{ `address`: `StringC` = t.string; `filteredDataPaths`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`STORAGE`](../enums/types.ClaimTypes.md#storage)\> }\>]\> +• `Const` **ClaimType**: `UnionC`\<[`Type`\<\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) }, `any`, `unknown`\>, `TypeC`\<\{ `domain`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`DOMAIN`](../enums/types.ClaimTypes.md#domain)\> }\>, `TypeC`\<\{ `rpcUrl`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`RPC_URL`](../enums/types.ClaimTypes.md#rpc_url)\> }\>, `TypeC`\<\{ `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`KEYBASE`](../enums/types.ClaimTypes.md#keybase)\> ; `username`: `StringC` = t.string }\>, `TypeC`\<\{ `name`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`NAME`](../enums/types.ClaimTypes.md#name)\> }\>, `TypeC`\<\{ `address`: `StringC` = t.string; `filteredDataPaths`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`STORAGE`](../enums/types.ClaimTypes.md#storage)\> }\>]\> #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:33](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L33) +[packages/sdk/metadata-claims/src/claim.ts:39](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L39) ___ @@ -114,7 +126,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:46](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L46) +[packages/sdk/metadata-claims/src/claim.ts:53](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L53) ___ @@ -130,11 +142,11 @@ ___ ### SignedClaimType -• `Const` **SignedClaimType**: `TypeC`\<\{ `claim`: `UnionC`\<[`Type`\<\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) }, `any`, `unknown`\>, `TypeC`\<\{ `domain`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`DOMAIN`](../enums/types.ClaimTypes.md#domain)\> }\>, `TypeC`\<\{ `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`KEYBASE`](../enums/types.ClaimTypes.md#keybase)\> ; `username`: `StringC` = t.string }\>, `TypeC`\<\{ `name`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`NAME`](../enums/types.ClaimTypes.md#name)\> }\>, `TypeC`\<\{ `address`: `StringC` = t.string; `filteredDataPaths`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`STORAGE`](../enums/types.ClaimTypes.md#storage)\> }\>]\> = ClaimType; `signature`: `StringC` = SignatureType }\> +• `Const` **SignedClaimType**: `TypeC`\<\{ `claim`: `UnionC`\<[`Type`\<\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) }, `any`, `unknown`\>, `TypeC`\<\{ `domain`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`DOMAIN`](../enums/types.ClaimTypes.md#domain)\> }\>, `TypeC`\<\{ `rpcUrl`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`RPC_URL`](../enums/types.ClaimTypes.md#rpc_url)\> }\>, `TypeC`\<\{ `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`KEYBASE`](../enums/types.ClaimTypes.md#keybase)\> ; `username`: `StringC` = t.string }\>, `TypeC`\<\{ `name`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`NAME`](../enums/types.ClaimTypes.md#name)\> }\>, `TypeC`\<\{ `address`: `StringC` = t.string; `filteredDataPaths`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`STORAGE`](../enums/types.ClaimTypes.md#storage)\> }\>]\> = ClaimType; `signature`: `StringC` = SignatureType }\> #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:41](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L41) +[packages/sdk/metadata-claims/src/claim.ts:48](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L48) ## Functions @@ -160,7 +172,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:87](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L87) +[packages/sdk/metadata-claims/src/claim.ts:103](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L103) ___ @@ -186,7 +198,33 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:81](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L81) +[packages/sdk/metadata-claims/src/claim.ts:97](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L97) + +___ + +### createRpcUrlClaim + +▸ **createRpcUrlClaim**(`rpcUrl`): `Object` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `rpcUrl` | `string` | + +#### Returns + +`Object` + +| Name | Type | +| :------ | :------ | +| `rpcUrl` | `string` | +| `timestamp` | `number` | +| `type` | [`RPC_URL`](../enums/types.ClaimTypes.md#rpc_url) | + +#### Defined in + +[packages/sdk/metadata-claims/src/claim.ts:109](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L109) ___ @@ -213,7 +251,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:93](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L93) +[packages/sdk/metadata-claims/src/claim.ts:115](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L115) ___ @@ -233,7 +271,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:68](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L68) +[packages/sdk/metadata-claims/src/claim.ts:84](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L84) ___ @@ -253,7 +291,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:72](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L72) +[packages/sdk/metadata-claims/src/claim.ts:88](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L88) ___ @@ -291,7 +329,7 @@ data is ClaimPayload\ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:64](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L64) +[packages/sdk/metadata-claims/src/claim.ts:80](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L80) ___ @@ -311,4 +349,4 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/claim.ts:77](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L77) +[packages/sdk/metadata-claims/src/claim.ts:93](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/claim.ts#L93) diff --git a/docs/sdk/metadata-claims/modules/metadata.md b/docs/sdk/metadata-claims/modules/metadata.md index 4a3f6d765..dec2d5ea4 100644 --- a/docs/sdk/metadata-claims/modules/metadata.md +++ b/docs/sdk/metadata-claims/modules/metadata.md @@ -40,7 +40,7 @@ Re-exports [ClaimTypes](../enums/types.ClaimTypes.md) ### IdentityMetadataType -• `Const` **IdentityMetadataType**: `TypeC`\<\{ `claims`: `ArrayC`\<`UnionC`\<[`Type`\<\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) }, `any`, `unknown`\>, `TypeC`\<\{ `domain`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`DOMAIN`](../enums/types.ClaimTypes.md#domain)\> }\>, `TypeC`\<\{ `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`KEYBASE`](../enums/types.ClaimTypes.md#keybase)\> ; `username`: `StringC` = t.string }\>, `TypeC`\<\{ `name`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`NAME`](../enums/types.ClaimTypes.md#name)\> }\>, `TypeC`\<\{ `address`: `StringC` = t.string; `filteredDataPaths`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`STORAGE`](../enums/types.ClaimTypes.md#storage)\> }\>]\>\> ; `meta`: `TypeC`\<\{ `address`: `Type`\<`string`, `string`, `unknown`\> = AddressType; `signature`: `StringC` = SignatureType }\> = MetaType }\> +• `Const` **IdentityMetadataType**: `TypeC`\<\{ `claims`: `ArrayC`\<`UnionC`\<[`Type`\<\{ `address`: `string` = AddressType; `publicKey`: `undefined` \| `string` ; `timestamp`: `number` = TimestampType; `type`: [`ACCOUNT`](../enums/types.ClaimTypes.md#account) }, `any`, `unknown`\>, `TypeC`\<\{ `domain`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`DOMAIN`](../enums/types.ClaimTypes.md#domain)\> }\>, `TypeC`\<\{ `rpcUrl`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`RPC_URL`](../enums/types.ClaimTypes.md#rpc_url)\> }\>, `TypeC`\<\{ `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`KEYBASE`](../enums/types.ClaimTypes.md#keybase)\> ; `username`: `StringC` = t.string }\>, `TypeC`\<\{ `name`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`NAME`](../enums/types.ClaimTypes.md#name)\> }\>, `TypeC`\<\{ `address`: `StringC` = t.string; `filteredDataPaths`: `StringC` = t.string; `timestamp`: `NumberC` = TimestampType; `type`: `LiteralC`\<[`STORAGE`](../enums/types.ClaimTypes.md#storage)\> }\>]\>\> ; `meta`: `TypeC`\<\{ `address`: `Type`\<`string`, `string`, `unknown`\> = AddressType; `signature`: `StringC` = SignatureType }\> = MetaType }\> #### Defined in diff --git a/docs/sdk/metadata-claims/modules/types.md b/docs/sdk/metadata-claims/modules/types.md index 18e4607ff..3252ded5b 100644 --- a/docs/sdk/metadata-claims/modules/types.md +++ b/docs/sdk/metadata-claims/modules/types.md @@ -32,7 +32,7 @@ #### Defined in -[packages/sdk/metadata-claims/src/types.ts:31](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L31) +[packages/sdk/metadata-claims/src/types.ts:32](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L32) ___ @@ -51,7 +51,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/types.ts:24](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L24) +[packages/sdk/metadata-claims/src/types.ts:25](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L25) ## Variables @@ -61,7 +61,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/types.ts:22](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L22) +[packages/sdk/metadata-claims/src/types.ts:23](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L23) ___ @@ -91,7 +91,7 @@ ___ #### Defined in -[packages/sdk/metadata-claims/src/types.ts:21](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L21) +[packages/sdk/metadata-claims/src/types.ts:22](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/metadata-claims/src/types.ts#L22) ## Functions diff --git a/packages/cli/src/commands/account/claim-rpc-url.ts b/packages/cli/src/commands/account/claim-rpc-url.ts new file mode 100644 index 000000000..fa83e6fec --- /dev/null +++ b/packages/cli/src/commands/account/claim-rpc-url.ts @@ -0,0 +1,35 @@ +import { createRpcUrlClaim } from '@celo/metadata-claims/lib/claim' +import { BaseCommand } from '../../base' +import { CustomFlags } from '../../utils/command' +import { ClaimCommand } from '../../utils/identity' + +export default class ClaimRpcUrl extends ClaimCommand { + static description = 'Claim a RPC URL and add the claim to a local metadata file' + static flags = { + ...BaseCommand.flags, + from: CustomFlags.address({ + required: true, + description: + 'Address of the account to set metadata for. Claiming address must be registered as validator', + }), + rpcUrl: CustomFlags.url({ + required: true, + description: 'The RPC URL to claim', + }), + } + static args = ClaimCommand.args + static examples = [ + 'claim-rpc-url ~/metadata.json --rpc-url example.com --from 0x5409ED021D9299bf6814279A6A1411A7e866A631', + ] + + self = ClaimRpcUrl + + async run() { + const res = await this.parse(ClaimRpcUrl) + const metadata = await this.readMetadata() + + await this.addClaim(metadata, createRpcUrlClaim(res.flags.rpcUrl)) + + await this.writeMetadata(metadata) + } +} diff --git a/packages/cli/src/commands/account/claims-l2.test.ts b/packages/cli/src/commands/account/claims-l2.test.ts new file mode 100644 index 000000000..bcddd4b6e --- /dev/null +++ b/packages/cli/src/commands/account/claims-l2.test.ts @@ -0,0 +1,180 @@ +import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' +import { testWithAnvilL2 } from '@celo/dev-utils/lib/anvil-test' +import { ClaimTypes, IdentityMetadataWrapper } from '@celo/metadata-claims' +import { now } from '@celo/metadata-claims/lib/types' +import { ux } from '@oclif/core' +import { readFileSync, writeFileSync } from 'fs' +import humanizeDuration from 'humanize-duration' +import { tmpdir } from 'os' +import Web3 from 'web3' +import { stripAnsiCodesFromNestedArray, testLocallyWithWeb3Node } from '../../test-utils/cliUtils' +import ClaimAccount from './claim-account' +import ClaimDomain from './claim-domain' +import ClaimName from './claim-name' +import ClaimRpcUrl from './claim-rpc-url' +import CreateMetadata from './create-metadata' +import RegisterMetadata from './register-metadata' +import ShowMetadata from './show-metadata' +process.env.NO_SYNCCHECK = 'true' + +testWithAnvilL2('account metadata cmds', (web3: Web3) => { + let account: string + let accounts: string[] + let kit: ContractKit + + beforeEach(async () => { + accounts = await web3.eth.getAccounts() + kit = newKitFromWeb3(web3) + account = accounts[0] + }) + + describe('Modifying the metadata file', () => { + const emptyFilePath = `${tmpdir()}/metadata-l2.json` + const generateEmptyMetadataFile = () => { + writeFileSync(emptyFilePath, IdentityMetadataWrapper.fromEmpty(account).toString()) + } + + const readFile = async () => { + return IdentityMetadataWrapper.fromFile(await kit.contracts.getAccounts(), emptyFilePath) + } + + test('account:create-metadata cmd', async () => { + const newFilePath = `${tmpdir()}/newfile.json` + await testLocallyWithWeb3Node(CreateMetadata, ['--from', account, newFilePath], web3) + const res = JSON.parse(readFileSync(newFilePath).toString()) + expect(res.meta.address).toEqual(account) + }) + + test('account:claim-name cmd', async () => { + generateEmptyMetadataFile() + const name = 'myname' + await testLocallyWithWeb3Node( + ClaimName, + ['--from', account, '--name', name, emptyFilePath], + web3 + ) + const metadata = await readFile() + const claim = metadata.findClaim(ClaimTypes.NAME) + expect(claim).toBeDefined() + expect(claim!.name).toEqual(name) + }) + + test('account:claim-domain cmd', async () => { + generateEmptyMetadataFile() + const domain = 'example.com' + await testLocallyWithWeb3Node( + ClaimDomain, + ['--from', account, '--domain', domain, emptyFilePath], + web3 + ) + const metadata = await readFile() + const claim = metadata.findClaim(ClaimTypes.DOMAIN) + expect(claim).toBeDefined() + expect(claim!.domain).toEqual(domain) + }) + + test('account:claim-rpc-url cmd', async () => { + generateEmptyMetadataFile() + const rpcUrl = 'http://example.com:8545' + + await expect( + testLocallyWithWeb3Node( + ClaimRpcUrl, + [emptyFilePath, '--from', account, '--rpcUrl', 'http://127.0.0.1:8545'], + web3 + ) + ).rejects.toMatchInlineSnapshot(` + [Error: Parsing --rpcUrl + Provided URL is a localhost address. Please provide a public URL. + See more help with --help] + `) + + await testLocallyWithWeb3Node( + ClaimRpcUrl, + [emptyFilePath, '--from', account, '--rpcUrl', rpcUrl], + web3 + ) + + const metadata = await readFile() + const claim = metadata.findClaim(ClaimTypes.RPC_URL) + + expect(claim).toBeDefined() + expect(claim!.rpcUrl).toEqual(rpcUrl) + + const infoMock = jest.spyOn(console, 'info') + const writeMock = jest.spyOn(ux.write, 'stdout') + + await testLocallyWithWeb3Node(ShowMetadata, [emptyFilePath, '--csv'], web3) + + expect(stripAnsiCodesFromNestedArray(infoMock.mock.calls)).toMatchInlineSnapshot(` + [ + [ + "Metadata at ${emptyFilePath} contains the following claims: + ", + ], + ] + `) + expect(stripAnsiCodesFromNestedArray(writeMock.mock.calls)).toMatchInlineSnapshot(` + [ + [ + "Type,Value,Status,Created At + ", + ], + [ + "RPC_URL,RPC URL: http://example.com:8545,N/A,${humanizeDuration( + (now() - claim!.timestamp) * 1000 + )} ago + ", + ], + ] + `) + }) + + test('account:claim-account cmd', async () => { + generateEmptyMetadataFile() + const otherAccount = accounts[1] + await testLocallyWithWeb3Node( + ClaimAccount, + ['--from', account, '--address', otherAccount, emptyFilePath], + web3 + ) + const metadata = await readFile() + const claim = metadata.findClaim(ClaimTypes.ACCOUNT) + expect(claim).toBeDefined() + expect(claim!.address).toEqual(otherAccount) + }) + }) + + describe('account:register-metadata cmd', () => { + describe('when the account is registered', () => { + beforeEach(async () => { + const accountsInstance = await kit.contracts.getAccounts() + await accountsInstance.createAccount().sendAndWaitForReceipt({ from: account }) + }) + + test('can register metadata', async () => { + await testLocallyWithWeb3Node( + RegisterMetadata, + ['--force', '--from', account, '--url', 'https://example.com'], + web3 + ) + }) + + test('fails if url is missing', async () => { + await expect( + testLocallyWithWeb3Node(RegisterMetadata, ['--force', '--from', account], web3) + ).rejects.toThrow('Missing required flag') + }) + }) + + it('cannot register metadata', async () => { + await expect( + testLocallyWithWeb3Node( + RegisterMetadata, + ['--force', '--from', account, '--url', 'https://example.com'], + web3 + ) + ).rejects.toThrow("Some checks didn't pass!") + }) + }) +}) diff --git a/packages/cli/src/commands/account/claims.test.ts b/packages/cli/src/commands/account/claims.test.ts index 212ee31d2..5fc7cf331 100644 --- a/packages/cli/src/commands/account/claims.test.ts +++ b/packages/cli/src/commands/account/claims.test.ts @@ -1,15 +1,20 @@ import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' import { ClaimTypes, IdentityMetadataWrapper } from '@celo/metadata-claims' +import { now } from '@celo/metadata-claims/lib/types' +import { ux } from '@oclif/core' import { readFileSync, writeFileSync } from 'fs' +import humanizeDuration from 'humanize-duration' import { tmpdir } from 'os' import Web3 from 'web3' -import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils' +import { stripAnsiCodesFromNestedArray, testLocallyWithWeb3Node } from '../../test-utils/cliUtils' import ClaimAccount from './claim-account' import ClaimDomain from './claim-domain' import ClaimName from './claim-name' +import ClaimRpcUrl from './claim-rpc-url' import CreateMetadata from './create-metadata' import RegisterMetadata from './register-metadata' +import ShowMetadata from './show-metadata' process.env.NO_SYNCCHECK = 'true' testWithAnvilL1('account metadata cmds', (web3: Web3) => { @@ -68,6 +73,51 @@ testWithAnvilL1('account metadata cmds', (web3: Web3) => { expect(claim!.domain).toEqual(domain) }) + test('account:claim-rpc-url cmd', async () => { + generateEmptyMetadataFile() + const rpcUrl = 'http://example.com:8545' + + await testLocallyWithWeb3Node( + ClaimRpcUrl, + [emptyFilePath, '--from', account, '--rpcUrl', rpcUrl], + web3 + ) + + const metadata = await readFile() + const claim = metadata.findClaim(ClaimTypes.RPC_URL) + + expect(claim).toBeDefined() + expect(claim!.rpcUrl).toEqual(rpcUrl) + + const infoMock = jest.spyOn(console, 'info') + const writeMock = jest.spyOn(ux.write, 'stdout') + + await testLocallyWithWeb3Node(ShowMetadata, [emptyFilePath, '--csv'], web3) + + expect(stripAnsiCodesFromNestedArray(infoMock.mock.calls)).toMatchInlineSnapshot(` + [ + [ + "Metadata at ${emptyFilePath} contains the following claims: + ", + ], + ] + `) + expect(stripAnsiCodesFromNestedArray(writeMock.mock.calls)).toMatchInlineSnapshot(` + [ + [ + "Type,Value,Status,Created At + ", + ], + [ + "RPC_URL,RPC URL: http://example.com:8545,N/A,${humanizeDuration( + (now() - claim!.timestamp) * 1000 + )} ago + ", + ], + ] + `) + }) + test('account:claim-account cmd', async () => { generateEmptyMetadataFile() const otherAccount = accounts[1] diff --git a/packages/cli/src/commands/governance/propose.ts b/packages/cli/src/commands/governance/propose.ts index 2bae736cc..497df8a9a 100644 --- a/packages/cli/src/commands/governance/propose.ts +++ b/packages/cli/src/commands/governance/propose.ts @@ -34,7 +34,7 @@ export default class Propose extends BaseCommand { }), force: Flags.boolean({ description: 'Skip execution check', default: false }), noInfo: Flags.boolean({ description: 'Skip printing the proposal info', default: false }), - descriptionURL: Flags.string({ + descriptionURL: CustomFlags.url({ required: true, description: 'A URL where further information about the proposal can be viewed', }), diff --git a/packages/cli/src/utils/command.test.ts b/packages/cli/src/utils/command.test.ts new file mode 100644 index 000000000..1a60435bb --- /dev/null +++ b/packages/cli/src/utils/command.test.ts @@ -0,0 +1,43 @@ +import { CustomFlags } from './command' + +describe('CustomFlags.url', () => { + it('should return the input if it is a valid URL', async () => { + const flag = CustomFlags.url({ + required: true, + description: 'Test URL', + }) + + await expect( + flag.parse('https://example.com', {} as any, {} as any) + ).resolves.toMatchInlineSnapshot(`"https://example.com"`) + }) + + it('should throw an error if the input is not a valid URL', async () => { + const flag = CustomFlags.url({ + required: true, + description: 'Test URL', + }) + + await expect( + flag.parse('invalid', {} as any, {} as any) + ).rejects.toThrowErrorMatchingInlineSnapshot(`""invalid" is not a valid URL"`) + }) + + it('should throw an error if the input is a localhost URL', async () => { + const flag = CustomFlags.url({ + required: true, + description: 'Test URL', + }) + + await expect( + flag.parse('http://localhost:8545', {} as any, {} as any) + ).rejects.toThrowErrorMatchingInlineSnapshot( + `"Provided URL is a localhost address. Please provide a public URL."` + ) + await expect(() => + flag.parse('http://127.0.0.1/path', {} as any, {} as any) + ).rejects.toThrowErrorMatchingInlineSnapshot( + `"Provided URL is a localhost address. Please provide a public URL."` + ) + }) +}) diff --git a/packages/cli/src/utils/command.ts b/packages/cli/src/utils/command.ts index 60678ef66..487ea55e3 100644 --- a/packages/cli/src/utils/command.ts +++ b/packages/cli/src/utils/command.ts @@ -89,6 +89,12 @@ const parsePhoneNumber: ParseFn = async (input) => { const parseUrl: ParseFn = async (input) => { if (URL_REGEX.test(input)) { + const url = new URL(input) + + if (url.hostname === 'localhost' || url.hostname === '127.0.0.1') { + throw new CLIError('Provided URL is a localhost address. Please provide a public URL.') + } + return input } else { throw new CLIError(`"${input}" is not a valid URL`) diff --git a/packages/cli/src/utils/identity.ts b/packages/cli/src/utils/identity.ts index e03a77d12..079f8943b 100644 --- a/packages/cli/src/utils/identity.ts +++ b/packages/cli/src/utils/identity.ts @@ -138,6 +138,9 @@ export const displayMetadata = async ( case ClaimTypes.DOMAIN: extra = `Domain: ${claim.domain}` break + case ClaimTypes.RPC_URL: + extra = `RPC URL: ${claim.rpcUrl}` + break case ClaimTypes.KEYBASE: extra = `Username: ${claim.username}` break diff --git a/packages/sdk/metadata-claims/.gitignore b/packages/sdk/metadata-claims/.gitignore new file mode 100644 index 000000000..c3af85790 --- /dev/null +++ b/packages/sdk/metadata-claims/.gitignore @@ -0,0 +1 @@ +lib/ diff --git a/packages/sdk/metadata-claims/lib/account.d.ts b/packages/sdk/metadata-claims/lib/account.d.ts deleted file mode 100644 index e12432041..000000000 --- a/packages/sdk/metadata-claims/lib/account.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import * as t from 'io-ts'; -import { ClaimTypes } from './types'; -/** - * - * Provide the type minus the validation that the public key and address are derived from the same private key - */ -export declare const AccountClaimTypeH: t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - address: t.Type; - publicKey: t.UnionC<[t.UndefinedC, t.Type]>; -}>; -export declare const AccountClaimType: t.Type<{ - type: ClaimTypes.ACCOUNT; - timestamp: number; - address: string; - publicKey: string | undefined; -}, any, unknown>; -export type AccountClaim = t.TypeOf; -export declare const createAccountClaim: (address: string, publicKey?: string) => AccountClaim; diff --git a/packages/sdk/metadata-claims/lib/account.js b/packages/sdk/metadata-claims/lib/account.js deleted file mode 100644 index 5363a4440..000000000 --- a/packages/sdk/metadata-claims/lib/account.js +++ /dev/null @@ -1,66 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.createAccountClaim = exports.AccountClaimType = exports.AccountClaimTypeH = void 0; -const address_1 = require("@celo/utils/lib/address"); -const io_1 = require("@celo/utils/lib/io"); -const Either_1 = require("fp-ts/lib/Either"); -const t = __importStar(require("io-ts")); -const types_1 = require("./types"); -/** - * - * Provide the type minus the validation that the public key and address are derived from the same private key - */ -exports.AccountClaimTypeH = t.type({ - type: t.literal(types_1.ClaimTypes.ACCOUNT), - timestamp: types_1.TimestampType, - address: io_1.AddressType, - // io-ts way of defining optional key-value pair - publicKey: t.union([t.undefined, io_1.PublicKeyType]), -}); -exports.AccountClaimType = new t.Type('AccountClaimType', exports.AccountClaimTypeH.is, (unknownValue, context) => Either_1.either.chain(exports.AccountClaimTypeH.validate(unknownValue, context), (claim) => { - if (claim.publicKey === undefined) { - return t.success(claim); - } - const derivedAddress = (0, address_1.publicKeyToAddress)(claim.publicKey); - return derivedAddress === claim.address - ? t.success(claim) - : t.failure(claim, context, 'public key did not match the address in the claim'); -}), (x) => x); -const createAccountClaim = (address, publicKey) => { - const claim = { - timestamp: (0, types_1.now)(), - type: types_1.ClaimTypes.ACCOUNT, - address, - publicKey, - }; - const parsedClaim = exports.AccountClaimType.decode(claim); - if ((0, Either_1.isLeft)(parsedClaim)) { - throw new Error(`A valid claim could not be created`); - } - return parsedClaim.right; -}; -exports.createAccountClaim = createAccountClaim; -//# sourceMappingURL=account.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/account.js.map b/packages/sdk/metadata-claims/lib/account.js.map deleted file mode 100644 index a132a0119..000000000 --- a/packages/sdk/metadata-claims/lib/account.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA4D;AAC5D,2CAA+D;AAC/D,6CAAiD;AACjD,y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AW,GAAG,wBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAElD,IAAI,IAAA,eAAM,EAAC,WAAW,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IACvD,CAAC;IAED,OAAO,WAAW,CAAC,KAAK,CAAA;AAC1B,CAAC,CAAA;AAfY,QAAA,kBAAkB,sBAe9B"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/claim.d.ts b/packages/sdk/metadata-claims/lib/claim.d.ts deleted file mode 100644 index 2f53fd188..000000000 --- a/packages/sdk/metadata-claims/lib/claim.d.ts +++ /dev/null @@ -1,89 +0,0 @@ -import * as t from 'io-ts'; -import { AccountClaim } from './account'; -import { ClaimTypes } from './types'; -export declare const KeybaseClaimType: t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - username: t.StringC; -}>; -export type KeybaseClaim = t.TypeOf; -declare const DomainClaimType: t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - domain: t.StringC; -}>; -declare const NameClaimType: t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - name: t.StringC; -}>; -declare const StorageClaimType: t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - address: t.StringC; - filteredDataPaths: t.StringC; -}>; -export declare const ClaimType: t.UnionC<[t.Type<{ - type: ClaimTypes.ACCOUNT; - timestamp: number; - address: string; - publicKey: string | undefined; -}, any, unknown>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - domain: t.StringC; -}>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - username: t.StringC; -}>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - name: t.StringC; -}>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - address: t.StringC; - filteredDataPaths: t.StringC; -}>]>; -export declare const SignedClaimType: t.TypeC<{ - claim: t.UnionC<[t.Type<{ - type: ClaimTypes.ACCOUNT; - timestamp: number; - address: string; - publicKey: string | undefined; - }, any, unknown>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - domain: t.StringC; - }>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - username: t.StringC; - }>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - name: t.StringC; - }>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - address: t.StringC; - filteredDataPaths: t.StringC; - }>]>; - signature: t.StringC; -}>; -export declare const DOMAIN_TXT_HEADER = "celo-site-verification"; -export type DomainClaim = t.TypeOf; -export type NameClaim = t.TypeOf; -export type StorageClaim = t.TypeOf; -export type Claim = DomainClaim | KeybaseClaim | NameClaim | AccountClaim | StorageClaim; -export type ClaimPayload = K extends typeof ClaimTypes.DOMAIN ? DomainClaim : K extends typeof ClaimTypes.NAME ? NameClaim : K extends typeof ClaimTypes.KEYBASE ? KeybaseClaim : K extends typeof ClaimTypes.ACCOUNT ? AccountClaim : StorageClaim; -/** @internal */ -export declare const isOfType: (type: K) => (data: Claim) => data is ClaimPayload; -export declare function hashOfClaim(claim: Claim): string; -export declare function hashOfClaims(claims: Claim[]): string; -export declare function serializeClaim(claim: Claim): string; -export declare const createNameClaim: (name: string) => NameClaim; -export declare const createDomainClaim: (domain: string) => DomainClaim; -export declare const createStorageClaim: (storageURL: string) => StorageClaim; -export {}; diff --git a/packages/sdk/metadata-claims/lib/claim.js b/packages/sdk/metadata-claims/lib/claim.js deleted file mode 100644 index 09e271edd..000000000 --- a/packages/sdk/metadata-claims/lib/claim.js +++ /dev/null @@ -1,100 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.createStorageClaim = exports.createDomainClaim = exports.createNameClaim = exports.serializeClaim = exports.hashOfClaims = exports.hashOfClaim = exports.isOfType = exports.DOMAIN_TXT_HEADER = exports.SignedClaimType = exports.ClaimType = exports.KeybaseClaimType = void 0; -const signatureUtils_1 = require("@celo/utils/lib/signatureUtils"); -const t = __importStar(require("io-ts")); -const account_1 = require("./account"); -const types_1 = require("./types"); -exports.KeybaseClaimType = t.type({ - type: t.literal(types_1.ClaimTypes.KEYBASE), - timestamp: types_1.TimestampType, - // TODO: Validate compliant username before just interpolating - username: t.string, -}); -const DomainClaimType = t.type({ - type: t.literal(types_1.ClaimTypes.DOMAIN), - timestamp: types_1.TimestampType, - domain: t.string, -}); -const NameClaimType = t.type({ - type: t.literal(types_1.ClaimTypes.NAME), - timestamp: types_1.TimestampType, - name: t.string, -}); -const StorageClaimType = t.type({ - type: t.literal(types_1.ClaimTypes.STORAGE), - timestamp: types_1.TimestampType, - address: t.string, - filteredDataPaths: t.string, -}); -exports.ClaimType = t.union([ - account_1.AccountClaimType, - DomainClaimType, - exports.KeybaseClaimType, - NameClaimType, - StorageClaimType, -]); -exports.SignedClaimType = t.type({ - claim: exports.ClaimType, - signature: types_1.SignatureType, -}); -exports.DOMAIN_TXT_HEADER = 'celo-site-verification'; -/** @internal */ -const isOfType = (type) => (data) => data.type === type; -exports.isOfType = isOfType; -function hashOfClaim(claim) { - return (0, signatureUtils_1.hashMessage)(serializeClaim(claim)); -} -exports.hashOfClaim = hashOfClaim; -function hashOfClaims(claims) { - const hashes = claims.map(hashOfClaim); - return (0, signatureUtils_1.hashMessage)(hashes.join('')); -} -exports.hashOfClaims = hashOfClaims; -function serializeClaim(claim) { - return JSON.stringify(claim); -} -exports.serializeClaim = serializeClaim; -const createNameClaim = (name) => ({ - name, - timestamp: (0, types_1.now)(), - type: types_1.ClaimTypes.NAME, -}); -exports.createNameClaim = createNameClaim; -const createDomainClaim = (domain) => ({ - domain, - timestamp: (0, types_1.now)(), - type: types_1.ClaimTypes.DOMAIN, -}); -exports.createDomainClaim = createDomainClaim; -const createStorageClaim = (storageURL) => ({ - address: storageURL, - timestamp: (0, types_1.now)(), - type: types_1.ClaimTypes.STORAGE, - filteredDataPaths: '.*', -}); -exports.createStorageClaim = createStorageClaim; -//# sourceMappingURL=claim.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/claim.js.map b/packages/sdk/metadata-claims/lib/claim.js.map deleted file mode 100644 index 22f700491..000000000 --- a/packages/sdk/metadata-claims/lib/claim.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"claim.js","sourceRoot":"","sources":["../src/claim.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mEAA4D;AAC5D,yCAA0B;AAC1B,uCAA0D;AAC1D,mCAAuE;AAE1D,QAAA,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAU,CAAC,OAAO,CAAC;IACnC,SAAS,EAAE,qBAAa;IACxB,8DAA8D;IAC9D,QAAQ,EAAE,CAAC,CAAC,MAAM;CACnB,CAAC,CAAA;AAGF,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC;IAC7B,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAU,CAAC,MAAM,CAAC;IAClC,SAAS,EAAE,qBAAa;IACxB,MAAM,EAAE,CAAC,CAAC,MAAM;CACjB,CAAC,CAAA;AAE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AAC,KAAY;IACzC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC;AAFD,wCAEC;AAEM,MAAM,eAAe,GAAG,CAAC,IAAY,EAAa,EAAE,CAAC,CAAC;IAC3D,IAAI;IACJ,SAAS,EAAE,IAAA,WAAG,GAAE;IAChB,IAAI,EAAE,kBAAU,CAAC,IAAI;CACtB,CAAC,CAAA;AAJW,QAAA,eAAe,mBAI1B;AAEK,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAe,EAAE,CAAC,CAAC;IACjE,MAAM;IACN,SAAS,EAAE,IAAA,WAAG,GAAE;IAChB,IAAI,EAAE,kBAAU,CAAC,MAAM;CACxB,CAAC,CAAA;AAJW,QAAA,iBAAiB,qBAI5B;AAEK,MAAM,kBAAkB,GAAG,CAAC,UAAkB,EAAgB,EAAE,CAAC,CAAC;IACvE,OAAO,EAAE,UAAU;IACnB,SAAS,EAAE,IAAA,WAAG,GAAE;IAChB,IAAI,EAAE,kBAAU,CAAC,OAAO;IACxB,iBAAiB,EAAE,IAAI;CACxB,CAAC,CAAA;AALW,QAAA,kBAAkB,sBAK7B"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/index.d.ts b/packages/sdk/metadata-claims/lib/index.d.ts deleted file mode 100644 index 31b421c8b..000000000 --- a/packages/sdk/metadata-claims/lib/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { Claim, createNameClaim } from './claim'; -export * from './metadata'; diff --git a/packages/sdk/metadata-claims/lib/index.js b/packages/sdk/metadata-claims/lib/index.js deleted file mode 100644 index 3075c7632..000000000 --- a/packages/sdk/metadata-claims/lib/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.createNameClaim = void 0; -var claim_1 = require("./claim"); -Object.defineProperty(exports, "createNameClaim", { enumerable: true, get: function () { return claim_1.createNameClaim; } }); -__exportStar(require("./metadata"), exports); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/index.js.map b/packages/sdk/metadata-claims/lib/index.js.map deleted file mode 100644 index b795a3c59..000000000 --- a/packages/sdk/metadata-claims/lib/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAAgD;AAAhC,wGAAA,eAAe,OAAA;AAC/B,6CAA0B"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/keybase.d.ts b/packages/sdk/metadata-claims/lib/keybase.d.ts deleted file mode 100644 index 5ecb73a92..000000000 --- a/packages/sdk/metadata-claims/lib/keybase.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Address } from '@celo/base/lib/address'; -import { KeybaseClaim } from './claim'; -import { AccountMetadataSignerGetters } from './types'; -export declare const keybaseFilePathToProof = ".well-known/celo/"; -export declare const proofFileName: (address: Address) => string; -export declare const targetURL: (username: string, address: Address) => string; -/** - * - * @remarks - * If verification encounters an error, returns the error message as a string - * otherwise returns undefined when successful - * - * @param accountsInfoGetters - * @param claim - * @param signer - * @returns a human readable string with claims (non)verifiability or undefined - */ -export declare function verifyKeybaseClaim(accountsInfoGetters: AccountMetadataSignerGetters, claim: KeybaseClaim, signer: Address): Promise; -export declare const createKeybaseClaim: (username: string) => KeybaseClaim; diff --git a/packages/sdk/metadata-claims/lib/keybase.js b/packages/sdk/metadata-claims/lib/keybase.js deleted file mode 100644 index b327ca9c8..000000000 --- a/packages/sdk/metadata-claims/lib/keybase.js +++ /dev/null @@ -1,74 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.createKeybaseClaim = exports.verifyKeybaseClaim = exports.targetURL = exports.proofFileName = exports.keybaseFilePathToProof = void 0; -const cross_fetch_1 = __importDefault(require("cross-fetch")); -const Either_1 = require("fp-ts/lib/Either"); -const claim_1 = require("./claim"); -const metadata_1 = require("./metadata"); -const types_1 = require("./types"); -exports.keybaseFilePathToProof = `.well-known/celo/`; -const proofFileName = (address) => `verify-${address}.json`; -exports.proofFileName = proofFileName; -const targetURL = (username, address) => `https://${username}.keybase.pub/${exports.keybaseFilePathToProof}${(0, exports.proofFileName)(address)}`; -exports.targetURL = targetURL; -/** - * - * @remarks - * If verification encounters an error, returns the error message as a string - * otherwise returns undefined when successful - * - * @param accountsInfoGetters - * @param claim - * @param signer - * @returns a human readable string with claims (non)verifiability or undefined - */ -function verifyKeybaseClaim(accountsInfoGetters, claim, signer) { - return __awaiter(this, void 0, void 0, function* () { - try { - const resp = yield (0, cross_fetch_1.default)((0, exports.targetURL)(claim.username, signer)); - if (!resp.ok) { - return `Proof of ownership could not be retrieved at ${(0, exports.targetURL)(claim.username, signer)}, request yielded ${resp.status} status code`; - } - const jsonResp = yield resp.json(); - const parsedClaim = claim_1.SignedClaimType.decode(jsonResp); - if ((0, Either_1.isLeft)(parsedClaim)) { - return 'Claim is incorrectly formatted'; - } - const hasValidSignature = yield metadata_1.IdentityMetadataWrapper.verifySignerForAddress(accountsInfoGetters, (0, claim_1.hashOfClaim)(parsedClaim.right.claim), parsedClaim.right.signature, signer); - if (!hasValidSignature) { - return 'Claim does not contain a valid signature'; - } - const parsedKeybaseClaim = claim_1.KeybaseClaimType.decode(parsedClaim.right.claim); - if ((0, Either_1.isLeft)(parsedKeybaseClaim)) { - return 'Hosted claim is not a Keybase claim'; - } - if (parsedKeybaseClaim.right.username !== claim.username) { - return 'Usernames do not match'; - } - return; - } - catch (error) { - return 'Could not verify Keybase claim: ' + error; - } - }); -} -exports.verifyKeybaseClaim = verifyKeybaseClaim; -const createKeybaseClaim = (username) => ({ - username, - timestamp: (0, types_1.now)(), - type: types_1.ClaimTypes.KEYBASE, -}); -exports.createKeybaseClaim = createKeybaseClaim; -//# sourceMappingURL=keybase.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/keybase.js.map b/packages/sdk/metadata-claims/lib/keybase.js.map deleted file mode 100644 index c916f044f..000000000 --- a/packages/sdk/metadata-claims/lib/keybase.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"keybase.js","sourceRoot":"","sources":["../src/keybase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,8DAA+B;AAC/B,6CAAyC;AACzC,mCAAsF;AACtF,yCAAoD;AACpD,mCAAuE;AAE1D,QAAA,sBAAsB,GAAG,mBAAmB,CAAA;AAClD,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,UAAU,OAAO,OAAO,CAAA;AAA9D,QAAA,aAAa,iBAAiD;AACpE,MAAM,SAAS,GAAG,CAAC,QAAgB,EAAE,OAAgB,EAAE,EAAE,CAC9D,WAAW,QAAQ,gBAAgB,8BAAsB,GAAG,IAAA,qBAAa,EAAC,OA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AAA;YACjC,CAAC;YAED,OAAM;QACR,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,kCAAkC,GAAG,KAAK,CAAA;QACnD,CAAC;IACH,CAAC;CAAA;AA5CD,gDA4CC;AAEM,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAgB,EAAE,CAAC,CAAC;IACrE,QAAQ;IACR,SAAS,EAAE,IAAA,WAAG,GAAE;IAChB,IAAI,EAAE,kBAAU,CAAC,OAAO;CACzB,CAAC,CAAA;AAJW,QAAA,kBAAkB,sBAI7B"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/metadata.d.ts b/packages/sdk/metadata-claims/lib/metadata.d.ts deleted file mode 100644 index ae5bcd7d0..000000000 --- a/packages/sdk/metadata-claims/lib/metadata.d.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { Address } from '@celo/base/lib/address'; -import { Signer } from '@celo/base/lib/signatureUtils'; -import * as t from 'io-ts'; -import { Claim, ClaimPayload } from './claim'; -import { AccountMetadataSignerGetters, ClaimTypes } from './types'; -export { ClaimTypes } from './types'; -type KitOrAccountsWrapper = AccountMetadataSignerGetters; -export declare const IdentityMetadataType: t.TypeC<{ - claims: t.ArrayC, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - domain: t.StringC; - }>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - username: t.StringC; - }>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - name: t.StringC; - }>, t.TypeC<{ - type: t.LiteralC; - timestamp: t.NumberC; - address: t.StringC; - filteredDataPaths: t.StringC; - }>]>>; - meta: t.TypeC<{ - address: t.Type; - signature: t.StringC; - }>; -}>; -export type IdentityMetadata = t.TypeOf; -export declare class IdentityMetadataWrapper { - data: IdentityMetadata; - static fromEmpty(address: Address): IdentityMetadataWrapper; - static fetchFromURL(contractKitOrAccountsWrapper: KitOrAccountsWrapper, url: string, tries?: number): Promise; - static fromFile(contractKitOrAccountsWrapper: KitOrAccountsWrapper, path: string): Promise; - static verifySigner(contractKitOrAccountsWrapper: KitOrAccountsWrapper, hash: any, signature: any, metadata: any): Promise; - static verifySignerForAddress(contractKitOrAccountsWrapper: KitOrAccountsWrapper, hash: any, signature: any, address: Address): Promise; - static fromRawString(contractKitOrAccountsWrapper: KitOrAccountsWrapper, rawData: string): Promise; - constructor(data: IdentityMetadata); - get claims(): ({ - type: ClaimTypes.ACCOUNT; - timestamp: number; - address: string; - publicKey: string | undefined; - } | { - type: ClaimTypes.KEYBASE; - timestamp: number; - username: string; - } | { - type: ClaimTypes.DOMAIN; - timestamp: number; - domain: string; - } | { - type: ClaimTypes.NAME; - timestamp: number; - name: string; - } | { - type: ClaimTypes.STORAGE; - timestamp: number; - address: string; - filteredDataPaths: string; - })[]; - hashOfClaims(): string; - toString(): string; - addClaim(claim: Claim, signer: Signer): Promise; - findClaim(type: K): ClaimPayload | undefined; - filterClaims(type: K): ClaimPayload[]; -} diff --git a/packages/sdk/metadata-claims/lib/metadata.js b/packages/sdk/metadata-claims/lib/metadata.js deleted file mode 100644 index 41bbfe0f5..000000000 --- a/packages/sdk/metadata-claims/lib/metadata.js +++ /dev/null @@ -1,212 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.IdentityMetadataWrapper = exports.IdentityMetadataType = exports.ClaimTypes = void 0; -const address_1 = require("@celo/base/lib/address"); -const async_1 = require("@celo/base/lib/async"); -const io_1 = require("@celo/utils/lib/io"); -const signatureUtils_1 = require("@celo/utils/lib/signatureUtils"); -const cross_fetch_1 = __importDefault(require("cross-fetch")); -const Either_1 = require("fp-ts/lib/Either"); -const t = __importStar(require("io-ts")); -const PathReporter_1 = require("io-ts/lib/PathReporter"); -const claim_1 = require("./claim"); -const types_1 = require("./types"); -var types_2 = require("./types"); -Object.defineProperty(exports, "ClaimTypes", { enumerable: true, get: function () { return types_2.ClaimTypes; } }); -const MetaType = t.type({ - address: io_1.AddressType, - signature: io_1.SignatureType, -}); -exports.IdentityMetadataType = t.type({ - claims: t.array(claim_1.ClaimType), - meta: MetaType, -}); -class IdentityMetadataWrapper { - static fromEmpty(address) { - return new IdentityMetadataWrapper({ - claims: [], - meta: { - address, - signature: '', - }, - }); - } - static fetchFromURL(contractKitOrAccountsWrapper, url, tries = 3) { - return __awaiter(this, void 0, void 0, function* () { - return (0, async_1.selectiveRetryAsyncWithBackOff)(() => __awaiter(this, void 0, void 0, function* () { - const resp = yield (0, cross_fetch_1.default)(url); - if (!resp.ok) { - throw new Error(`Request failed with status ${resp.status}`); - } - return this.fromRawString(contractKitOrAccountsWrapper, yield resp.text()); - }), tries, ['Request failed with status 404'], []); - }); - } - static fromFile(contractKitOrAccountsWrapper, path) { - let readFileSync; - try { - const fs = require('fs'); - readFileSync = fs.readFileSync; - } - catch (_a) { - console.error('cant read from file in browser or environment without native fs module'); - } - return this.fromRawString(contractKitOrAccountsWrapper, readFileSync(path, 'utf-8')); - } - static verifySigner(contractKitOrAccountsWrapper, hash, signature, metadata) { - return __awaiter(this, void 0, void 0, function* () { - return this.verifySignerForAddress(contractKitOrAccountsWrapper, hash, signature, metadata.address); - }); - } - static verifySignerForAddress(contractKitOrAccountsWrapper, hash, signature, address) { - return __awaiter(this, void 0, void 0, function* () { - // First try to verify on account's address - if (!(0, signatureUtils_1.verifySignature)(hash, signature, address)) { - const accounts = yield getAccounts(contractKitOrAccountsWrapper); - // If this fails, signature may still be one of `address`' signers - if (yield accounts.isAccount(address)) { - const signers = yield Promise.all([ - accounts.getVoteSigner(address), - accounts.getValidatorSigner(address), - accounts.getAttestationSigner(address), - ]); - return signers.some((signer) => (0, signatureUtils_1.verifySignature)(hash, signature, signer)); - } - return false; - } - return true; - }); - } - static fromRawString(contractKitOrAccountsWrapper, rawData) { - return __awaiter(this, void 0, void 0, function* () { - const data = JSON.parse(rawData); - const validatedData = exports.IdentityMetadataType.decode(data); - if ((0, Either_1.isLeft)(validatedData)) { - // TODO: We could probably return a more useful error in the future - throw new Error(PathReporter_1.PathReporter.report(validatedData).join(', ')); - } - // Verify signature on the data - const claims = validatedData.right.claims; - const hash = (0, claim_1.hashOfClaims)(claims); - if (claims.length > 0 && - !(yield this.verifySigner(contractKitOrAccountsWrapper, hash, validatedData.right.meta.signature, validatedData.right.meta))) { - throw new Error(`Signature could not be validated. Guessing signer: ${(0, signatureUtils_1.guessSigner)(hash, validatedData.right.meta.signature)}`); - } - const res = new IdentityMetadataWrapper(validatedData.right); - // Verify that singular claim types appear at most once - types_1.SINGULAR_CLAIM_TYPES.forEach((claimType) => { - const results = res.filterClaims(claimType); - if (results.length > 1) { - throw new Error(`Found ${results.length} claims of type ${claimType}, should be at most 1`); - } - }); - return res; - }); - } - constructor(data) { - this.data = data; - } - get claims() { - return this.data.claims; - } - hashOfClaims() { - return (0, claim_1.hashOfClaims)(this.data.claims); - } - toString() { - return JSON.stringify({ - claims: this.data.claims, - meta: this.data.meta, - }); - } - addClaim(claim, signer) { - return __awaiter(this, void 0, void 0, function* () { - switch (claim.type) { - case types_1.ClaimTypes.ACCOUNT: - if ((0, address_1.eqAddress)(claim.address, this.data.meta.address)) { - throw new Error("Can't claim self"); - } - break; - case types_1.ClaimTypes.DOMAIN: { - const existingClaims = this.data.claims.filter((el) => el.domain === claim.domain); - if (existingClaims.length > 0) { - return existingClaims[0]; - } - break; - } - case types_1.ClaimTypes.KEYBASE: { - const existingClaims = this.data.claims.filter((el) => el.username === claim.username); - if (existingClaims.length > 0) { - return existingClaims[0]; - } - } - default: - break; - } - if (types_1.SINGULAR_CLAIM_TYPES.includes(claim.type)) { - const index = this.data.claims.findIndex((0, claim_1.isOfType)(claim.type)); - if (index !== -1) { - this.data.claims.splice(index, 1); - } - } - this.data.claims.push(claim); - this.data.meta.signature = yield signer.sign(this.hashOfClaims()); - return claim; - }); - } - findClaim(type) { - return this.data.claims.find((0, claim_1.isOfType)(type)); - } - filterClaims(type) { - return this.data.claims.filter((0, claim_1.isOfType)(type)); - } -} -exports.IdentityMetadataWrapper = IdentityMetadataWrapper; -// at first these functions required a `kit` but thats a bit heavy -// as all that is used are functions on the accounts contract so allow just those functions to be passed -function getAccounts(contractKitOrAccountsWrapper) { - return __awaiter(this, void 0, void 0, function* () { - if ('getVoteSigner' in contractKitOrAccountsWrapper && - 'isAccount' in contractKitOrAccountsWrapper && - 'getValidatorSigner' in contractKitOrAccountsWrapper && - 'getAttestationSigner' in contractKitOrAccountsWrapper) { - return contractKitOrAccountsWrapper; - } - throw new Error(`Must pass object with the required functions: getVoteSigner, isAccount, getValidatorSigner, getAttestationSigner. Received ${JSON.stringify(contractKitOrAccountsWrapper)}`); - }); -} -//# sourceMappingURL=metadata.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/metadata.js.map b/packages/sdk/metadata-claims/lib/metadata.js.map deleted file mode 100644 index 8d8b4654a..000000000 --- a/packages/sdk/metadata-claims/lib/metadata.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA2D;AAC3D,gDAAqE;AAErE,2CAA+D;AAC/D,mEAA6E;AAC7E,8DAA+B;AAC/B,6CAAyC;AACzC,yCAA0B;AAC1B,yDAAqD;AACrD,mCAAgF;AAChF,mCAKgB;AAEhB,iCAAoC;AAA3B,mGAAA,UAAU,OAAA;AAInB,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC;IACtB,OAAO,EAAE,gBAAW;IACpB,SAAS,EAAE,kBAAa;CACzB,CAAC,CAAA;AAEW,QAAA,oBAAoB,GAAG,CAAC,CAAC,IAAI,CAAC;IACzC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,iBAAS,CAAC;IAC1B,IAAI,EAAE,QAAQ;CACf,CAAC,CAAA;AAIF,MAAa,uBAAuB;IAGlC,MAAM,CAAC,SAAS,CAAC,OAAgB;QAC/B,OAAO,IAAI,uBAAuB,CAAC;YACjC,MAAM,EAAE,EAAE;YACV,IAAI,EAAE;gBACJ,OAAO;gBACP,SAAS,EAAE,EAAE;aACd;SACF,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,CAAO,YAAY,CACvB,4BAAkD,EAClD,GAAW,EACX,KAAK,GAAG,CAAC;;YAET,OAAO,IAAA,sCAA8B,EACnC,GAAS,EAAE;gBACT,MAAM,IAAI,GAAG,MAAM,IAAA,qBAAK,EAAC,GAAG,CAAC,CAAA;gBAC7B,IAAI,CAAC,IAAI,CAAC,EAAE,E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AAC,YAAY,EAAE,CAAC,CAAA;YACjE,OAAO,KAAK,CAAA;QACd,CAAC;KAAA;IAED,SAAS,CAAuB,IAAO;QACrC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,CAAA;IAC9C,CAAC;IAED,YAAY,CAAuB,IAAO;QACxC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,CAAA;IAChD,CAAC;CACF;AAzLD,0DAyLC;AAED,kEAAkE;AAClE,wGAAwG;AACxG,SAAe,WAAW,CACxB,4BAAkD;;QAElD,IACE,eAAe,IAAI,4BAA4B;YAC/C,WAAW,IAAI,4BAA4B;YAC3C,oBAAoB,IAAI,4BAA4B;YACpD,sBAAsB,IAAI,4BAA4B,EACtD,CAAC;YACD,OAAO,4BAA4B,CAAA;QACrC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,8HAA8H,IAAI,CAAC,SAAS,CAC1I,4BAA4B,CAC7B,EAAE,CACJ,CAAA;IACH,CAAC;CAAA"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/types.d.ts b/packages/sdk/metadata-claims/lib/types.d.ts deleted file mode 100644 index d21e1e654..000000000 --- a/packages/sdk/metadata-claims/lib/types.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -import * as t from 'io-ts'; -import type { Address, StrongAddress } from '@celo/base/lib/address'; -export declare const SignatureType: t.StringC; -export declare const TimestampType: t.NumberC; -/** @internal */ -export declare const now: () => number; -export declare enum ClaimTypes { - ACCOUNT = "ACCOUNT", - DOMAIN = "DOMAIN", - KEYBASE = "KEYBASE", - NAME = "NAME", - PROFILE_PICTURE = "PROFILE_PICTURE", - STORAGE = "STORAGE", - TWITTER = "TWITTER" -} -export declare const VERIFIABLE_CLAIM_TYPES: ClaimTypes[]; -export declare const SINGULAR_CLAIM_TYPES: ClaimTypes[]; -export type AccountSignerGetters = { - isAccount: (address: Address) => Promise; - getVoteSigner: (address: Address) => Promise; - getValidatorSigner: (address: Address) => Promise; - getAttestationSigner: (address: Address) => Promise; -}; -export type AccountMetadataSignerGetters = { - getMetadataURL: (address: string) => Promise; -} & AccountSignerGetters; diff --git a/packages/sdk/metadata-claims/lib/types.js b/packages/sdk/metadata-claims/lib/types.js deleted file mode 100644 index 4058c986c..000000000 --- a/packages/sdk/metadata-claims/lib/types.js +++ /dev/null @@ -1,45 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SINGULAR_CLAIM_TYPES = exports.VERIFIABLE_CLAIM_TYPES = exports.ClaimTypes = exports.now = exports.TimestampType = exports.SignatureType = void 0; -const t = __importStar(require("io-ts")); -exports.SignatureType = t.string; -exports.TimestampType = t.number; -/** @internal */ -const now = () => Math.round(new Date().getTime() / 1000); -exports.now = now; -var ClaimTypes; -(function (ClaimTypes) { - ClaimTypes["ACCOUNT"] = "ACCOUNT"; - ClaimTypes["DOMAIN"] = "DOMAIN"; - ClaimTypes["KEYBASE"] = "KEYBASE"; - ClaimTypes["NAME"] = "NAME"; - ClaimTypes["PROFILE_PICTURE"] = "PROFILE_PICTURE"; - ClaimTypes["STORAGE"] = "STORAGE"; - ClaimTypes["TWITTER"] = "TWITTER"; -})(ClaimTypes || (exports.ClaimTypes = ClaimTypes = {})); -exports.VERIFIABLE_CLAIM_TYPES = [ClaimTypes.KEYBASE, ClaimTypes.ACCOUNT, ClaimTypes.DOMAIN]; -exports.SINGULAR_CLAIM_TYPES = [ClaimTypes.NAME]; -//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/types.js.map b/packages/sdk/metadata-claims/lib/types.js.map deleted file mode 100644 index 9deb63c88..000000000 --- a/packages/sdk/metadata-claims/lib/types.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA0B;AAIb,QAAA,aAAa,GAAG,CAAC,CAAC,MAAM,CAAA;AACxB,QAAA,aAAa,GAAG,CAAC,CAAC,MAAM,CAAA;AAErC,gBAAgB;AACT,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;AAAnD,QAAA,GAAG,OAAgD;AAEhE,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,iCAAmB,CAAA;IACnB,+BAAiB,CAAA;IACjB,iCAAmB,CAAA;IACnB,2BAAa,CAAA;IACb,iDAAmC,CAAA;IACnC,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;AACrB,CAAC,EARW,UAAU,0BAAV,UAAU,QAQrB;AAEY,QAAA,sBAAsB,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;AACpF,QAAA,oBAAoB,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/verify.d.ts b/packages/sdk/metadata-claims/lib/verify.d.ts deleted file mode 100644 index 6a87b4489..000000000 --- a/packages/sdk/metadata-claims/lib/verify.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -/// -import { AccountClaim } from './account'; -import { Claim, DomainClaim } from './claim'; -import { AccountMetadataSignerGetters } from './types'; -/** - * Verifies a claim made by an account, i.e. whether a claim can be verified to be correct - * @param kit AccountMetadataSignerGetters object - * @param claim The claim to verify - * @param address The address that is making the claim - * @returns If valid, returns undefined. If invalid or unable to verify, returns a string with the error - */ -export declare function verifyClaim(accountMeta: AccountMetadataSignerGetters, claim: Claim, address: string, tries?: number): Promise; -export declare const verifyAccountClaim: (accountMeta: AccountMetadataSignerGetters, claim: AccountClaim, address: string, tries?: number) => Promise; -type dnsResolverFunction = (hostname: string, callback: (err: NodeJS.ErrnoException, addresses: string[][]) => void) => void; -/** - * It verifies if a DNS domain includes in the TXT records an entry with name - * `celo-site-verification` and a valid signature in base64 - */ -export declare const verifyDomainRecord: (accountMeta: AccountMetadataSignerGetters, claim: DomainClaim, address: string, dnsResolver?: dnsResolverFunction) => Promise; -export {}; diff --git a/packages/sdk/metadata-claims/lib/verify.js b/packages/sdk/metadata-claims/lib/verify.js deleted file mode 100644 index 0b8fa8f1f..000000000 --- a/packages/sdk/metadata-claims/lib/verify.js +++ /dev/null @@ -1,89 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.verifyDomainRecord = exports.verifyAccountClaim = exports.verifyClaim = void 0; -const address_1 = require("@celo/base/lib/address"); -const io_1 = require("@celo/base/lib/io"); -const node_dns_1 = require("node:dns"); // TODO replace with non node specifc package -const node_util_1 = require("node:util"); // TODO replace with non node specifc package -const claim_1 = require("./claim"); -const keybase_1 = require("./keybase"); -const metadata_1 = require("./metadata"); -const types_1 = require("./types"); -/** - * Verifies a claim made by an account, i.e. whether a claim can be verified to be correct - * @param kit AccountMetadataSignerGetters object - * @param claim The claim to verify - * @param address The address that is making the claim - * @returns If valid, returns undefined. If invalid or unable to verify, returns a string with the error - */ -function verifyClaim(accountMeta, claim, address, tries = 3) { - return __awaiter(this, void 0, void 0, function* () { - switch (claim.type) { - case types_1.ClaimTypes.KEYBASE: - return (0, keybase_1.verifyKeybaseClaim)(accountMeta, claim, address); - case types_1.ClaimTypes.ACCOUNT: - return (0, exports.verifyAccountClaim)(accountMeta, claim, address, tries); - case types_1.ClaimTypes.DOMAIN: - return (0, exports.verifyDomainRecord)(accountMeta, claim, address); - default: - break; - } - return; - }); -} -exports.verifyClaim = verifyClaim; -const verifyAccountClaim = (accountMeta, claim, address, tries = 3) => __awaiter(void 0, void 0, void 0, function* () { - const metadataURL = yield accountMeta.getMetadataURL(claim.address); - if (!(0, io_1.isValidUrl)(metadataURL)) { - return `Metadata URL of ${claim.address} could not be retrieved`; - } - let metadata; - try { - metadata = yield metadata_1.IdentityMetadataWrapper.fetchFromURL(accountMeta, metadataURL, tries); - } - catch (error) { - return `Metadata could not be fetched for ${claim.address} at ${metadataURL}: ${error.toString()}`; - } - const accountClaims = metadata.filterClaims(types_1.ClaimTypes.ACCOUNT); - if (accountClaims.find((x) => (0, address_1.eqAddress)(x.address, address)) === undefined) { - return `${claim.address} did not claim ${address}`; - } - return; -}); -exports.verifyAccountClaim = verifyAccountClaim; -/** - * It verifies if a DNS domain includes in the TXT records an entry with name - * `celo-site-verification` and a valid signature in base64 - */ -const verifyDomainRecord = (accountMeta, claim, address, dnsResolver = node_dns_1.resolveTxt) => __awaiter(void 0, void 0, void 0, function* () { - try { - const getRecords = (0, node_util_1.promisify)(dnsResolver); - const domainRecords = yield getRecords(claim.domain); - for (const record of domainRecords) { - for (const entry of record) { - if (entry.startsWith(claim_1.DOMAIN_TXT_HEADER)) { - const signatureBase64 = entry.substring(claim_1.DOMAIN_TXT_HEADER.length + 1); - const signature = Buffer.from(signatureBase64, 'base64').toString('binary'); - if (yield metadata_1.IdentityMetadataWrapper.verifySignerForAddress(accountMeta, (0, claim_1.serializeClaim)(claim), signature, address)) { - return; - } - } - } - } - return `Unable to verify domain claim with address ${address}`; - } - catch (error) { - return `Unable to fetch domain TXT records: ${error.toString()}`; - } -}); -exports.verifyDomainRecord = verifyDomainRecord; -//# sourceMappingURL=verify.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/verify.js.map b/packages/sdk/metadata-claims/lib/verify.js.map deleted file mode 100644 index 5f301444a..000000000 --- a/packages/sdk/metadata-claims/lib/verify.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkD;AAClD,0CAA8C;AAC9C,uCAAqC,CAAC,6CAA6C;AACnF,yCAAqC,CAAC,6CAA6C;AAEnF,mCAA+E;AAC/E,uCAA8C;AAC9C,yCAAoD;AACpD,mCAAkE;AAElE;;;;;;GAMG;AACH,SAAsB,WAAW,CAC/B,WAAyC,EACzC,KAAY,EACZ,OAAe,EACf,KAAK,GAAG,CAAC;;QAET,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,kBAAU,CAAC,OAAO;gBACrB,OAAO,IAAA,4BAAkB,EAAC,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;YACxD,KAAK,kBAAU,CAAC,OAAO;gBACrB,OAAO,IAAA,0BAAkB,EAAC,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CA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AmC,qBAAiB,EACpD,EAAE;IACF,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,IAAA,qBAAS,EAAC,WAAW,CAAC,CAAA;QACzC,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACpD,KAAK,MAAM,MAAM,IAAI,aAAa,EAAE,CAAC;YACnC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,IAAI,KAAK,CAAC,UAAU,CAAC,yBAAiB,CAAC,EAAE,CAAC;oBACxC,MAAM,eAAe,GAAG,KAAK,CAAC,SAAS,CAAC,yBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;oBACrE,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;oBAC3E,IACE,MAAM,kCAAuB,CAAC,sBAAsB,CAClD,WAAW,EACX,IAAA,sBAAc,EAAC,KAAK,CAAC,EACrB,SAAS,EACT,OAAO,CACR,EACD,CAAC;wBACD,OAAM;oBACR,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,8CAA8C,OAAO,EAAE,CAAA;IAChE,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,uCAAuC,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAA;IAClE,CAAC;AACH,CAAC,CAAA,CAAA;AA/BY,QAAA,kBAAkB,sBA+B9B"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/src/claim.ts b/packages/sdk/metadata-claims/src/claim.ts index 71b157beb..7950dc5c4 100644 --- a/packages/sdk/metadata-claims/src/claim.ts +++ b/packages/sdk/metadata-claims/src/claim.ts @@ -17,6 +17,12 @@ const DomainClaimType = t.type({ domain: t.string, }) +const RpcUrlClaimType = t.type({ + type: t.literal(ClaimTypes.RPC_URL), + timestamp: TimestampType, + rpcUrl: t.string, +}) + const NameClaimType = t.type({ type: t.literal(ClaimTypes.NAME), timestamp: TimestampType, @@ -33,6 +39,7 @@ const StorageClaimType = t.type({ export const ClaimType = t.union([ AccountClaimType, DomainClaimType, + RpcUrlClaimType, KeybaseClaimType, NameClaimType, StorageClaimType, @@ -45,12 +52,21 @@ export const SignedClaimType = t.type({ export const DOMAIN_TXT_HEADER = 'celo-site-verification' export type DomainClaim = t.TypeOf +export type RpcUrlClaim = t.TypeOf export type NameClaim = t.TypeOf export type StorageClaim = t.TypeOf -export type Claim = DomainClaim | KeybaseClaim | NameClaim | AccountClaim | StorageClaim +export type Claim = + | DomainClaim + | RpcUrlClaim + | KeybaseClaim + | NameClaim + | AccountClaim + | StorageClaim export type ClaimPayload = K extends typeof ClaimTypes.DOMAIN ? DomainClaim + : K extends typeof ClaimTypes.RPC_URL + ? RpcUrlClaim : K extends typeof ClaimTypes.NAME ? NameClaim : K extends typeof ClaimTypes.KEYBASE @@ -90,6 +106,12 @@ export const createDomainClaim = (domain: string): DomainClaim => ({ type: ClaimTypes.DOMAIN, }) +export const createRpcUrlClaim = (rpcUrl: string): RpcUrlClaim => ({ + rpcUrl, + timestamp: now(), + type: ClaimTypes.RPC_URL, +}) + export const createStorageClaim = (storageURL: string): StorageClaim => ({ address: storageURL, timestamp: now(), diff --git a/packages/sdk/metadata-claims/src/metadata.ts b/packages/sdk/metadata-claims/src/metadata.ts index e02fb20be..1d4b2bea3 100644 --- a/packages/sdk/metadata-claims/src/metadata.ts +++ b/packages/sdk/metadata-claims/src/metadata.ts @@ -187,6 +187,13 @@ export class IdentityMetadataWrapper { } break } + case ClaimTypes.RPC_URL: { + const existingClaims = this.data.claims.filter((el: any) => el.rpcUrl === claim.rpcUrl) + if (existingClaims.length > 0) { + return existingClaims[0] + } + break + } case ClaimTypes.KEYBASE: { const existingClaims = this.data.claims.filter((el: any) => el.username === claim.username) if (existingClaims.length > 0) { diff --git a/packages/sdk/metadata-claims/src/types.ts b/packages/sdk/metadata-claims/src/types.ts index 17aa3d492..c26553cb3 100644 --- a/packages/sdk/metadata-claims/src/types.ts +++ b/packages/sdk/metadata-claims/src/types.ts @@ -11,6 +11,7 @@ export const now = () => Math.round(new Date().getTime() / 1000) export enum ClaimTypes { ACCOUNT = 'ACCOUNT', DOMAIN = 'DOMAIN', + RPC_URL = 'RPC_URL', KEYBASE = 'KEYBASE', NAME = 'NAME', PROFILE_PICTURE = 'PROFILE_PICTURE',