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..c3cc80c8d --- /dev/null +++ b/packages/cli/src/commands/account/claim-rpc-url.ts @@ -0,0 +1,26 @@ +import { createRpcUrlClaim } from '@celo/metadata-claims/lib/claim' +import { Flags } from '@oclif/core' +import { ClaimCommand } from '../../utils/identity' +export default class ClaimRpcUrl extends ClaimCommand { + static description = 'Claim a domain and add the claim to a local metadata file' + static flags = { + ...ClaimCommand.flags, + rpcUrl: Flags.string({ + required: true, + description: 'The RPC URL you want to claim', + }), + } + static args = ClaimCommand.args + static examples = [ + 'claim-rpc-url ~/metadata.json --rpc-url example.com --from 0x5409ED021D9299bf6814279A6A1411A7e866A631', + ] + + 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/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,yCAA0B;AAC1B,mCAAwD;AAExD;;;GAGG;AACU,QAAA,iBAAiB,GAAG,CAAC,CAAC,IAAI,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAU,CAAC,OAAO,CAAC;IACnC,SAAS,EAAE,qBAAa;IACxB,OAAO,EAAE,gBAAW;IACpB,gDAAgD;IAChD,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,kBAAa,CAAC,CAAC;CACjD,CAAC,CAA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im.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;AAEF,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAU,CAAC,IAAI,CAAC;IAChC,SAAS,EAAE,qBAAa;IACxB,IAAI,EAAE,CAAC,CAAC,MAAM;CACf,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC;IAC9B,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAU,CAAC,OAAO,CAAC;IACnC,SAAS,EAA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,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,OAAO,CAAC,EAAE,CAAA;AADzE,QAAA,SAAS,aACgE;AAEtF;;;;;;;;;;GAUG;AAEH,SAAsB,kBAAkB,CACtC,mBAAiD,EACjD,KAAmB,EACnB,MAAe;;QAEf,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAA,qBAAK,EAAC,IAAA,iBAAS,EAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;YAC3D,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;gBACb,OAA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AAA,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":";;;;;;;;;;;;;;;;;;;;;;;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C,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,CAAA;YAC/D,KAAK,kBAAU,CAAC,MAAM;gBACpB,OAAO,IAAA,0BAAkB,EAAC,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;YACxD;gBACE,MAAK;QACT,CAAC;QACD,OAAM;IACR,CAAC;CAAA;AAjBD,kCAiBC;AAEM,MAAM,kBAAkB,GAAG,CAChC,WAAyC,EACzC,KAAmB,EACnB,OAAe,EACf,KAAK,GAAG,CAAC,EACT,EAAE;IACF,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,cA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AE,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',