Skip to content

Commit

Permalink
Merge pull request #64 from lens-protocol/feat/sign-message
Browse files Browse the repository at this point in the history
feat: adds signMetadata and lensMessage helpers
  • Loading branch information
cesarenaldi committed May 8, 2024
2 parents 1a89cb6 + 281fbe2 commit e78716a
Show file tree
Hide file tree
Showing 25 changed files with 175 additions and 46 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-turkeys-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lens-protocol/metadata': minor
---

**feat:** adds `signMetadata` and `lensMessage` helpers
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"@jest/globals": "^29.7.0",
"@lens-protocol/client": "2.0.0-alpha.25",
"@types/fs-extra": "^11.0.1",
"@types/json-stable-stringify": "^1.0.36",
"@types/node": "^20.5.0",
"@types/uuid": "^9.0.4",
"@typescript-eslint/eslint-plugin": "^6.4.0",
Expand Down Expand Up @@ -106,6 +107,7 @@
},
"packageManager": "pnpm@8.2.0",
"dependencies": {
"json-stable-stringify": "^1.1.1",
"uuid": "^9.0.1"
},
"pnpm": {
Expand Down
96 changes: 86 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions src/__tests__/signMetadata.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, it } from '@jest/globals';
import { Wallet } from 'ethers';

const signer = new Wallet('0xd6e6257e8cf0f321ad0f798dd0b121a7eb4fe9c7c51994e843c0a1ed05867a5f');

import { MetadataAttributeType } from '../MetadataAttribute';
import { textOnly } from '../builders';
import { signMetadata } from '../signMetadata.js';

describe(`Given the ${signMetadata.name} function`, () => {
describe('when called on PublicationMetadata', () => {
it('should return signed metadata with simple flat metadata', async () => {
const metadata = textOnly({
content: 'Hello, world!',
id: '42',
attributes: [
{
key: 'string',
value: 'value',
type: MetadataAttributeType.STRING,
},
{
key: 'boolean',
value: 'true',
type: MetadataAttributeType.BOOLEAN,
},
],
});

const signed = await signMetadata(metadata, (message) => signer.signMessage(message));

expect(signed).toHaveProperty(
'signature',
'0x28e8944e5ec1ab1cce78ead972262af4e2e0148d7f8eabf36ff03ff827021b685c3858b8e34caef13a932fb992a856a41f9f0a9107d3440dbca52ec4101aca761b',
);
});
});
});
2 changes: 1 addition & 1 deletion src/builders/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export type AdvancedContractConditionDetails = {

/**
* The function ABI. Has to be in a human-readable string format, which you can convert using the ethers library.
* See here for more info https://docs.ethers.io/v5/api/utils/abi/fragments/#human-readable-abi
* See here for more info https://docs.ethers.org/v5/api/utils/abi/formats/#abi-formats--human-readable-abi
*/
abi: string;

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export * from './module/index.js';
export * from './primitives.js';
export * from './profile/index.js';
export * from './publication/index.js';
export * from './signMetadata.js';
export type { Brand, DistributiveOmit, Overwrite, Prettify, TwoAtLeastArray } from './utils.js';
2 changes: 0 additions & 2 deletions src/profile/ProfileMetadataSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ export type ProfileMetadata = {
lens: ProfileMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
2 changes: 0 additions & 2 deletions src/publication/3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ export type ThreeDMetadata = MarketplaceMetadata & {
lens: ThreeDMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
2 changes: 0 additions & 2 deletions src/publication/ArticleSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ export type ArticleMetadata = MarketplaceMetadata & {
lens: ArticleMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
2 changes: 0 additions & 2 deletions src/publication/AudioSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export type AudioMetadata = MarketplaceMetadata & {
lens: AudioMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
2 changes: 0 additions & 2 deletions src/publication/CheckingInSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ export type CheckingInMetadata = MarketplaceMetadata & {
lens: CheckingInMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
2 changes: 0 additions & 2 deletions src/publication/EmbedSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ export type EmbedMetadata = MarketplaceMetadata & {
lens: EmbedMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
2 changes: 0 additions & 2 deletions src/publication/EventSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ export type EventMetadata = MarketplaceMetadata & {
lens: EventMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
2 changes: 0 additions & 2 deletions src/publication/ImageSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export type ImageMetadata = MarketplaceMetadata & {
lens: ImageMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
2 changes: 0 additions & 2 deletions src/publication/LinkSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ export type LinkMetadata = MarketplaceMetadata & {
lens: LinkMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
2 changes: 0 additions & 2 deletions src/publication/LiveStreamSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ export type LiveStreamMetadata = MarketplaceMetadata & {
lens: LiveStreamMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
2 changes: 0 additions & 2 deletions src/publication/MintSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export type MintMetadata = MarketplaceMetadata & {
lens: MintMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*
* @experimental DO NOT use yet
*/
signature?: Signature;
};
Expand Down
Loading

0 comments on commit e78716a

Please sign in to comment.