Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: actions with tx signing #111

Merged
merged 18 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
Expand Down
79 changes: 79 additions & 0 deletions packages/blockchain-sdk-solana/examples/exmple-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Considerations
// 1. Smart message should encapsulate all possible actions, including link and sign transaction - this is needed to be interoperable in different clients
// 2. Multiple actions should be later supported (e.g. both link and sign transaction), based on mockups e.g. https://www.figma.com/file/YMrtyevM6MlWYDZBO2fLb4/Use-Case-Examples?type=design&node-id=1-820&mode=dev
// 3. Single smart message should be produced if multiple actions exist, we should forbid using multiple tx-services in a context of single actionable notif
import { DappMessageActionType, type DappMessageSmartMessageAction } from '@dialectlabs/sdk/src';
import type { TensorNftBuyNowSmartMessage } from '../../sdk-actions-spec';
import type { DappMessages } from '../../sdk/src/';
// @ts-ignore

const dappMessages = (1 as DappMessages);
const tensorSmartMessage: TensorNftBuyNowSmartMessage = {
transactionServiceId: 'tensor-nft-buy',
transactionParams: {
collectionId: 'foo',
mintAddress: 'bar',
owner: 'foo',
price: 'foo',
priceWithFeeAndRoyalty: 'foo',
},
};
const buyNftSmartMessage: DappMessageSmartMessageAction = {
type: DappMessageActionType.SMART_MESSAGE,
smartMessage: tensorSmartMessage,
};
// Examples:
// 1. SENDING SIGN_TRANSACTION ACTIONS, including possible multiple actions
// a) W/O TX_SERVICE_ID NOT ALLOWED
dappMessages.send({
actionsV2: {
type: DappMessageActionType.SMART_MESSAGE,
smartMessage: {
transactionServiceId: 'foo',
transactionParams: {
payer: 'foo',
payee: 'bar',
amount: 'foo',
links: [{
label: 'foo',
url: 'foo',
}],
},
},
},
message: 'foo',
recipient: 'dfs',
});
// b) SINGLE TX_SERVICE ID ALLOWED
dappMessages.send({
actionsV2: buyNftSmartMessage,
message: 'foo',
recipient: 'fds',
});
// 2. SENDING LINK ACTIONS
// a) MULTIPLE W/O TX_SERVICE_ID ARE NOT ALLOWED
dappMessages.send({
actionsV2: {
type: DappMessageActionType.LINK,
links: [{
label: 'foo',
url: 'foo',
}, {
label: 'foo',
url: 'foo',
}],
},
recipients: ['sfd'],
message: 'foo',
});// b) SINGLE link ALLOWED
dappMessages.send({
actionsV2: {
type: DappMessageActionType.LINK,
links: [{
label: 'foo',
url: 'foo',
}],
},
recipients: ['sfd'],
message: 'foo',
});// b) SINGLE link ALLOWED
7 changes: 7 additions & 0 deletions packages/sdk-actions-spec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CHANGELOG

## [UNRELEASED]

## [1.0.0] - 2024-04-23

- feat: initial release with several actions
13 changes: 13 additions & 0 deletions packages/sdk-actions-spec/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
verbose: true,
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '(.*\\.spec)\\.(jsx?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testTimeout: 60000,
testRunner: 'jasmine2',
};
export default config;
29 changes: 29 additions & 0 deletions packages/sdk-actions-spec/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@dialectlabs/sdk-actions-spec",
"version": "1.0.0",
"repository": "[email protected]:dialectlabs/sdk.git",
"author": "dialectlabs",
"license": "Apache-2.0",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"exports": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"scripts": {
"clean": "rm -rf lib",
"lint": "eslint \"{src,test}/**/*.ts\" --fix",
"build": "yarn clean && yarn build:cjs; yarn build:esm",
"build:cjs": "tsc --project tsconfig.cjs.json",
"build:cjs:watch": "concurrently \"tsc --project tsconfig.cjs.json --watch\"",
"build:esm": "tsc --project tsconfig.esm.json",
"build:esm:watch": "concurrently \"tsc --project tsconfig.esm.json --watch\"",
"dev": "yarn clean && concurrently \"npm:build:cjs:watch\" \"npm:build:esm:watch\"",
"test": "jest"
},
"peerDependencies": {
"@dialectlabs/sdk": "1.x",
"@solana/web3.js": "1.x"
}
}
2 changes: 2 additions & 0 deletions packages/sdk-actions-spec/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './smart-messages/tensor-transactions-spec';
export * from './smart-messages/token-transfer-spec';
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { SmartMessage, SmartMessageParams } from '@dialectlabs/sdk';

export interface TensorNftBuyNowSmartMessage extends SmartMessage {
transactionServiceId: 'tensor-nft-buy-now';
transactionParams: NftBuyTransactionParams;
}

export interface NftBuyTransactionParams extends SmartMessageParams {
mintAddress: string;
collectionId: string;
price: string;
owner: string;
priceWithFeeAndRoyalty: string;
imageUrl?: string;
collectionName?: string;
nftName?: string;
}

export interface TensorNftBuyFloorSmartMessage extends SmartMessage {
transactionServiceId: 'tensor-nft-buy-floor';
transactionParams: NftBuyFloorTransactionParams;
}

export interface NftBuyFloorTransactionParams extends SmartMessageParams {
collectionId: string;
collectionName: string;
imageUrl?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { SmartMessage, SmartMessageParams } from '@dialectlabs/sdk';

export interface TokenTransferSmartMessage extends SmartMessage {
transactionServiceId: 'token-transfer';
transactionParams: TokenTransferSmartMessageParams;
}

export interface TokenTransferSmartMessageParams extends SmartMessageParams {
payerWalletAddress: string;
payeeWalletAddress: string;
tokenMintAddress?: string;
amount: string;
}
18 changes: 18 additions & 0 deletions packages/sdk-actions-spec/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"target": "ES6",
"module": "CommonJS",
"outDir": "lib/cjs",
"declarationDir": "lib/types"
},
"rootDir": "./src",
"include": ["src/**/*.ts"],
"exclude": [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"tests/**/*.test.ts",
"tests/**/*.spec.ts"
]
}
17 changes: 17 additions & 0 deletions packages/sdk-actions-spec/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"module": "ESNext",
"outDir": "lib/esm",
"declarationDir": "lib/types"
},
"rootDir": "./src",
"include": ["src/**/*.ts"],
"exclude": [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"tests/**/*.test.ts",
"tests/**/*.spec.ts"
]
}
8 changes: 8 additions & 0 deletions packages/sdk-actions-spec/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./src"
},
"rootDir": "./src",
"include": ["src/**/*.ts", "tests/**/*.ts"]
}
4 changes: 4 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## [1.9.0] - 2024-04-23

- feat: support tx actions in notifications

## [1.7.8] - 2024-04-18

- feat: expose dapp id in notification channel subscriptions
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dialectlabs/sdk",
"version": "1.8.0",
"version": "1.9.0",
"type": "module",
"repository": "[email protected]:dialectlabs/sdk.git",
"author": "dialectlabs",
Expand Down
44 changes: 36 additions & 8 deletions packages/sdk/src/dapp/dapp.interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { AddressType, DappAddress } from '../address/addresses.interface';
import type {
NotificationConfig,
NotificationSubscription,
NotificationType,
} from '../wallet/wallet.interface';
import type { NotificationConfig, NotificationSubscription, NotificationType } from '../wallet/wallet.interface';
import type { AccountAddress } from '../auth/auth.interface';

export interface Dapps {
Expand Down Expand Up @@ -76,29 +72,60 @@ export interface FindDappQuery {
blockchainType?: BlockchainType;
}

export interface DappMessageAction {
export enum DappMessageActionType {
LINK = 'Link',
SMART_MESSAGE = 'SmartMessage',
}

interface DappMessageActionBase {
type: DappMessageActionType;
}

export interface DappMessageLinksAction extends DappMessageActionBase {
type: DappMessageActionType.LINK;
links: [DappMessageLinkAction];
}
export interface DappMessageLinkAction {
label: string;
url: string;
}

export interface DappMessageSmartMessageAction extends DappMessageActionBase {
type: DappMessageActionType.SMART_MESSAGE;
smartMessage: SmartMessage;
}

export interface SmartMessage {
transactionServiceId: string;
transactionParams: SmartMessageParams;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SmartMessageParams {}


export interface SendDappMessageCommandBase {
message: string;
title?: string;
imageUrl?: string;
notificationTypeId?: string;
addressTypes?: AddressType[];
// tags?: string[];
actions?: DappMessageAction[];
}

export type BroadcastDappMessageCommand = SendDappMessageCommandBase;
export interface BroadcastDappMessageCommand extends SendDappMessageCommandBase {
actionsV2?: DappMessageLinksAction;
}

export interface UnicastDappMessageCommand extends SendDappMessageCommandBase {
recipient: AccountAddress;
actionsV2?: DappMessageLinksAction | DappMessageSmartMessageAction;
}

export interface MulticastDappMessageCommand
extends SendDappMessageCommandBase {
recipients: AccountAddress[];
actionsV2?: DappMessageLinksAction;
}

export type SendDappMessageCommand =
Expand Down Expand Up @@ -147,3 +174,4 @@ export class DappNotificationSubscription {
notificationType!: NotificationType;
subscriptions!: NotificationSubscription[];
}

Loading
Loading