8.1.15 • Published 2 months ago

@credenza-web3/passport v8.1.15

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Credenza3 Passport

Installation

with npm

npm install @credenza-web3/passport

with yarn

yarn add @credenza-web3/passport

with pnpm

pnpm install @credenza-web3/passport

or include a script tag

<script src="https://cdn.jsdelivr.net/npm/@credenza-web3/passport/dist/passport.umd.js"></script>
<script>
  const Passport = window.CredenzaPassport
</script>

or with esm

<script type="module">
  import {Passport} from 'https://cdn.jsdelivr.net/npm/@credenza-web3/passport/+esm'
</script>

Usage

Create the Passport instance

const passport = new Passport({
  chainId: Passport.chains.POLYGON_MUMBAI,
  clientId: "СREDENZA OAUTH CLIENT ID",
  config: {
    buyTokens?: true
    auth?: {
      extendedRegistration: false,
      credentials?: false
      google?: true
      ticketmaster?: false
      passwordless?: false
      metamask?: true
    },
    nav?: {
      theme?: Passport.themes.BLACK,
      direction?: Passport.navDirections.BOTTOM,
    },
    email?: {
      templateId?: string // For custom email template usage
    },
    content?: {
      cloak?: boolean
      // depends on `cloak: true`
      payPerArticle?: [
        {
          nfts: [{address: 'contract-address-1', tokens:['token-id-1', 'token-id-2'], type: 'ERC1155' | 'ERC721'}],
          memberships: [{address: 'contract-address-1', owner: 'owner-address-1'}],
          uriMasks: ['part-of-the-article-uri'] // [''] for all uris
        }
      ],
      imageUrl?: 'https://yoursite.com/image.png', // Replaces default `Standford Socker` image
      signin: {
        title: "Your title!", // Replaces default ``
        description: "Your description.", // Replaces default ``
      },
      signup: {
        title: "Your title!", // Replaces default ``
        description: "Your description.", // Replaces default ``
      },
      logout: {
        title: "Your title!", // Replaces default ``
        description: "Your description!", // Replaces default ``
      },
      paymentResult?: {
        title?: "Your title!", // Replaces default `Success!`
        subtitle?: "Your subtitle!", // Replaces default `Your payment was successful!`
        description?: "Your description!", // Replaces default `Usually it takes us as many as a few minutes to deliver tokens to your account.`
      }
      progressVideos?: [{
        embedded: true,
        src: 'https://www.youtube.com/embed/tgbNymZ7vqY',
      }, {
        src: 'https://media.w3.org/2010/05/sintel/trailer.mp4'
      }]
    },
  },
})

await passport.init()

Passport instance Properties

isLoggedIn: boolean

chainId: string

ethers: Ethers.js https://docs.ethers.io/v5/

user: User instance

Passport static properties

Passport.version (string) Current package version

Passport.chains (enum) Supported chains

Passport.pages = (enum) Available pages for logged in User

Passport.paymentTypes = (enum) Available payment types

Passport.themes = (enum) Available color schemas

Passport.navDirections = (enum) Available directions where passport nav bar will expand when opened

Passport.navMinimizationTogglerPositions = (enum) Available minimization toggler positions

Passport.events = (enum) Available events for passport.on() listener

Modes

Passport can be used in 3 modes: Code UI Navigation

Apple Pay

You must verify your domain. https://support.stripe.com/questions/enable-apple-pay-on-your-stripe-account Enabled by default on all supported devices and registered domains.

Google Pay

Is enabled on all supported devices by default

Code mode

Login with credentials

await passport.login(provider: "OAUTH" | "METAMASK", oauthType?: "CREDENTIALS" | "GOOGLE" | "PASSWORDLESS" | "TICKETMASTER")
// Do not provide is 'signUp' param if you want passport to try detect automatically.

Logout

await passport.logout()

Switch chain

await passport.switchChain({chainId: string}):Promise<void> // any of Passport.chains

Get ethers provider

await passport.getWeb3Provider():Promise<EthersRPCProvider> // returns Ethers provider

Get current session address

await passport.getAddress():Promise<string | null>

Check membership

await passport.checkMembership(ownerAddress:string):Promise<{isMember:boolean, meta: unknown}>

Get current user roles

await passport.getRoles():Promise<(Admin | Superadmin | User)[]>

Get current user NFTs

await passport.getNfts():Promise<({
  amount: number
  contract_type: string // e.g. "ERC721"
  name: string
  symbol: string
  token_address: string
  token_id: string
  token_uri: string
})[]>

Get CRED Contract

await passport.getCREDContract():Promise<({
  address: string
  decimals: number
  contract: ethers.Contract
})>

Send CRED Stored Value

Do not pass contract if you transfer the native network tokens.

await passport.sendTokens(address: string, amount: string | bigint, contract?: ethers.Contract):Promise<any>

Send Credenza NFT

await passport.sendNft(contract: ethers.Contract, recipient: string, tokenId: string, amount: number):Promise<any>

Request AirDrop

await passport.requestAirDrop({ contractAddress, tokenId, amount, targetAddress }: {
  targetAddress: string
  contractAddress: string
  tokenId?: string | number // tokenId can be skipped if we need to airdrop erc721
  amount?: number // if amount is skipped - default is 1
}):Promise<void>

Request Loyalty Points

await passport.requestLoyaltyPoints(eventId: string, contractAddress: string):Promise<void>

Confirm email / phone number

await passport.confirmAccount({phoneCode?:number, emailCode?:number}):Promise<boolean>

Navigation mode

Show navigation panel

await passport.showNavigation({
  bottom?: "5px",
  right?: "5px",
  left?: "inherit",
  top?: "inherit",
}, {
  minimization?: {
    enabled?: boolean, // false
    toggler?: {
      enabled?: boolean, // false
      position?: Passport.navMinimizationTogglerPositions.(LEFT | RIGHT), // left
    }
  }
}); // Bottom right corner

Hide navigation panel

passport.hideNavigation();

Passport UI mode

Open UI (Use one of Credenza.pages.PROFILE, Credenza.pages.PASSPORT_ID)

await passport.openUI() // defaults to Credenza.pages.PROFILE

Close UI

passport.close()

Open Passport alert

passport.toastAlert(
  message,
  type?: 'success' | 'warning' | 'failure' | 'info', // defaults to info
  opts?:{
    duration?: number // if -1 - then there is no timer and it stays untill dismissed,
    centered?: {
      enabled?: boolean,
      position?: 'top' | 'bottom' // can be used only for centered block
    }
  }
)

Perform NFT or Membership payment

await passport.openUI(Passport.pages.PAYMENT, {
  title: string,
  subtitle: string,
  payments?: {
    credenzaStoredValue?: {
        disabled?: boolean //default - false
    },
    stripe?: {
        disabled?: boolean // default - false
    }
  },
  tokens: [{
    contractAddress: string, // contract address
    tokenId: string,
    amount?: number  // amount of tokens
  }],
  memberships: [
    {
      contractAddress: string, // contract address
      typeId?: string // If typeId === "0", API will treat it as a simple memberships purchase. If typeId > "0", ex. "1", "2", API will look for club memberships purchase.
    }
  ]
  email?: {
    templateId?: string // For custom email template usage
  }
})

Destroy passport

passport.destroy()

Events (Most likely for Navigation and UI modes)

Listen for event

const unsubscribe = passport.on(Passport.events[eventName], (data) => {
  console.log(data)
})

Listen for event(Triggers once)

const unsubscribe = passport.once(Passport.events[eventName], (data) => {
  console.log(data)
})

Supported query params

Prepopulates email address on login / signup form.

?credenza_user_email=test%40test.com
// ?credenza_user_email=encodeURIComponent(test@test.com)

SSR

Passport is not build for the Server Side Rendering, but you still can make it work with the SSR app. Make sure you disable SSR for passport specific component or you can dynamically import passport after it's mounted e.g.

// svelte
onMount(() => {
  const {Passport} = (await import('@credenza-web3/passport'))
})
8.1.15

2 months ago

8.1.14

2 months ago

8.1.13

2 months ago

8.1.12

2 months ago

8.1.11

3 months ago

8.1.10

3 months ago

8.1.8

3 months ago

8.1.7

3 months ago

8.1.9

3 months ago

8.1.6

3 months ago

8.1.5

3 months ago

8.1.4

3 months ago

8.1.3

3 months ago

8.1.2

3 months ago

8.1.0

3 months ago

8.1.1

3 months ago

8.0.5

3 months ago

8.0.6

3 months ago

8.0.4

3 months ago

8.0.1

3 months ago

8.0.0

3 months ago

8.0.3

3 months ago

8.0.2

3 months ago

7.1.0

5 months ago

7.0.6

5 months ago

7.0.5

5 months ago

7.0.4

5 months ago

7.0.3

5 months ago

7.0.2

5 months ago

6.1.9

5 months ago

7.0.0-rc.8

5 months ago

7.0.0-rc.7

5 months ago

7.0.0-rc.9

5 months ago

7.0.0

5 months ago

7.0.1

5 months ago

7.0.0-rc.4

5 months ago

7.0.0-rc.6

5 months ago

7.0.0-rc.5

5 months ago

7.0.0-rc.3

5 months ago

7.0.0-rc.2

5 months ago

7.0.0-rc.1

5 months ago

6.1.6

5 months ago

6.1.5

5 months ago

6.1.8

5 months ago

6.1.7

5 months ago

6.1.2

5 months ago

6.1.1

5 months ago

6.1.4

5 months ago

6.1.3

5 months ago

6.0.0-alpha.3

7 months ago

6.0.0-alpha.4

7 months ago

6.0.0-alpha.5

7 months ago

6.0.0-alpha.6

7 months ago

5.6.19

7 months ago

5.6.18

7 months ago

5.6.15

8 months ago

5.6.14

8 months ago

5.6.17

8 months ago

5.6.16

8 months ago

5.6.11

8 months ago

5.6.10

8 months ago

6.0.0-alpha.1

7 months ago

5.6.13

8 months ago

6.0.0-alpha.2

7 months ago

5.6.12

8 months ago

6.0.13

6 months ago

6.0.12

6 months ago

6.0.11

6 months ago

6.0.10

6 months ago

5.5.13

9 months ago

5.5.11

9 months ago

5.5.12

9 months ago

5.5.10

9 months ago

5.7.0-alpha.3

7 months ago

5.7.0-alpha.4

7 months ago

5.7.0-alpha.1

8 months ago

5.7.0-alpha.2

7 months ago

5.7.0-alpha.7

7 months ago

5.7.0-alpha.8

7 months ago

5.7.0-alpha.5

7 months ago

5.7.0-alpha.6

7 months ago

5.6.15-alpha.2

8 months ago

5.7.0-alpha.9

7 months ago

5.6.15-alpha.1

8 months ago

6.0.7

6 months ago

6.0.6

6 months ago

6.0.9

6 months ago

6.0.8

6 months ago

6.0.1

7 months ago

6.0.0

7 months ago

5.4.7-beta.0

10 months ago

6.0.3

7 months ago

6.0.2

7 months ago

6.0.5

7 months ago

6.0.4

7 months ago

5.3.9

10 months ago

5.3.8

10 months ago

5.3.7

10 months ago

5.3.6

10 months ago

5.3.5

11 months ago

5.3.4

11 months ago

6.1.0

6 months ago

5.5.0-beta.3

10 months ago

5.5.0-beta.2

10 months ago

5.5.0-beta.1

10 months ago

5.5.0-beta.0

10 months ago

5.6.0-alpha.1

9 months ago

5.3.12

10 months ago

5.3.11

10 months ago

5.4.6

10 months ago

5.3.10

10 months ago

5.4.5

10 months ago

5.4.4

10 months ago

5.4.3

10 months ago

5.4.2

10 months ago

5.4.1

10 months ago

5.4.0

10 months ago

5.5.9

10 months ago

5.5.8

10 months ago

5.5.7

10 months ago

5.5.6

10 months ago

5.5.5

10 months ago

5.5.4

10 months ago

5.5.3

10 months ago

5.5.2

10 months ago

5.5.1

10 months ago

5.5.0

10 months ago

5.6.0-beta.1

9 months ago

5.6.9

8 months ago

5.6.8

8 months ago

5.6.7

8 months ago

5.6.6

8 months ago

5.6.5

8 months ago

5.6.4

8 months ago

5.6.3

8 months ago

5.6.2

8 months ago

5.6.1

8 months ago

5.6.0

8 months ago

5.7.0-alpha.10

7 months ago

5.7.0-alpha.11

7 months ago

5.3.3

11 months ago

5.3.2

11 months ago

5.3.1

11 months ago

5.3.0

11 months ago

5.2.13

11 months ago

5.2.12

11 months ago

5.2.9

11 months ago

5.2.8

11 months ago

5.2.11

11 months ago

5.2.10

11 months ago

5.0.30

1 year ago

5.0.31

1 year ago

5.0.32

1 year ago

5.0.33

1 year ago

5.0.34

1 year ago

5.0.26

1 year ago

5.0.27

1 year ago

5.0.28

1 year ago

5.0.29

1 year ago

5.1.9

12 months ago

5.1.8

12 months ago

5.1.7

12 months ago

5.1.6

12 months ago

5.1.5

12 months ago

5.1.4

12 months ago

5.1.3

12 months ago

5.1.2

12 months ago

5.1.1

12 months ago

5.1.0

1 year ago

5.2.7

11 months ago

5.2.6

11 months ago

5.2.5

11 months ago

5.2.4

11 months ago

5.2.3

11 months ago

5.2.2

11 months ago

5.2.1

11 months ago

5.2.0

11 months ago

5.1.16

11 months ago

5.1.15

11 months ago

5.1.14

11 months ago

5.1.13

11 months ago

5.1.12

11 months ago

5.1.11

12 months ago

5.1.10

12 months ago

5.0.0-rc.1

1 year ago

5.0.0-rc.2

1 year ago

5.0.0-rc.3

1 year ago

5.0.20

1 year ago

5.0.21

1 year ago

5.0.22

1 year ago

5.0.23

1 year ago

5.0.24

1 year ago

5.0.25

1 year ago

5.0.9

1 year ago

5.0.7

1 year ago

5.0.6

1 year ago

5.0.5

1 year ago

5.0.4

1 year ago

5.0.3

1 year ago

5.0.2

1 year ago

5.0.1

1 year ago

5.0.10

1 year ago

5.0.0

1 year ago

5.0.11

1 year ago

5.0.12

1 year ago

5.0.13

1 year ago

5.0.14

1 year ago

5.0.15

1 year ago

5.0.16

1 year ago

5.0.17

1 year ago

5.0.19

1 year ago

5.0.0-alpha.7

1 year ago

5.0.0-alpha.6

1 year ago

5.0.0-alpha.5

1 year ago

5.0.0-alpha.4

1 year ago

5.0.0-alpha.8

1 year ago

5.0.0-beta.4

1 year ago

5.0.0-beta.5

1 year ago

5.0.0-beta.2

1 year ago

5.0.0-rc.0

1 year ago

5.0.0-beta.3

1 year ago

5.0.0-beta.0

1 year ago

5.0.0-beta.1

1 year ago

5.0.0-alpha.3

1 year ago

5.0.0-alpha.2

1 year ago

5.0.0-alpha.1

1 year ago

5.0.0-alpha.0

1 year ago

4.2.5

1 year ago

4.2.4

1 year ago

4.2.6

1 year ago

4.1.7

1 year ago

4.2.3

1 year ago

4.2.2

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

4.0.0-alpha.1

1 year ago

4.0.0-alpha.0

1 year ago

3.2.2

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.2.4

1 year ago

3.2.3

1 year ago

4.0.0

1 year ago

3.1.3

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.1.7

1 year ago

3.1.6

1 year ago

3.1.5

1 year ago

3.1.4

1 year ago

4.0.0-rc.10

1 year ago

4.0.0-rc.12

1 year ago

4.0.0-rc.11

1 year ago

3.1.10

1 year ago

3.1.9

1 year ago

3.1.8

1 year ago

4.0.0-rc.9

1 year ago

4.0.0-rc.8

1 year ago

4.0.0-rc.1

1 year ago

4.0.0-rc.3

1 year ago

4.0.0-rc.2

1 year ago

4.0.0-rc.5

1 year ago

4.0.0-rc.4

1 year ago

4.0.0-rc.7

1 year ago

4.0.0-rc.6

1 year ago

4.1.4

1 year ago

4.1.3

1 year ago

4.1.6

1 year ago

4.1.5

1 year ago

4.1.0

1 year ago

4.1.2

1 year ago

4.1.1

1 year ago

2.4.1

1 year ago

2.4.3

1 year ago

2.2.13

1 year ago

2.4.2

1 year ago

2.2.11

2 years ago

2.2.12

1 year ago

3.0.4

1 year ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.6

1 year ago

3.0.5

1 year ago

2.3.8

1 year ago

2.3.7

1 year ago

2.3.9

1 year ago

3.0.0

1 year ago

2.3.0

1 year ago

2.5.0

1 year ago

2.3.2

1 year ago

2.3.1

1 year ago

2.3.4

1 year ago

2.3.3

1 year ago

2.3.6

1 year ago

2.3.5

1 year ago

2.3.12

1 year ago

2.3.11

1 year ago

2.3.10

1 year ago

2.2.1

2 years ago

2.2.0

2 years ago

2.0.2

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.5

2 years ago

2.2.4

2 years ago

2.2.7

2 years ago

2.2.6

2 years ago

2.2.10

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.1.0

2 years ago

2.2.9

2 years ago

2.2.8

2 years ago

1.0.11

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.10

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

0.9.7

2 years ago

1.0.0

2 years ago

0.9.6

2 years ago

0.9.5

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.9.4

2 years ago

0.9.3

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.0

2 years ago

0.8.20

2 years ago

0.8.19

2 years ago

0.8.18

2 years ago

0.8.17

2 years ago

0.8.16

2 years ago

0.8.15

2 years ago

0.8.14

2 years ago

0.8.13

2 years ago

0.8.12

2 years ago

0.8.11

2 years ago

0.8.10

2 years ago

0.8.8

2 years ago

0.8.7

2 years ago

0.8.6

2 years ago

0.8.5

2 years ago

0.8.4

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.7.0

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.3

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago